-
Notifications
You must be signed in to change notification settings - Fork 551
/
popup.js
63 lines (53 loc) · 1.84 KB
/
popup.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
document.addEventListener("DOMContentLoaded", function () {
document.querySelector("#config").addEventListener("click", function () {
window.open(chrome.runtime.getURL("options.html"));
});
document.querySelector("#about").addEventListener("click", function () {
window.open("https://github.com/igrigorik/videospeed");
});
document.querySelector("#feedback").addEventListener("click", function () {
window.open("https://github.com/igrigorik/videospeed/issues");
});
document.querySelector("#enable").addEventListener("click", function () {
toggleEnabled(true, settingsSavedReloadMessage);
});
document.querySelector("#disable").addEventListener("click", function () {
toggleEnabled(false, settingsSavedReloadMessage);
});
chrome.storage.sync.get({ enabled: true }, function (storage) {
toggleEnabledUI(storage.enabled);
});
function toggleEnabled(enabled, callback) {
chrome.storage.sync.set(
{
enabled: enabled
},
function () {
toggleEnabledUI(enabled);
if (callback) callback(enabled);
}
);
}
function toggleEnabledUI(enabled) {
document.querySelector("#enable").classList.toggle("hide", enabled);
document.querySelector("#disable").classList.toggle("hide", !enabled);
const suffix = `${enabled ? "" : "_disabled"}.png`;
chrome.action.setIcon({
path: {
"19": "icons/icon19" + suffix,
"38": "icons/icon38" + suffix,
"48": "icons/icon48" + suffix
}
});
}
function settingsSavedReloadMessage(enabled) {
setStatusMessage(
`${enabled ? "Enabled" : "Disabled"}. Reload page to see changes`
);
}
function setStatusMessage(str) {
const status_element = document.querySelector("#status");
status_element.classList.toggle("hide", false);
status_element.innerText = str;
}
});