forked from mitchcapper/videospeed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
65 lines (55 loc) · 1.95 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
64
65
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/smart-move-media/adjust-video-speed");
});
document.querySelector("#feedback").addEventListener("click", function () {
window.open("https://github.com/smart-move-media/adjust-video-speed/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`;
if (chrome && chrome["browserAction"] && chrome.browserAction["setIcon"]) {
chrome.browserAction.setIcon({
path: {
"16": "icons/icon16" + suffix,
"32": "icons/icon32" + 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;
}
});