Closed Moondarker closed 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...
Thanks a lot.
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];
}
}
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