-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
45 lines (38 loc) · 1.6 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
function localize() {
document.querySelector('#label_auto_skip').innerHTML = chrome.i18n.getMessage("skip");
document.querySelector('#label_rewind').innerHTML = chrome.i18n.getMessage("rewind");
}
function setHooks(){
chrome.storage.sync = chrome.storage.sync || {};
const autoSkipInput = document.getElementById('input_auto_skip');
const rewindInput = document.getElementById('input_rewind');
autoSkipInput.addEventListener('change', function () {
const inputState = {
autoSkip: autoSkipInput.checked,
rewind: rewindInput.checked
};
chrome.storage.sync.set({inputState});
chrome.runtime.sendMessage({ type: 'updateState', inputState });
});
rewindInput.addEventListener('change', function () {
const inputState = {
autoSkip: autoSkipInput.checked,
rewind: rewindInput.checked
};
chrome.storage.sync.set({inputState});
chrome.runtime.sendMessage({ type: 'updateState', inputState });
});
}
// Load input state from Chrome storage when the popup opens
window.addEventListener('DOMContentLoaded', function () {
localize();
chrome.storage.sync.get('inputState', function (storageData) {
if (storageData && storageData.inputState) {
const autoSkipInput = document.getElementById('input_auto_skip');
const rewindInput = document.getElementById('input_rewind');
autoSkipInput.checked = storageData.inputState.autoSkip;
rewindInput.checked = storageData.inputState.rewind;
}
});
setHooks();
});