Skip to content

Commit 6a5edf5

Browse files
authored
Fix repeating dislike count issue on YouTube
Description: This pull request fixes an issue where the dislike count on YouTube videos was being repeated multiple times, leading to incorrect display and a poor user experience. Problem: The dislike count was being updated and displayed repeatedly, which resulted in the same number being shown multiple times in a row. This issue also caused the "dislike" button to become unresponsive in some cases, preventing users from interacting with it. Solution: I adjusted the makeUI function to check whether the dislike count element already exists before updating it. This ensures that the UI is only updated when necessary, preventing the issue of repeated display. Added a check to ensure that the text content is only updated if it has changed, which further optimizes performance and prevents unnecessary UI updates. Testing: I tested this solution on both regular YouTube videos and YouTube Shorts to ensure that the dislike count is displayed correctly and updated only when necessary. The "dislike" button remains fully functional after these changes. Please review the changes and let me know if there are any further adjustments needed. Thank you for your consideration!
1 parent 870e04e commit 6a5edf5

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

scripts/youtube_viewDislikes.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default {
3838
);
3939
if (!label) return;
4040
let text = numberFormat(dislikeCount);
41+
42+
// Kiểm tra và chỉ cập nhật nếu cần thiết
4143
if (label.textContent != text) label.textContent = text;
4244
}
4345

@@ -62,22 +64,31 @@ export default {
6264

6365
function makeUI(dislikeCount = 0) {
6466
let className = "yt-spec-button-shape-next__button-text-content";
65-
let exist = button.querySelector(className);
67+
let exist = button.querySelector(`.${className}`);
68+
69+
// Kiểm tra nếu phần tử đã tồn tại, chỉ cập nhật nội dung
6670
if (exist) {
67-
exist.textContent = numberFormat(dislikeCount);
71+
const currentText = exist.textContent;
72+
const newText = numberFormat(dislikeCount);
73+
74+
// Chỉ cập nhật nếu nội dung thay đổi
75+
if (currentText !== newText) {
76+
exist.textContent = newText;
77+
}
6878
} else {
6979
let dislikeText = document.createElement("div");
7080
dislikeText.classList.add(className);
7181
dislikeText.textContent = numberFormat(dislikeCount);
7282
button.appendChild(dislikeText);
83+
7384
listeners.push(
7485
UfsGlobal.DOM.onElementRemoved(dislikeText, () =>
7586
makeUI(dislikeCount)
7687
)
7788
);
7889
}
7990

80-
// fix button style
91+
// Sửa lại phong cách của nút
8192
button.style.width = "auto";
8293
const dislikeIcon = button.querySelector(
8394
".yt-spec-button-shape-next__icon"
@@ -94,9 +105,9 @@ export default {
94105
}
95106

96107
function run() {
97-
// remove all pre listeners
108+
// Xóa tất cả listeners trước đó
98109
listeners.forEach((fn) => fn?.());
99-
listeners = []; // Reset listeners array after clearing
110+
listeners = []; // Reset listeners array sau khi xóa
100111

101112
if (isShorts()) listeners.push(listenShort());
102113
else listeners.push(listenVideo());
@@ -124,7 +135,6 @@ const cached = {};
124135

125136
const getDislikeDataDebounced = UfsGlobal.Utils.debounce(getDislikeData, 100);
126137

127-
// Source code extracted from https://chrome.google.com/webstore/detail/return-youtube-dislike/gebbhagfogifgggkldgodflihgfeippi
128138
async function getDislikeData(videoId, callback) {
129139
if (!videoId) return;
130140

0 commit comments

Comments
 (0)