-
Notifications
You must be signed in to change notification settings - Fork 0
/
skipper.js
60 lines (46 loc) · 1.55 KB
/
skipper.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
if (window.sleep == undefined) {
window.sleep = seconds => new Promise(resolve => setTimeout(resolve, 1000 * seconds))
}
if (window.ytautoskipadendpoint == undefined) {
window.ytautoskipadendpoint = "https://www.youtube.com/watch"
}
function loadExtensionStorage() {
return chrome.storage.local;
}
async function checkForSkippingAd(seconds) {
console.log("skipper was called");
var storage = loadExtensionStorage()
var { ytautoskipad_active: state } = await storage.get(["ytautoskipad_active"])
if (!state) {
return;
}
while (true) {
let {ytautoskipad_imediateskip: imediateState} = await storage.get(["ytautoskipad_imediateskip"]);
let waitTime = imediateState ? 0 : 6
const { href: url } = window.location;
state = await storage.get(["ytautoskipad_active"])
if (state.ytautoskipad_active != true) {
console.log('stopping skipper...')
break;
}
if (url.includes(window.ytautoskipadendpoint)) {
// getting element that indicates an ad has started playing.
const previewAdBtn = document.querySelector('div[id*="preview-ad"')
if (previewAdBtn) {
console.log('wait_time', waitTime)
if (waitTime) await window.sleep(waitTime)
console.log('skipping...')
// as click on skip button are not working anymore, probably
// cause its an unstrusted click we acellerate the video ad.
let video = document.querySelector('video')
video.currentTime = video.duration;
}
else console.log('no ad')
}
else {
console.log('invalid_url', location?.href)
}
await window.sleep(seconds)
}
}
checkForSkippingAd(1)