-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
69 lines (60 loc) · 2.27 KB
/
inject.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
$(document).ready(function () {
newButton = `
<button style="border:1px solid;padding:3px 12px;font-size:18px;line-height:1.5;border-radius:10px;color:#fff;margin:9px;background-color:#007bff;border-color:#007bff;bottom:auto;left:auto;right:240px;z-index:9999;position:fixed;" onclick="start()">开始</button>
<script>
function start () {
function getRandom (n, m) {
const num = Math.floor(Math.random() * (m - n + 1) + n)
return num
}
const setTime = prompt('请设置时间,分钟单位。', '')
const check = getRandom(0, 1)
const p = window.document.getElementById('movie_player')
p.setPlaybackQualityRange('hd1080')
p.unMute()
p.setVolume(100)
if (setTime < 20) {
reminder(setTime)
} else if (setTime >= 20 && setTime < 30) {
const videoTime = getRandom(13, setTime - 5)
if (check === '0') {
setTimeout(function () {
p.pauseVideo()
}, videoTime * 60000)
setTimeout(function () {
p.playVideo()
}, (videoTime + getRandom(2, 5)) * 60000)
reminder(setTime)
} else if (check === '1') {
setTimeout(function () {
p.seekTo(p.getCurrentTime() + getRandom(-300, 240))
}, videoTime * 60000)
reminder(setTime)
}
} else if (setTime >= 30) {
const videoEarly = getRandom(12, 20)
const videoLater = getRandom(20, setTime)
setTimeout(function () {
p.pauseVideo()
}, videoEarly * 60000)
setTimeout(function () {
p.playVideo()
}, (videoEarly + getRandom(2, 5)) * 60000)
setTimeout(function () {
p.seekTo(p.getCurrentTime() + getRandom(-360, 360))
}, videoLater * 60000)
reminder(setTime)
}
}
function reminder (setTime) {
return new Promise((resolve) => {
chrome.runtime.sendMessage('${chrome.runtime.id}', Number(setTime),
res => {
resolve(res)
} // End res
) // End sendMessage
}) // End Promise
}
</script>`
$('body').prepend(newButton)
})