Skip to content

Instantly share code, notes, and snippets.

@cmondev

cmondev/correct-elements.js Secret

Last active Oct 17, 2020
Embed
What would you like to do?
YouTube Reaction Overview 2
function getVideoAnchorElements(element) {
let elements = [];
const tagName = element.tagName.toLowerCase();
switch(tagName) {
case "ytd-search":
elements = element.querySelectorAll("ytd-video-renderer #video-title");
break;
case "ytd-browse":
elements = getCorrectElementsForYtdBrowse(element);
break;
default:
break;
}
return elements;
}
function getCorrectElementsForYtdBrowse(element) {
const pageSubType = element.getAttribute("page-subtype");
if(pageSubType === "subscriptions") {
return element.querySelectorAll("ytd-grid-video-renderer #video-title");
}
else if(pageSubType === "home") {
return element.querySelectorAll("ytd-rich-grid-media #video-title-link");
}
// Either "trends" or something else
else {
return element.querySelectorAll("ytd-video-renderer #video-title");
}
}
(function() {
window.addEventListener("load", function(event) {
getCurrentElementAndEvalData();
});
})();
function getCurrentElementAndEvalData() {
const root = document.querySelector("#content #page-manager");
const currentElement = root.querySelector("[role='main']");
getIdsAndQueryData(getVideoAnchorElements(currentElement));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.