From 30213b9ecf68788c46f40601b205e9d6fe6db280 Mon Sep 17 00:00:00 2001 From: Snow <35224538+KibbeWater@users.noreply.github.com> Date: Wed, 16 Oct 2024 01:27:27 +0200 Subject: [PATCH] Unobserved child node removals (#1096) * fix(userscript): listen to node removals * fix(combined): observe node removals --- .../UserScript/Return Youtube Dislike.user.js | 9 +++++++-- Extensions/combined/src/events.js | 1 + Extensions/combined/src/state.js | 14 +++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index 2bb961c2..c5136305 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -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() { @@ -648,6 +652,7 @@ function setEventListeners(evt) { { attributes: true, subtree: true, + childList: true, }, updateDOMDislikes, ); diff --git a/Extensions/combined/src/events.js b/Extensions/combined/src/events.js index 92511c71..326eaa7c 100644 --- a/Extensions/combined/src/events.js +++ b/Extensions/combined/src/events.js @@ -116,6 +116,7 @@ function createSmartimationObserver() { { attributes: true, subtree: true, + childList: true, }, updateDOMDislikes, ); diff --git a/Extensions/combined/src/state.js b/Extensions/combined/src/state.js index 90dd1b8e..0ae6cfa0 100644 --- a/Extensions/combined/src/state.js +++ b/Extensions/combined/src/state.js @@ -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; } }