-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
executable file
·99 lines (92 loc) · 2.17 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
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
//options.js - file to hold the logic of the options saving
//Shrey Ravi
//WorkMode 3.0.2 - Using Chrome Storage API + Custom URL Blocking
resetArray = [
"facebook.com/",
"twitter.com/",
"youtube.com/",
"reddit.com/",
"pinterest.com/",
"vimeo.com/",
"plus.google",
"tumblr.com/",
"instagram.com/",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
];
/**
* Function that saves options to Chrome's localstorage
*/
function save_options() {
var options = new Array(20);
var i;
for(i = 1; i <= options.length; i++){
options[i-1] = document.getElementById('website'+i).value;
}
chrome.storage.sync.set({
option: options,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved! Thank you.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
/**
* Restores select box and checkbox state using the preferences stored in chrome.storage.
*/
function restore_options() {
chrome.storage.sync.get({
option: resetArray
}, function(items) {
var x;
for(x = 1; x <= 20; x++){
document.getElementById('website'+x).value = items.option[x-1];
}
});
}
/**
* Resets the options input to a default start state
*/
function reset() {
var x;
for(x = 1; x <= 20; x++){
document.getElementById('website'+x).value = resetArray[x-1];
}
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options were reset to install configurations.';
setTimeout(function() {
status.textContent = '';
}, 750);
}
/**
* Once page is loaded, load the localstorage options values
*/
document.addEventListener('DOMContentLoaded', restore_options);
/**
* If the reset button is properly rendered, attach a listener to activate reset logic
*/
var resetbtn = document.getElementById('reset');
if(resetbtn) {
resetbtn.addEventListener('click',reset);
}
/**
* If the save button is properly rendered, attach a listener to activate save logic
*/
var svbtn = document.getElementById('save');
if(svbtn) {
svbtn.addEventListener('click',
save_options);
}