-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartContentScript.js
98 lines (86 loc) · 2.25 KB
/
StartContentScript.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
console.log("Start Content Script Running")
let adID = 1
let skip = null
let startMsg = {
Info: "Requesting URL State",
data: 0
}
let commPort = null
commPort = chrome.runtime.connect()
disbatchMsg()
function onMsgReceive(reply) {
console.log(reply.Info)
switch (reply.data) {
case 0:
startMsg.Info = "[?] Requesting URL State"
startMsg.data = 0
disbatchMsg()
break
case 1:
startMsg.Info = "[?] Requesting Video-Checking Service Start"
startMsg.data = 1
disbatchMsg()
break
case 2:
startMsg.Info = "[?] Start Verified"
startMsg.data = null
addDisplayChangeListener("ad-top-bar-container", (contentType) => {
if (contentType === 1) {
console.log("Show is Playing")
window.clearInterval(skip)
changeSpeed(1)
}else if (contentType === 0) {
console.log("Ad is Playing")
skip = window.setInterval(changeSpeed,1000, 10)
}
})
disbatchMsg()
break
}
}
function disbatchMsg() {
commPort.postMessage(startMsg)
commPort.onMessage.addListener(onMsgReceive)
}
function addDisplayChangeListener(className, callback) {
let displayType = null
let lastDisplayType = null
let adSlot = document.getElementsByClassName(className)
for (let j = 0; j < adSlot.length; j++) {
lastDisplayType = adSlot[j].style.display
}
window.setInterval( () => {
for (let k = 0; k < adSlot.length; k++) {
displayType = adSlot[k].style.display
}
if (displayType !== lastDisplayType) {
if (displayType === "none") {
callback(1)//Show is playing
}else {
callback(0)//Ad is playing
}
lastDisplayType = displayType
}
},10)
}
function changeSpeed(speed) {
let player = document.getElementsByClassName('video-player')
for (let i = 0; i < player.length; i++) {
player[i].playbackRate = speed
}
}
/*
function disbatchMsg() {
liftedResolve = null
liftedReject = null
msgReceivedPromise = new Promise((resolve, reject) => {
liftedResolve = resolve
liftedReject = reject
})
chrome.runtime.sendMessage(startMsg, (reply) => {
liftedResolve()
onMsgReceive(reply)
})
return msgReceivedPromise
}
*/