Created
September 30, 2022 07:17
-
-
Save xtrm-en/4bf366eb06f365ef99ec8cb5acb484d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getByX(path) { | |
return document.evaluate( | |
path, | |
document, | |
null, | |
XPathResult.FIRST_ORDERED_NODE_TYPE, | |
null | |
).singleNodeValue; | |
} | |
const cardXPath = | |
"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-playlist-video-list-renderer/div[3]/ytd-playlist-video-renderer"; | |
const settingsXPath = "/div[3]/ytd-menu-renderer/yt-icon-button/button"; | |
const addToPlaylistXPath = | |
"/html/body/ytd-app/ytd-popup-container/tp-yt-iron-dropdown/div/ytd-menu-popup-renderer/tp-yt-paper-listbox/ytd-menu-service-item-renderer[3]/tp-yt-paper-item"; | |
const closeXPath = | |
"/html/body/ytd-app/ytd-popup-container/tp-yt-paper-dialog/ytd-add-to-playlist-renderer/div[1]/yt-icon-button/button"; | |
const playlistContainerXPath = "//*[@id=\"playlists\"]"; | |
const playlistElemSelector = "#checkbox #checkboxLabel #checkbox-container #checkbox-label #label"; | |
function register(id) { | |
console.log("> Registering " + id); | |
let settingsButton = getByX(cardXPath + "[" + id + "]" + settingsXPath); | |
console.log("Opening dialog..."); | |
settingsButton.click(); | |
setTimeout(() => { | |
let add = getByX(addToPlaylistXPath); | |
console.log("Opening selection modal..."); | |
add.click(); | |
setTimeout(() => { | |
let playlistsDiv = getByX(playlistContainerXPath); | |
let playlistId = 0; | |
for (let j = 0; j < playlistsDiv.children.length; j++) { | |
let playlistElem = playlistsDiv.children[j]; | |
let title = playlistElem.querySelector(playlistElemSelector).innerHTML; | |
if (title === "Actual music playlist") { | |
playlistId = j; | |
break; | |
} | |
} | |
let checkbox = document.getElementsByTagName("tp-yt-paper-checkbox")[playlistId]; | |
let close = getByX(closeXPath); | |
console.log("Adding to playlist..."); | |
checkbox.click(); | |
setTimeout(() => { | |
close.click(); | |
console.log("! Done"); | |
}, 400); | |
}, 800); | |
}, 300); | |
} | |
let count = 0; | |
setInterval(() => { | |
count++; | |
register(count); | |
}, 1800); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment