-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
46 lines (40 loc) · 1.04 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
async function getCurrentTab() {
let queryOptions = { active: true, currentWindow: true }
let [tab] = await chrome.tabs.query(queryOptions)
return tab
}
const checkbox = document.getElementById('autoNext')
checkbox.addEventListener('change', async e => {
const checked = e.target.checked
const tab = await getCurrentTab()
console.log(tab)
if (checked) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: autoNext,
})
} else {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: cancelAutoNext,
})
}
})
/**
*
*/
function autoNext() {
if (!window.autoNextFn) {
window.autoNextFn = e => {
const nextArrow = document.querySelector('[data-e2e="arrow-right"]')
console.log('next', nextArrow, e)
if (e.target.tagName === 'VIDEO' && nextArrow) {
nextArrow.click()
}
}
}
document.addEventListener('ended', window.autoNextFn, true)
}
function cancelAutoNext() {
document.removeEventListener('ended', window.autoNextFn, true)
}