-
Notifications
You must be signed in to change notification settings - Fork 12
/
popup.js
51 lines (45 loc) · 1.77 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
// Try if Edge browser object exists, else default to chrome
var browser = self.browser;
if (typeof browser === "undefined") {
browser = self.chrome;
}
document.addEventListener("DOMContentLoaded", function(event) {
var miniYouTubeActivated = true;
var onOffSwitch = document.getElementById('myonoffswitch');
var enabledDescription = document.getElementById('mnyt-enabled');
var disabledDescription = document.getElementById('mnyt-disabled');
// Update the switch based on activation status
getActivationStatus(updateSwitchState);
// Add listener to the switch
onOffSwitch.onclick = toggleSwitch;
function getActivationStatus(callBack) {
browser.runtime.sendMessage({"get_activation_status": true}, function(response) {
var activated = true;
if ("is_active" in response) {
activated = response["is_active"];
}
callBack(activated);
});
}
function toggleSwitch() {
miniYouTubeActivated = onOffSwitch.checked;
// Send a message to background.js to save status and update icon
browser.runtime.sendMessage({"update_icon": miniYouTubeActivated});
updateDescription();
}
function updateSwitchState(activated) {
miniYouTubeActivated = activated;
onOffSwitch.checked = miniYouTubeActivated;
browser.runtime.sendMessage({"update_icon": miniYouTubeActivated});
updateDescription();
}
function updateDescription() {
if (miniYouTubeActivated) {
enabledDescription.style.display = "block";
disabledDescription.style.display = "none";
} else {
enabledDescription.style.display = "none";
disabledDescription.style.display = "block";
}
}
});