-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtubeVideo.js
78 lines (75 loc) · 2.55 KB
/
youtubeVideo.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
async function setupYoutubeVideo() {
getRatingFromBackground(); //comment out, if you want to get the rating from foreground (in firefox this would be possible)
//getRating();
if (!ratingGotFromBack){return false} //comment out, if you want to get the rating from foreground (in firefox this would be possible)
if (
!(
$("ytd-toggle-button-renderer a yt-formatted-string")
.eq(1)
.text() == "" ||
$("ytd-toggle-button-renderer a yt-formatted-string")
.eq(1)
.text() == undefined
)
) {
await fillDislikes(
$("ytd-toggle-button-renderer a yt-formatted-string").eq(-1)
);
} else {
return false;
}
likes = $("ytd-toggle-button-renderer a yt-formatted-string").eq(-2);
if (!(likes.text() == "" || likes.text() == undefined)) {
if (!/\d/.test(likes.text())) {
await fillLikes(likes);
}
} else {
return false;
}
clearInterval(interval);
youtubeLiked = $(
"#top-level-buttons-computed ytd-toggle-button-renderer a yt-icon-button"
)
.eq(0)
.hasClass("style-default-active");
youtubeDisliked = $(
"#top-level-buttons-computed ytd-toggle-button-renderer a yt-icon-button"
)
.eq(1)
.hasClass("style-default-active");
if (liked && youtubeLiked == false) {
$("#top-level-buttons-computed ytd-toggle-button-renderer")
.eq(0)
.click();
}
if (disliked && youtubeDisliked == false) {
$("#top-level-buttons-computed ytd-toggle-button-renderer")
.eq(1)
.click();
}
if (youtubeLiked && liked == false) {
liked = true;
sendRating(1);
}
if (youtubeDisliked && disliked == false) {
disliked = true;
sendRating(-1);
}
assignDislikeButton(
$("#top-level-buttons-computed ytd-toggle-button-renderer").eq(1)
);
assignLikeButton(
$("#top-level-buttons-computed ytd-toggle-button-renderer").eq(0)
);
}
interval = undefined
const setup = () => interval = setInterval(setupYoutubeVideo, 300);
function checkWatchUrl() {
if (location.pathname.startsWith("/watch")) {
setup();
}
}
const pageLoad = () => {contentScriptReload(); checkWatchUrl()};
// checks if user loads new page (needed bc youtube changes sites with replacing history state )
//document.addEventListener("yt-navigate-start", pageLoad);
document.addEventListener('yt-navigate-finish', pageLoad);