HatScripts / youtube-auto-liker

A userscript that automatically likes 👍 each video you watch on YouTube ▶️
68 stars 15 forks source link

Try multiple selectors to find buttons #31

Closed BleakBluets closed 1 year ago

BleakBluets commented 1 year ago

Fixes #30

Changed the button selectors for subscribe, like, and dislike to be arrays which can contain multiple selectors. If one selector fails, the next one is tried. This way, when a YouTube layout rollout splits users between two different layouts, auto-liker can support both layouts simultaneously.

The GitHub diff finder had difficulty finding the changes (it says I added 218 lines and deleted 198), but all that changed was the SELECTORS constant, and I added for-loops when assigning the subscribebutton, likebutton, and dislikebutton variables. (and I incremented the version number)

Disregard. This functionality already exists as it is. For some reason I thought the comma-separated selectors were causing the issue, but document.querySelector() grabs only the first matching tag it finds and only one style of like/dislike/subscribe button will exist on a page at a time.

BleakBluets commented 1 year ago

One problem I see is that auto-liker uses these selectors to search for the buttons every time it checks if the user is subscribed or already voted the video. Previous versions did this as well, but now that multiple selectors are being checked, performance may need to be more of a concern. I think that the selectors should be checked in the onInit() function. I'll make a separate pull request for that later and you can decide whether to merge it if you agree.

BleakBluets commented 1 year ago

Whoops forgot to mention. While testing, I removed a check for the style-default-active class in isButtonPressed(). I didn't mean to commit that change. However, all YouTube layouts use the aria-pressed attribute, so I don't think it's needed anymore unless I'm overlooking something.