Browse Source

fixed some exception checking

dev
Kyle 9 months ago
parent
commit
3811f8c5ba
2 changed files with 18 additions and 20 deletions
  1. +11
    -10
      js/index.js
  2. +7
    -10
      js/options.js

+ 11
- 10
js/index.js View File

@@ -3,11 +3,16 @@ function restore_options() {
console.log("Loading Settings", result)
var quads = document.getElementsByClassName("quadrant")
var style = document.createElement("style")
if (result) {
if (! typeof result === "undefined") {
if (! typeof result.links) result.links = []
if (! typeof result.colors) result.colors = []
if (! typeof result.mode) result.mode = "light"
for (i = 0; i < quads.length; i++) {
if (i < result.links.length) {
var link = result.links[i]
if (link.substring(0,4) == "http") {
if (link == "") {
quads[i].href = "options.html"
} else if (link.substring(0,4) == "http") {
quads[i].href = link
} else {
quads[i].href = "http://" + link
@@ -26,16 +31,12 @@ function restore_options() {
browser.storage.sync.set({links:result.links})
}
}
if (result.mode) {
if (result.mode == "dark") {
document.body.classList.add("dark")
} else {
document.body.classList.remove("dark")
}
if (result.mode == "dark") {
document.body.classList.add("dark")
} else {
result.mode = "light"
browser.storage.sync.set({mode:result.mode})
document.body.classList.remove("dark")
}

document.head.appendChild(style)
}
})


+ 7
- 10
js/options.js View File

@@ -21,7 +21,10 @@ function restore_options() {
console.log("Loading Settings", result)
var input_links = document.querySelectorAll('input[type="text"]')
var input_colors = document.querySelectorAll('input[type="color"]')
if (result) {
if (! typeof result === "undefined") {
if (! typeof result.links) result.links = []
if (! typeof result.colors) result.colors = []
if (! typeof result.mode) result.mode = "light"
for (i = 0; i < input_links.length; i++) {
if (i < result.links.length) {
input_links[i].value = result.links[i]
@@ -37,17 +40,11 @@ function restore_options() {
browser.storage.sync.set({colors:result.colors})
}
}
if (result.mode) {
if (result.mode == "dark") {
document.body.classList.add("dark")
} else {
document.body.classList.remove("dark")
}
if (result.mode == "dark") {
document.body.classList.add("dark")
} else {
result.mode = "light"
browser.storage.sync.set({mode:result.mode})
document.body.classList.remove("dark")
}
document.head.appendChild(style)
}
})
}


Loading…
Cancel
Save