-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsubs.js
More file actions
156 lines (133 loc) · 4.96 KB
/
subs.js
File metadata and controls
156 lines (133 loc) · 4.96 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
let hidden = [];
let hideWatched = null;
let hidePremieres = null;
let hideShorts = null;
let hideLives = null;
let hideMembersOnly = null;
let hideCollabsUnsubscribed = null;
let hideMostRelevant = 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.querySelectorAll(".ytThumbnailOverlayProgressBarHostWatchedProgressBarSegment").length > 0 || // new YT layout as of 09/2025
item.querySelectorAll("thumbnail-overlay-progress-bar-view-model").length > 0) || // new lockupViewModel layout as of 01/2026
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");
if (!sidebar) return;
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) {
// Try old layout
let titleElem = item.querySelector("#video-title");
if (titleElem && titleElem.title) {
return titleElem.title;
}
// Try new lockupViewModel layout - the title is in an anchor tag
let lockupViewModel = item.querySelector("lockup-view-model");
if (lockupViewModel) {
let link = lockupViewModel.querySelector("a");
if (link) {
return link.getAttribute("title") || link.textContent.trim();
}
}
return "";
}
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"];
}
if (hideLives == null) {
hideLives = settings["settings.hide.lives"];
}
if (hideMembersOnly == null) {
hideMembersOnly = settings["settings.hide.members.only"];
}
if (hideCollabsUnsubscribed == null) {
hideCollabsUnsubscribed = settings["settings.hide.collabs.unsubscribed"];
}
if (hideMostRelevant == null) {
hideMostRelevant = settings["settings.hide.most.relevant"];
}
if (hideCollabsUnsubscribed && isSubscriptionsPage()) {
buildSubscriptionCache();
}
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);
}