Anarios / return-youtube-dislike

Chrome extension to return youtube dislikes
https://returnyoutubedislike.com/
GNU General Public License v3.0
12.34k stars 548 forks source link

Extension fix for the latest YouTube update #991

Closed Moondarker closed 7 months ago

Moondarker commented 7 months ago

Fixes #981 (also for duplicates: fixes #989, fixes #990) Should be backwards compatible if this is yet another A/B test from YouTube, but tbh it'd be great if we could find all the outdated code and drop it at some point

Tested on: Windows 10, Chrome Stable 119.0.6045.161

Moondarker commented 7 months ago

Also, it looks like the version in extension stores is somehow more recent than the code in main branch at least by 2 patches, lmk if you want me to do anything about it...

Anarios commented 7 months ago

Thanks a lot.

GladistonXD commented 7 months ago

Could automate this so that if YouTube makes new changes, it automatically identifies the button, it would be something more or less like this:

function getDislikeButton() {
  let allElements = document.getElementsByTagName("*");
  let firstElementWithDislikeButton = null;

  for (let i = 0; i < allElements.length; i++) {
    let element = allElements[i];
    if (element.tagName.toLowerCase().includes('dislike-button')) {
      firstElementWithDislikeButton = element;
      break;
    }
  }

  if (firstElementWithDislikeButton) {
    let elementsInside = firstElementWithDislikeButton.getElementsByTagName('*');
    let elementsWithDislikeRegex = [];

    Array.from(elementsInside).forEach((element) => {
      let regex = /[^"</]*dislike-button[^">]*/;
      if (regex.test(element.outerHTML)) {
        elementsWithDislikeRegex.push(element);
      }
    });

    if (elementsWithDislikeRegex.length > 0) {
      let lastElement = elementsWithDislikeRegex[elementsWithDislikeRegex.length - 1];
      return lastElement;
    }
  }
}

function getLikeButton() {
  let allElements = document.getElementsByTagName("*");
  let elementsWithDislikeButton = [];

  for (let i = 0; i < allElements.length; i++) {
    let element = allElements[i];
    if (element.tagName.toLowerCase().includes('dislike-button')) {
      elementsWithDislikeButton.push(element);
    }
  }

  if (elementsWithDislikeButton.length > 0) {
    return elementsWithDislikeButton[0];
  }
}