Created
May 1, 2025 10:00
-
-
Save alexander480/799143c5bd45271995f6e79a49eca020 to your computer and use it in GitHub Desktop.
Move YouTube Videos From "Watch Later" To A New Playlist
This file contains hidden or 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
// Move YouTube Videos From "Watch Later" To A New Playlist. | |
setInterval(function () { | |
// define name of playlist to move videos to | |
const newPlaylistName = 'old watch later'; | |
// 1) grab the first video entry | |
const video = document.querySelector('ytd-playlist-video-renderer'); | |
if (!video) return; | |
// helper to open that video's action menu | |
function openMenu(cb) { | |
const btn = video.querySelector('ytd-menu-renderer yt-icon-button'); | |
if (!btn) return console.warn('No action button'); | |
btn.click(); | |
setTimeout(cb, 400); | |
} | |
// 2) open menu & click “Save to…” | |
openMenu(() => { | |
const items = Array.from(document.querySelectorAll('ytd-menu-service-item-renderer')); | |
const saveItem = items.find(el => | |
el.innerText.trim().toLowerCase().startsWith('save to') | |
); | |
if (!saveItem) { | |
console.warn('“Save to…” not found:', items.map(el => el.innerText)); | |
return; | |
} | |
saveItem.click(); | |
// 3) wait for dialog, click to add to new specified playlist | |
setTimeout(() => { | |
const option = Array.from(document.querySelectorAll('yt-formatted-string')) | |
.find(el => el.innerText.trim().toLowerCase() === newPlaylistName); | |
if (!option) { | |
console.warn('Playlist “' + newPlaylistName + '” not found'); | |
} else { | |
option.click(); | |
} | |
// 4) close save dialog | |
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' })); | |
// 5) after a short pause, re-open menu & click “Remove from Watch later” | |
setTimeout(() => { | |
openMenu(() => { | |
const remItems = Array.from(document.querySelectorAll('ytd-menu-service-item-renderer')); | |
const removeItem = remItems.find(el => | |
el.innerText.trim().toLowerCase().includes('remove from watch later') | |
); | |
if (!removeItem) { | |
console.warn('“Remove from Watch later” not found:', remItems.map(el => el.innerText)); | |
} else { | |
removeItem.click(); | |
} | |
}); | |
}, 500); | |
}, 500); | |
}); | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment