Skip to content

Commit

Permalink
Unobserved child node removals (#1096)
Browse files Browse the repository at this point in the history
* fix(userscript): listen to node removals

* fix(combined): observe node removals
  • Loading branch information
KibbeWater authored Oct 15, 2024
1 parent 928d6df commit 30213b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Extensions/UserScript/Return Youtube Dislike.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ function setDislikes(dislikesCount) {
mobileDislikes = dislikesCount;
return;
}
getDislikeTextContainer()?.removeAttribute("is-empty");
getDislikeTextContainer().innerText = dislikesCount;

const _container = getDislikeTextContainer();
_container?.removeAttribute("is-empty");
if (_container?.innerText !== dislikesCount) {
_container.innerText = dislikesCount;
}
}

function getLikeCountFromButton() {
Expand Down Expand Up @@ -648,6 +652,7 @@ function setEventListeners(evt) {
{
attributes: true,
subtree: true,
childList: true,
},
updateDOMDislikes,
);
Expand Down
1 change: 1 addition & 0 deletions Extensions/combined/src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function createSmartimationObserver() {
{
attributes: true,
subtree: true,
childList: true,
},
updateDOMDislikes,
);
Expand Down
14 changes: 11 additions & 3 deletions Extensions/combined/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,28 @@ function setLikes(likesCount) {

function setDislikes(dislikesCount) {
cLog(`SET dislikes ${dislikesCount}`);
getDislikeTextContainer()?.removeAttribute("is-empty");

const _container = getDislikeTextContainer();
_container?.removeAttribute("is-empty");

let _dislikeText
if (!isLikesDisabled()) {
if (isMobile()) {
getButtons().children[1].querySelector(".button-renderer-text").innerText = dislikesCount;
return;
}
getDislikeTextContainer().innerText = dislikesCount;
_dislikeText = dislikesCount;
} else {
cLog("likes count disabled by creator");
if (isMobile()) {
getButtons().children[1].querySelector(".button-renderer-text").innerText = localize("TextLikesDisabled");
return;
}
getDislikeTextContainer().innerText = localize("TextLikesDisabled");
_dislikeText = localize("TextLikesDisabled");
}

if (_dislikeText != null && _container?.innerText !== _dislikeText) {
_container.innerText = _dislikeText;
}
}

Expand Down

0 comments on commit 30213b9

Please sign in to comment.