diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 10a82474..a9e81710 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -148,7 +148,8 @@ logues = {{ logues|tojson if sb_lg else "[]" }}, ls0 = {{ ls0|tojson }}; - document.documentElement.className = localStorage.cpp_thm || dtheme; + var STG = window.localStorage; + document.documentElement.className = (STG && STG.cpp_thm) || dtheme; diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 28cf5fa3..8ecc7648 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -3405,8 +3405,8 @@ function sortfiles(nodes) { } catch (ex) { console.log("failed to apply sort config: " + ex); - console.log("resetting fsort " + sread('fsort')) - localStorage.removeItem('fsort'); + console.log("resetting fsort " + sread('fsort')); + sdrop('fsort'); } return nodes; } diff --git a/copyparty/web/md.html b/copyparty/web/md.html index 5e08d07a..cbc2eb9c 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -139,16 +139,15 @@ var md_opt = { }; (function () { - var l = localStorage, - drk = l.light != 1, + var l = window.localStorage, + drk = (l && l.light) != 1, btn = document.getElementById("lightswitch"), f = function (e) { if (e) { e.preventDefault(); drk = !drk; } document.documentElement.className = drk? "z":"y"; btn.innerHTML = "go " + (drk ? "light":"dark"); -l.light = drk? 0:1; +try { l.light = drk? 0:1; } catch (ex) { } }; - btn.onclick = f; f(); })(); diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index f2f8a01a..dc2f702b 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -933,7 +933,7 @@ var set_lno = (function () { var keydown = function (ev) { if (!ev && window.event) { ev = window.event; - if (localStorage.dev_fbw == 1) { + if (dev_fbw == 1) { toast.warn(10, 'hello from fallback code ;_;\ncheck console trace'); console.error('using window.event'); } diff --git a/copyparty/web/mde.html b/copyparty/web/mde.html index bba78514..8b57336b 100644 --- a/copyparty/web/mde.html +++ b/copyparty/web/mde.html @@ -37,12 +37,12 @@ var md_opt = { }; var lightswitch = (function () { - var l = localStorage, - drk = l.light != 1, + var l = window.localStorage, + drk = (l && l.light) != 1, f = function (e) { if (e) drk = !drk; document.documentElement.className = drk? "z":"y"; -l.light = drk? 0:1; +try { l.light = drk? 0:1; } catch (ex) { } }; f(); return f; diff --git a/copyparty/web/splash.html b/copyparty/web/splash.html index 47db5a1a..29776e19 100644 --- a/copyparty/web/splash.html +++ b/copyparty/web/splash.html @@ -110,7 +110,8 @@ var SR = {{ r|tojson }}, lang="{{ lang }}", dfavico="{{ favico }}"; -document.documentElement.className=localStorage.cpp_thm||"{{ this.args.theme }}"; +var STG = window.localStorage; +document.documentElement.className = (STG && STG.cpp_thm) || "{{ this.args.theme }}"; diff --git a/copyparty/web/svcs.html b/copyparty/web/svcs.html index c0df4a24..1353ffe6 100644 --- a/copyparty/web/svcs.html +++ b/copyparty/web/svcs.html @@ -238,7 +238,8 @@ var SR = {{ r|tojson }}, lang="{{ lang }}", dfavico="{{ favico }}"; -document.documentElement.className=localStorage.cpp_thm||"{{ args.theme }}"; +var STG = window.localStorage; +document.documentElement.className = (STG && STG.cpp_thm) || "{{ args.theme }}"; diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 3148a52a..51e37d0f 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -431,7 +431,7 @@ function U2pvis(act, btns, uc, st) { if (sread('potato') === null) { btn.click(); toast.inf(30, L.u_gotpot); - localStorage.removeItem('potato'); + sdrop('potato'); } u2f.appendChild(ode); @@ -2687,7 +2687,7 @@ function up2k_init(subtle) { parallel_uploads = v; if (v == u2j) - localStorage.removeItem('nthread'); + sdrop('nthread'); else swrite('nthread', v); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index ca7c0840..dc548cab 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -12,6 +12,7 @@ if (window.CGV) var wah = '', + STG = null, NOAC = 'autocorrect="off" autocapitalize="off"', L, tt, treectl, thegrid, up2k, asmCrypto, hashwasm, vbar, marked, T0 = Date.now(), @@ -40,6 +41,16 @@ if (!window.Notification || !Notification.permission) if (!window.FormData) window.FormData = false; +try { + STG = window.localStorage; + STG.STG; +} +catch (ex) { + STG = null; + if ((ex + '').indexOf('sandbox') < 0) + console.log('no localStorage: ' + ex); +} + try { CB = '?' + document.currentScript.src.split('?').pop(); @@ -285,10 +296,11 @@ function anymod(e, shift_ok) { } +var dev_fbw = sread('dev_fbw'); function ev(e) { if (!e && window.event) { e = window.event; - if (localStorage.dev_fbw == 1) { + if (dev_fbw == 1) { toast.warn(10, 'hello from fallback code ;_;\ncheck console trace'); console.error('using window.event'); } @@ -925,9 +937,16 @@ function jcp(obj) { } +function sdrop(key) { + try { + STG.removeItem(key); + } + catch (ex) { } +} + function sread(key, al) { try { - var ret = localStorage.getItem(key); + var ret = STG.getItem(key); return (!al || has(al, ret)) ? ret : null; } catch (e) { @@ -938,9 +957,9 @@ function sread(key, al) { function swrite(key, val) { try { if (val === undefined || val === null) - localStorage.removeItem(key); + STG.removeItem(key); else - localStorage.setItem(key, val); + STG.setItem(key, val); } catch (e) { } }