-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
71 lines (70 loc) · 2.94 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
window.onload = function () {
let theme_mode = "";
chrome.storage.local.get(["key_theme"], function (theme) {
if (theme.key_theme === "light") {
theme_mode = "light";
document.body.style.background = "#eeeeee";
document.getElementById("options-body").classList.add("bg-white");
document.getElementById("options-body").classList.add("border-white");
}
else {
theme_mode = "dark";
var checkbox = document.getElementById("theme");
checkbox.setAttribute("checked", "");
document.body.style.background = "#2E2E2F";
document.getElementById("options-body").classList.add("bg-dark");
document.getElementById("options-body").classList.add("muted-text");
document.getElementById("options-body").classList.add("border-dark");
document.getElementsByTagName("tbody")[0].classList.add("muted-text");
let dividers = document.getElementsByTagName("hr");
for (let m = 0; m < dividers.length; m++)
{
dividers[m].classList.add("lightDivider");
}
let iconList = document.getElementsByClassName("icons");
for (let n = 0; n < iconList.length; n++)
{
iconList[n].classList.replace("light-icons", "dark-icons");
}
}
});
chrome.storage.local.get(["key_block"], function (result) {
let table = document.getElementsByClassName("table")[0];
for (let i = 0; i < result.key_block.length; i++) {
let row = table.insertRow();
let websiteUrl = row.insertCell(0);
let removeIcon = row.insertCell(1);
websiteUrl.innerHTML = result.key_block[i];
if(theme_mode == "light")
{
removeIcon.innerHTML = "<a href='' class='icons light-icons'><i class='fas fa-minus-circle'></i></a>"
}
else
{
removeIcon.innerHTML = "<a href='' class='icons dark-icons'><i class='fas fa-minus-circle'></i></a>"
}
removeIcon.setAttribute("id", i.toString());
removeIcon.addEventListener("click", function () {
removeIcon.closest("tr").remove();
result.key_block.splice(i, 1);
chrome.storage.local.set({ key_block: result.key_block }, function () {
console.log("list updated");
});
})
};
});
}
document.getElementById("theme").addEventListener("change", function () {
if (this.checked) {
chrome.storage.local.set({ key_theme: "dark" }, function () {
console.log("theme preference updated");
});
chrome.tabs.reload();
}
else {
chrome.storage.local.set({ key_theme: "light" }, function () {
console.log("theme preference updated");
});
chrome.tabs.reload();
}
});