-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
47 lines (41 loc) · 1.34 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
const autoSkipCheck = document.getElementById('autoSkip')
const hideSponsoredCheck = document.getElementById('hideSponsored')
const manualSkipBtn = document.getElementById('manualSkip')
autoSkipCheck.addEventListener('input', setOption('autoSkip'))
hideSponsoredCheck.addEventListener('input', setOption('hideSponsored'))
manualSkipBtn.addEventListener('click', sendManualSkip)
// Default settings
let settings = {
autoSkip: false,
hideSponsored: true
}
// Load current settings and set popup values
browser.storage.sync.get('skipButtonSettings').then(({ skipButtonSettings }) => {
if (skipButtonSettings) {
settings = skipButtonSettings
} else {
updateStorage()
}
autoSkipCheck.checked = settings.autoSkip
hideSponsoredCheck.checked = settings.hideSponsored
})
function setOption(option) {
return (event) => {
settings[option] = event.target.checked
updateStorage()
}
}
function updateStorage() {
browser.storage.sync.set({ skipButtonSettings: settings })
}
function sendManualSkip() {
browser.tabs.query({
active: true,
currentWindow: true
}).then(tabs => tabs.forEach(tab => {
browser.scripting.executeScript({
target: { allFrames: true, tabId: tab.id },
func: () => typeof manualSkip !== 'undefined' && manualSkip()
})
}))
}