Skip to content

Instantly share code, notes, and snippets.

@nirlanka
Last active July 15, 2024 03:55
Show Gist options
  • Save nirlanka/f84d49e6b6f9b1707d7eb5365c1fcd48 to your computer and use it in GitHub Desktop.
Save nirlanka/f84d49e6b6f9b1707d7eb5365c1fcd48 to your computer and use it in GitHub Desktop.
(YouTube) Create a playlist from a channel with all its videos
// 1. Create a new playlist
// 2. Load all video thumbnails in channel in required order (scroll down until the end)
// 3. Run script:
{
const ll=document.querySelectorAll('yt-icon-button.dropdown-trigger.style-scope.ytd-menu-renderer #button'); // all videos' menu buttons
let i=0;
function loop() {
ll[i].click(); // open menu
document.querySelectorAll('tp-yt-paper-listbox ytd-menu-service-item-renderer')[2].click(); // click Add to Playlist
setTimeout(() => {
const pl=document.querySelectorAll('tp-yt-paper-dialog tp-yt-paper-checkbox')[1]; // new playlist in menu
if ((!pl.checked)) { // if not already checked
pl.click(); // click to add (checkbox)
}
document.querySelector('yt-icon-button#close-button').click(); // close playlists menu
i++;
console.log(i + '/' + ll.length); // show i/len
if (i<ll.length) { // loop non-break condition
loop(); // continue the loop
}
}, 2000); // delay for playlist menu opening
}
loop(); // start the loop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment