-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
46 lines (44 loc) · 2.04 KB
/
settings.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
if (typeof browser === "undefined") {
var browser = chrome;
}
document.addEventListener('DOMContentLoaded', () => {
const backImg = document.getElementById('backImg');
const enableJoinButtonSwitch = document.getElementById('enable-join-button-switch');
const changeListeningToSpButtonSwitch = document.getElementById('change-listening-to-sp-switch');
const delayOtherActivities = document.getElementById('delay-other-activities-switch');
function sendUpdate() {
browser.runtime.sendMessage({
action: "updateSettings",
enableJoinButton: enableJoinButtonSwitch.checked,
changeListeningToSp: changeListeningToSpButtonSwitch.checked,
delayOtherActivities: delayOtherActivities.checked
});
}
backImg.addEventListener('click', () => {
history.back();
})
const enableJoinButtonSwitchState = localStorage.getItem('enableJoinButton');
if (enableJoinButtonSwitchState !== null) {
enableJoinButtonSwitch.checked = enableJoinButtonSwitchState === 'true';
}
const changeListeningToSpButtonSwitchState = localStorage.getItem('changeListeningToSp');
if (changeListeningToSpButtonSwitchState !== null) {
changeListeningToSpButtonSwitch.checked = changeListeningToSpButtonSwitchState === 'true';
}
const delayOtherActivitiesState = localStorage.getItem('delayOtherActivities');
if (delayOtherActivitiesState !== null) {
delayOtherActivities.checked = delayOtherActivitiesState === 'true';
}
enableJoinButtonSwitch.addEventListener('change', () => {
localStorage.setItem('enableJoinButton', enableJoinButtonSwitch.checked);
sendUpdate();
})
changeListeningToSpButtonSwitch.addEventListener('change', () => {
localStorage.setItem('changeListeningToSp', changeListeningToSpButtonSwitch.checked);
sendUpdate();
})
delayOtherActivities.addEventListener('change', () => {
localStorage.setItem('delayOtherActivities', delayOtherActivities.checked);
sendUpdate();
})
});