forked from co3moz/socialimiter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
85 lines (69 loc) · 2.59 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
function domLoaded () {
var objects = document.getElementsByTagName('html');
for (var j = 0; j < objects.length; j++) {
var obj = objects[j];
var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : "";
});
if (valNewH != valStrH) {
obj.innerHTML = valNewH;
}
}
chrome.storage.sync.get(function (e) {
(e || (e = {}));
(e.settings || (e.settings = {}));
var sub = document.getElementById("allowedTimeSub");
var allowedTime = document.getElementById("allowedTime");
allowedTime.value = e.settings.allowedTime || 1800;
allowedTime.onchange = allowedTime.onkeyup = function () {
sub.innerText = intToTime(+allowedTime.value);
if (+allowedTime.value > 86400) {
sub.innerText = chrome.i18n.getMessage("tooBig");
}
if (+allowedTime.value < 60) {
sub.innerText = chrome.i18n.getMessage("tooSmall");
}
};
allowedTime.onkeyup();
var save = document.getElementById("save");
save.onclick = function (e) {
e.preventDefault();
if (+allowedTime.value > 86400) {
return save.style.backgroundColor = "orange";
}
if (+allowedTime.value < 60) {
return save.style.backgroundColor = "orange";
}
chrome.storage.sync.get(function (e) {
(e || (e = {}));
(e.settings || (e.settings = {}));
e.settings.allowedTime = +allowedTime.value;
chrome.storage.sync.set(e);
save.style.backgroundColor = "green";
setTimeout(function() {
save.style.backgroundColor = "";
}, 1000);
});
};
var resetSites = document.getElementById("resetSites");
resetSites.onclick = function (e) {
e.preventDefault();
chrome.storage.sync.clear();
save.onclick(e);
resetSites.style.backgroundColor = "green";
setTimeout(function() {
resetSites.style.backgroundColor = "";
}, 1000);
};
});
}
document.addEventListener('DOMContentLoaded', domLoaded);
function intToTime (time) {
if (time <= 0) return "";
if (time < 60) return (time | 0) + chrome.i18n.getMessage("seconds");
if (time < 3600) return (time / 60 | 0) + chrome.i18n.getMessage("minutes") + intToTime(time % 60);
if (time < 86400) return (time / 3600 | 0) + chrome.i18n.getMessage("hours") + intToTime(time % 3600);
if (time < 2592000) return (time / 86400 | 0) + chrome.i18n.getMessage("days") + intToTime(time % 86400);
return (time / 2592000 | 0) + chrome.i18n.getMessage("months") + intToTime(time % 86400);
}