-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
123 lines (115 loc) · 4.72 KB
/
settings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Find UI elements.
const Button = document.getElementById("addtowhitelist");
const saveLast = document.getElementById("saveLast");
const themeTransition = document.getElementById("themeTransition");
const selectTheme = document.getElementById("themes");
// On settings load.
chrome.storage.sync.get("url", function(whitelist){
for (let i = 0; i < whitelist.url.length; i++) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (whitelist.url[i] == tabs[0].url) {
Button.innerText = "Disable on this site!"
}
});
}
});
chrome.storage.sync.get("saveLast", function(status){
if (status.saveLast) {
saveLast.checked = true
console.log(`Restoring save last choice checkbox to ${status.saveLast}.`);
} else {
saveLast.checked = false
console.log(`Restoring save last choice checkbox to ${status}.`);
}
});
chrome.storage.sync.get("theme", function(status){
selectTheme.value = status.theme
console.log(`Restoring theme select to ${status.theme}.`)
});
chrome.storage.sync.get("onLoadAnim", function(animation){
if (animation.onLoadAnim) {
themeTransition.checked = true
console.log(`Restoring theme transition checkbox to ${animation.onLoadAnim}.`);
} else {
themeTransition.checked = false
console.log(`Restoring theme transtion checkbox to ${animation.onLoadAnim}.`)
}
});
// Whitelist button logic.
Button.addEventListener('click', function () {
chrome.storage.sync.get("url", function(whitelist){
if (whitelist.url) {
if (whitelist.url.length > 0) {
whitelist = whitelist.url
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (whitelist.includes(tabs[0].url)) {
whitelist = whitelist.filter(function(value, index, arr){
return value != tabs[0].url;
});
chrome.storage.sync.set({ "url": whitelist }, function(){
console.log('Site removed from whitelist.')
Button.innerText = "Enable on this site!"
});
} else {
whitelist.push(tabs[0].url)
chrome.storage.sync.set({ "url": whitelist }, function(){
console.log('Site adden to whitelist.')
Button.innerText = "Disable on this site!"
});
}
});
} else {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.storage.sync.set({ "url": [tabs[0].url] }, function(){
console.log('Site adden to whitelist.')
Button.innerText = "Disable on this site!"
});
});
}
} else {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.storage.sync.set({ "url": [tabs[0].url] }, function(){
console.log('Site adden to whitelist.')
Button.innerText = "Disable on this site!"
});
});
}
});
});
// Save last choice checkbox logic.
saveLast.addEventListener('click', function () {
if (saveLast.checked) {
chrome.storage.sync.set({ "saveLast": true }, function(){
console.log('Setting save last choice to true.');
});
} else {
chrome.storage.sync.set({ "saveLast": false }, function(){
console.log('Setting save last choice to false.')
});
}
});
// Enable transition effect checkbox logic.
themeTransition.addEventListener('click', function () {
if (themeTransition.checked) {
chrome.storage.sync.set({ "onLoadAnim": true }, function(){
console.log('Setting theme transition to true.')
});
} else {
chrome.storage.sync.set({ "onLoadAnim": false }, function(){
console.log('Setting theme transition to false.')
});
}
});
// theme selector logic.
selectTheme.onchange = () => {
value = selectTheme.options[selectTheme.selectedIndex].innerHTML
chrome.storage.sync.set({ "isChangePending": true }, function(){
console.log('This reload is a theme change!');
});
chrome.storage.sync.set({ "theme": value }, function(){
console.log(`Theme selected ${value}.`);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.update(tabs[0].id, {url: tabs[0].url});
});
});
}