-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
69 lines (56 loc) · 1.69 KB
/
controller.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
66
67
68
69
async function getCurrentTab() {
const options = { active: true, lastFocusedWindow: true }
console.log(chrome)
const [tab] = await chrome.tabs.query(options)
return tab;
}
async function loadConfiguration() {
let storage = await chrome.storage.local.get(["ytautoskipad_active", "ytautoskipad_imediateskip"])
if (storage && storage?.ytautoskipad_active) {
let button = document.querySelector('button')
await startOp(button)
}
// defining checkbox state based on storage.ytautoskipad_imediateskip
let imediateSkip = document.querySelector('input[type=checkbox]')
imediateSkip.checked = storage?.ytautoskipad_imediateskip || false;
}
window.onload = loadConfiguration
const button = document.querySelector('button')
const imediateSkip = document.querySelector('input[type=checkbox]')
button.onclick = async event => {
const el = event.target;
switch (el.innerText.toLowerCase()) {
case "start":
await startOp(el)
break;
case "stop":
await stopOp(el)
break;
}
}
imediateSkip.onclick = async (event) => {
await updateImediateSkip()
}
async function startOp(el) {
el.innerText = "Stop"
el.style.backgroundColor = 'red'
await chrome.storage.local.set({ytautoskipad_active: true})
const tab = await getCurrentTab()
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["skipper.js"]
})
.then(() => console.log('skipper called'))
}
async function stopOp(el) {
el.innerText = "Start"
el.style.backgroundColor = 'dodgerblue'
await chrome.storage.local.set({ytautoskipad_active: false})
}
async function updateImediateSkip() {
let state = imediateSkip.checked;
console.log('checkbox', state)
await chrome.storage.local.set({
ytautoskipad_imediateskip: state,
})
}