about summary refs log tree commit diff stats
path: root/src/pages/options/init.js
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2023-01-21 14:29:10 +0300
committerManeraKai <manerakai@protonmail.com>2023-01-21 14:29:10 +0300
commit57e32c8d7ac8a9fb34a6c5d76b677a9df7dc714f (patch)
treebbde34f9224c9944c26f9cb67575a32d71e773f9 /src/pages/options/init.js
parentUX/UI tweaks (diff)
downloadlibredirect-57e32c8d7ac8a9fb34a6c5d76b677a9df7dc714f.zip
Cleaned code. Fixed settings conversion not working
Diffstat (limited to 'src/pages/options/init.js')
-rw-r--r--src/pages/options/init.js55
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()
 	})
 }