-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttvad.js
65 lines (48 loc) · 1.36 KB
/
ttvad.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
console.log("[ttvad]", "script.js loaded");
//video_sel = 'video[playsinline webkit-playsinline]';
video_sel = 'video';
carousel_sel = 'div[data-a-target="front-page-carousel"]';
async function sleep (ms) {
await new Promise(r => setTimeout(r, ms));
}
async function get_player () {
video_list = document.querySelectorAll(video_sel);
poll_rate = 250; //ms
timeout_left = 60 * 1000; // ms
init_timeout = 60 * 1000; // ms
while(timeout_left > 0) {
if (video_list.length != 0) {
console.log("[ttvad]", "time elapsed: " + (init_timeout - timeout_left));
return video_list;
} else {
await sleep(poll_rate);
video_list = document.querySelectorAll(video_sel);
}
timeout_left -= poll_rate;
}
}
function block_player (player_list) {
block_player.play_count = 0;
player_list[0].onplay = function () {
player = document.querySelectorAll(video_sel)[0];
player.pause();
if (block_player.play_count > 1) {
player.onplay = null;
}
block_player.play_count += 1;
}
}
// unused
function unblock_player (player_list) {
player_list[0].onplay = null;
}
// unused
function remove_carousel () {
// works but if the carousel thing is removed,
// then it seem onplay() is not called
carousel_list = document.querySelectorAll(carousel_sel);
carousel_list[0].remove();
}
player = get_player();
player.then(value => block_player(value));
//remove_carousel();