forked from greatsuspender/thegreatsuspender
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
83 lines (67 loc) · 3.01 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
/*global document, window, gsStorage, chrome */
(function () {
"use strict";
// Saves options to localStorage.
function save_options() {
var preview = document.getElementById("preview"),
whitelist = document.getElementById("whitelist").value,
select = document.getElementById("timeToSuspend"),
timeToSuspend = select.children[select.selectedIndex].value;
gsStorage.setPreviewOption(preview.checked);
gsStorage.setWhitelist(whitelist);
gsStorage.setTimeToSuspendOption(timeToSuspend);
}
function selectComboBox(element, key) {
var i,
child;
for (i = 0; i < element.children.length; i++) {
child = element.children[i];
if (child.value === key) {
child.selected = "true";
break;
}
}
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var preview = gsStorage.fetchPreviewOption(),
unsuspendOnFocus = gsStorage.fetchUnsuspendOnFocusOption(),
timeToSuspend = gsStorage.fetchTimeToSuspendOption(),
whitelist = gsStorage.fetchWhitelist();
document.getElementById("preview").checked = preview;
document.getElementById("unsuspendOnFocus").checked = unsuspendOnFocus;
document.getElementById("whitelist").value = whitelist;
selectComboBox(document.getElementById("timeToSuspend"), timeToSuspend);
}
var readyStateCheckInterval = window.setInterval(function () {
if (document.readyState === "complete") {
window.clearInterval(readyStateCheckInterval);
var previewEl = document.getElementById('preview'),
unsuspendOnFocusEl = document.getElementById("unsuspendOnFocus"),
whitelistEl = document.getElementById("whitelist"),
timeToSuspendEl = document.getElementById("timeToSuspend"),
showHistoryEl = document.getElementById('showHistory'),
clearHistoryEl = document.getElementById('clearHistory');
previewEl.onclick = function (e) {
gsStorage.setPreviewOption(previewEl.checked);
};
unsuspendOnFocusEl.onclick = function (e) {
gsStorage.setUnsuspendOnFocusOption(unsuspendOnFocusEl.checked);
};
whitelistEl.onkeyup = function (e) {
gsStorage.setWhitelist(whitelistEl.value);
};
timeToSuspendEl.onchange = function (e) {
gsStorage.setTimeToSuspendOption(timeToSuspendEl.children[timeToSuspendEl.selectedIndex].value);
};
showHistoryEl.onclick = function (e) {
chrome.tabs.create({url: chrome.extension.getURL("history.html")});
};
clearHistoryEl.onclick = function (e) {
gsStorage.clearGsHistory();
gsStorage.clearPreviews();
};
restore_options();
}
}, 10);
}());