Skip to content

Commit edd6f45

Browse files
Merge pull request #25 from vtt132109/patch-1
fix dislike for youtube
2 parents 6fd8fea + 4de5945 commit edd6f45

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

scripts/youtube_viewDislikes.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export default {
3838
);
3939
if (!label) return;
4040
let text = numberFormat(dislikeCount);
41-
if (label.textContent === text) return;
42-
label.textContent = text;
41+
if (label.textContent !== text) {
42+
label.textContent = text;
43+
}
4344
}
4445

4546
let videoId = getVideoId();
@@ -62,9 +63,8 @@ export default {
6263
if (!button) return;
6364

6465
function makeUI(dislikeCount = 0) {
65-
// dislike text
6666
let className = "yt-spec-button-shape-next__button-text-content";
67-
let exist = button.querySelector(className);
67+
let exist = button.querySelector(`.${className}`);
6868
if (exist) {
6969
exist.textContent = numberFormat(dislikeCount);
7070
} else {
@@ -77,10 +77,7 @@ export default {
7777
);
7878
}
7979

80-
// fix button style
8180
button.style.width = "auto";
82-
83-
// fix dislike icon style
8481
const dislikeIcon = button.querySelector(
8582
".yt-spec-button-shape-next__icon"
8683
);
@@ -98,6 +95,7 @@ export default {
9895
function run() {
9996
// remove all pre listeners
10097
listeners.forEach((fn) => fn?.());
98+
listeners = []; // Reset listeners array after clearing
10199

102100
if (isShorts()) listeners.push(listenShort());
103101
else listeners.push(listenVideo());
@@ -171,30 +169,27 @@ function isInViewport(element) {
171169
const height = innerHeight || document.documentElement.clientHeight;
172170
const width = innerWidth || document.documentElement.clientWidth;
173171
return (
174-
// When short (channel) is ignored, the element (like/dislike AND short itself) is
175-
// hidden with a 0 DOMRect. In this case, consider it outside of Viewport
176172
!(rect.top == 0 && rect.left == 0 && rect.bottom == 0 && rect.right == 0) &&
177173
rect.top >= 0 &&
178174
rect.left >= 0 &&
179175
rect.bottom <= height &&
180176
rect.right <= width
181177
);
182178
}
179+
183180
function isVideoLoaded() {
184181
const videoId = getVideoId();
185182
return (
186-
// desktop: spring 2024 UI
187183
document.querySelector(`ytd-watch-grid[video-id='${videoId}']`) !== null ||
188-
// desktop: older UI
189184
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null ||
190-
// mobile: no video-id attribute
191185
document.querySelector('#player[loading="false"]:not([hidden])') !== null
192186
);
193187
}
194188

195189
function isShorts() {
196190
return location.pathname.startsWith("/shorts");
197191
}
192+
198193
function isNewDesign() {
199194
return document.getElementById("comment-teaser") !== null;
200195
}

0 commit comments

Comments
 (0)