Fix breakage when dom.storage.enabled is set to false (thanks DJ-Leith for report).
This commit is contained in:
parent
06cf6d322f
commit
b6edebed58
|
@ -51,17 +51,41 @@
|
||||||
}
|
}
|
||||||
addEventListener("load", onload, true);
|
addEventListener("load", onload, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let root = document.documentElement;
|
||||||
|
root.classList.add("__NoScript_Theme__");
|
||||||
|
|
||||||
|
let update = toTheme => {
|
||||||
|
return root.dataset.theme = toTheme;
|
||||||
|
}
|
||||||
|
|
||||||
var Themes = {
|
var Themes = {
|
||||||
setup(theme = null) {
|
setup(theme = null) {
|
||||||
if (theme) {
|
if (theme) {
|
||||||
|
if (window.localStorage) {
|
||||||
localStorage.setItem("theme", theme);
|
localStorage.setItem("theme", theme);
|
||||||
|
}
|
||||||
|
if (browser && browser.storage) {
|
||||||
|
browser.storage.local.set({theme});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (localStorage) {
|
||||||
theme = localStorage.getItem("theme") || "auto";
|
theme = localStorage.getItem("theme") || "auto";
|
||||||
}
|
}
|
||||||
let root = document.documentElement;
|
if (!theme && browser && browser.storage) {
|
||||||
root.classList.add("__NoScript_Theme__");
|
if (document.readyState === "loading") {
|
||||||
return root.dataset.theme = theme;
|
document.documentElement.style.visibility = "hidden";
|
||||||
|
}
|
||||||
|
return browser.storage.local.get(["theme"]).then(r => {
|
||||||
|
update(r.theme);
|
||||||
|
document.documentElement.style.visibility = "";
|
||||||
|
return r.theme;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Themes.setup();
|
return update(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Promise.resolve(Themes.setup());
|
||||||
}
|
}
|
2
src/nscl
2
src/nscl
|
@ -1 +1 @@
|
||||||
Subproject commit 8e753c290fcde4673a5ca2b4a2e5960f551c0e18
|
Subproject commit b3fd54f17e394930cfd5801d0d5733290334f959
|
|
@ -54,17 +54,19 @@ body {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
section form, section fieldset {
|
section fieldset {
|
||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
padding: .5em 1em;
|
padding: .5em 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
section > form {
|
||||||
|
padding: 0 .5em;
|
||||||
|
}
|
||||||
|
|
||||||
fieldset:disabled {
|
fieldset:disabled {
|
||||||
opacity: .5;
|
opacity: .5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.sect-sites form {
|
.sect-sites form {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
|
|
|
@ -28,7 +28,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h1>__MSG_OptionsLong__</h1>
|
<h1>__MSG_OptionsLong__</h1>
|
||||||
<span id="version"></span>
|
<span id="version"> </span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
|
@ -41,10 +41,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<a class="donate button" href="https://noscript.net/donate" title="__MSG_DonateLong__">__MSG_DonateShort__</a>
|
<a class="donate button" href="https://noscript.net/donate" title="__MSG_DonateLong__">__MSG_DonateShort__</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<section id="sect-io">
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<div id="main-tabs" class="flextabs">
|
<div id="main-tabs" class="flextabs">
|
||||||
|
|
||||||
<h3 class="flextabs__tab"><button class="flextabs__toggle">__MSG_SectionGeneral__</button></h3>
|
<h3 class="flextabs__tab"><button class="flextabs__toggle">__MSG_SectionGeneral__</button></h3>
|
||||||
|
|
|
@ -19,14 +19,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
document.querySelector("#version").textContent = _("Version",
|
||||||
|
browser.runtime.getManifest().version);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
await UI.init();
|
await UI.init();
|
||||||
|
|
||||||
let policy = UI.policy;
|
let policy = UI.policy;
|
||||||
|
|
||||||
let version = browser.runtime.getManifest().version;
|
|
||||||
document.querySelector("#version").textContent = _("Version", version);
|
|
||||||
// simple general options
|
// simple general options
|
||||||
|
|
||||||
let opt = UI.wireOption;
|
let opt = UI.wireOption;
|
||||||
|
|
10
src/ui/ui.js
10
src/ui/ui.js
|
@ -139,18 +139,20 @@ var UI = (() => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof storage === "function") {
|
if (typeof storage === "function") {
|
||||||
let value = storage(null);
|
(async() => {
|
||||||
|
let value = await storage(null);
|
||||||
for (let i of inputs) {
|
for (let i of inputs) {
|
||||||
i.onchange = e => storage(i);
|
i.onchange = e => storage(i);
|
||||||
i.checked = value === i.value;
|
i.checked = value === i.value;
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
} else {
|
} else {
|
||||||
let obj = UI[storage];
|
let obj = UI[storage];
|
||||||
let value = obj[name];
|
let value = obj[name];
|
||||||
for (let i of inputs) {
|
for (let i of inputs) {
|
||||||
if (i.value === value) i.checked = true;
|
if (i.value === value) i.checked = true;
|
||||||
if (onchange) onchange(i);
|
if (onchange) onchange(i);
|
||||||
i.onchange = async() => {
|
i.onchange = async () => {
|
||||||
obj[name] = i.value;
|
obj[name] = i.value;
|
||||||
await UI.updateSettings({[storage]: obj});
|
await UI.updateSettings({[storage]: obj});
|
||||||
if (onchange) onchange(i);
|
if (onchange) onchange(i);
|
||||||
|
@ -167,7 +169,9 @@ var UI = (() => {
|
||||||
}
|
}
|
||||||
if (typeof storage === "function") {
|
if (typeof storage === "function") {
|
||||||
input.onchange = e => storage(input);
|
input.onchange = e => storage(input);
|
||||||
input.checked = storage(null);
|
(async () => {
|
||||||
|
input.checked = await storage(null);
|
||||||
|
})();
|
||||||
} else {
|
} else {
|
||||||
let obj = UI[storage];
|
let obj = UI[storage];
|
||||||
input.checked = obj[name];
|
input.checked = obj[name];
|
||||||
|
|
Loading…
Reference in New Issue