Files
return-youtube-dislike/Extensions
SHIARJEOLATIVERNSTOVATERAPTICKBARYPINEU cb5915a3d4 Update Return Youtube Dislike.user.js (Might not be the best fix)
Here's a description you could use for a commit message, PR, or changelog entry:

Harden button-lookup functions against missing/changed DOM elements

getButtons(), getLikeButton(), and getDislikeButton() previously assumed YouTube's like/dislike DOM structure was always present and would throw a TypeError (e.g. "Cannot read properties of null/undefined") whenever the expected elements weren't found — for example during early page load, mid-navigation, or after a YouTube layout change breaks a selector.

Changes:

getLikeButton() / getDislikeButton() now cache a single getButtons() result per call instead of invoking it multiple times within the same expression, avoiding inconsistent reads if the DOM mutates between calls, and return null early if getButtons() itself returns nothing.
Audited all direct callers of these three functions and added ?. / early-return guards where a null return wasn't already handled: isVideoLiked, isVideoNotLiked, getLikeTextContainer, setLikes on the like side; mobile isVideoDisliked, and getDislikeTextContainer's fallback branch on the dislike side (both previously used ?. on the outer button but still dereferenced a possibly-null nested querySelector("button") result unguarded).
Fixed getDislikeTextContainer short-circuiting to undefined instead of null when dislikeButton is missing, which meant its result === null fallback check never triggered and it could try appending to a null button.
Fixed setDislikes checking _container?.innerText !== dislikesCount (safe) but then assigning _container.innerText = ... unguarded in the branch body, which still threw when _container was null.

No behavior change when the expected elements are present — this only prevents uncaught exceptions when they're not, letting the existing polling loop (checkForJS_Finish, 111ms interval) retry on the next tick instead of the script erroring out.
2026-08-19 16:36:18 -07:00
..