diff options
author | ManeraKai <manerakai@protonmail.com> | 2023-01-21 14:29:10 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2023-01-21 14:29:10 +0300 |
commit | 57e32c8d7ac8a9fb34a6c5d76b677a9df7dc714f (patch) | |
tree | bbde34f9224c9944c26f9cb67575a32d71e773f9 /src/pages/options/init.js | |
parent | UX/UI tweaks (diff) | |
download | libredirect-57e32c8d7ac8a9fb34a6c5d76b677a9df7dc714f.zip |
Cleaned code. Fixed settings conversion not working
Diffstat (limited to 'src/pages/options/init.js')
-rw-r--r-- | src/pages/options/init.js | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/pages/options/init.js b/src/pages/options/init.js index 015daac7..aab66f93 100644 --- a/src/pages/options/init.js +++ b/src/pages/options/init.js @@ -1,42 +1,41 @@ window.browser = window.browser || window.chrome import localise from "../../assets/javascripts/localise.js" +import utils from "../../assets/javascripts/utils.js" function changeTheme() { - return new Promise(resolve => { - browser.storage.local.get("options", r => { - switch (r.options.theme) { - case "dark": - document.body.classList.add("dark-theme") - document.body.classList.remove("light-theme") - for (const element of document.body.getElementsByClassName('dark')) { - element.style.display = 'none'; - } - break - case "light": + return new Promise(async resolve => { + switch ((await utils.getOptions()).theme) { + case "dark": + document.body.classList.add("dark-theme") + document.body.classList.remove("light-theme") + for (const element of document.body.getElementsByClassName('dark')) { + element.style.display = 'none'; + } + break + case "light": + document.body.classList.add("light-theme") + document.body.classList.remove("dark-theme") + for (const element of document.body.getElementsByClassName('light')) { + element.style.display = 'none'; + } + break + default: + if (matchMedia("(prefers-color-scheme: light)").matches) { document.body.classList.add("light-theme") document.body.classList.remove("dark-theme") for (const element of document.body.getElementsByClassName('light')) { element.style.display = 'none'; } - break - default: - if (matchMedia("(prefers-color-scheme: light)").matches) { - document.body.classList.add("light-theme") - document.body.classList.remove("dark-theme") - for (const element of document.body.getElementsByClassName('light')) { - element.style.display = 'none'; - } - } else { - document.body.classList.add("dark-theme") - document.body.classList.remove("light-theme") - for (const element of document.body.getElementsByClassName('dark')) { - element.style.display = 'none'; - } + } else { + document.body.classList.add("dark-theme") + document.body.classList.remove("light-theme") + for (const element of document.body.getElementsByClassName('dark')) { + element.style.display = 'none'; } - } - resolve() - }) + } + } + resolve() }) } |