-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsubs.js
118 lines (98 loc) · 3.57 KB
/
subs.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
let hidden = [];
let hideWatched = null;
let hidePremieres = null;
let hideShorts = null;
let intervalId = null;
function isYouTubeWatched(item) {
let ytWatchedPercentThreshold = settings["settings.mark.watched.youtube.watched"];
return ytWatchedPercentThreshold === true && (
(item.querySelectorAll("yt-formatted-string.style-scope.ytd-thumbnail-overlay-playback-status-renderer").length > 0 || //has "WATCHED" on thumbnail
item.querySelectorAll("#progress.style-scope.ytd-thumbnail-overlay-resume-playback-renderer").length > 0) || //has progress bar on thumbnail TODO allow percentage threshold
item.hasAttribute("is-dismissed") //also hide empty blocks left in by pressing "HIDE" button
)
}
function hideWatchedChanged(event) {
try {
let toggle = document.getElementById(HIDE_WATCHED_TOGGLE);
log("Hide Watched checkbox was changed. New value is: " + !hideWatched);
if (hideWatched) {
hideWatched = false;
toggle.classList.remove("subs-btn-hide-watched-checked");
toggle.classList.add("subs-btn-hide-watched-unchecked");
showWatched();
} else {
hideWatched = true;
toggle.classList.remove("subs-btn-hide-watched-unchecked");
toggle.classList.add("subs-btn-hide-watched-checked");
removeWatchedAndAddButton();
}
} catch (e) {
logError(e);
}
}
function collapseSectionChanged(event) {
try {
let checkbox = event.target;
log("Checkbox for section " + checkbox.getAttribute("id") + " changed. New value is: " + checkbox.checked);
let contentDiv = checkbox.closest(sectionDismissableQuery()).querySelector(sectionContentsQuery());
if (checkbox.checked) {
contentDiv.style.display = '';
} else {
contentDiv.style.display = 'none';
loadMoreVideos();
}
} catch (e) {
logError(e);
}
}
function markAllAsWatched() {
let els = document.querySelectorAll(vidQuery());
for (let item of els) {
new SubscriptionVideo(item).markWatched();
}
loadMoreVideos();
}
function loadMoreVideos() {
log("Loading more videos");
// workaround to load more videos, slightly scroll in the sidebar :)
let sidebar = document.getElementById("guide-inner-content");
let top = sidebar.scrollTop;
// +1 -1 so the scroll moves a bit even if its at complete bottom or top
sidebar.scrollTop += 1;
sidebar.scrollTop -= 1;
// move it back to original position
sidebar.scrollTop = top;
}
function getVideoTitle(item) {
return item.querySelector("#video-title").title;
}
async function initSubs() {
log("Initializing subs page...");
await loadWatchedVideos();
if (hideWatched == null || !settings["settings.hide.watched.keep.state"]) {
hideWatched = settings["settings.hide.watched.default"];
}
if (hidePremieres == null) {
hidePremieres = settings["settings.hide.premieres"];
}
if (hideShorts == null) {
hideShorts = settings["settings.hide.shorts"];
}
buildUI();
intervalId = window.setInterval(function () {
if (hideWatched) {
try {
removeWatchedAndAddButton();
} catch (e) {
logError(e);
}
}
}, settings["settings.hide.watched.refresh.rate"]);
removeWatchedAndAddButton();
log("Initializing subs page... DONE");
}
function stopSubs() {
log("Stopping subs page behaviour");
removeUI();
window.clearInterval(intervalId);
}