Last active
September 21, 2018 23:30
-
-
Save edc/5689416 to your computer and use it in GitHub Desktop.
Add a whole Youtube playlist to watch later - so you can clone the list easily
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
// this script copies a youtube playlist to the "watch later" list, so you can easily clone the | |
// list by creating a new one off the watch later list. You must run this on a playlist overview | |
// page like http://www.youtube.com/playlist?list=xxxxxxxxx | |
// this script is meant to be converted into a bookmarklet, using something like http://mrcoles.com/bookmarklet/ | |
// after conversion, it becomes this: | |
// javascript:(function()%7Bvar%20buttons%20%3D%20document.querySelectorAll(%22button.addto-watch-later-button%22)%3Bvar%20videos%20%3D%20document.querySelectorAll(%22.playlist-video-item%22)%3Bif%20(videos.length%20!%3D%20buttons.length)%20%7Balert(%22Some%20videos%20are%20already%20in%20watch%20later!%20Found%20%22%20%2B%20videos.length%20%2B%20%22%20videos%20but%20%22%20%2B%20buttons.length%20%2B%20%22%20buttons.%20Abort%20now.%22)%3B%7D%20else%20%7Bif%20(confirm(%22Add%20%22%20%2B%20buttons.length%20%2B%20%22%20videos%3F%22))%20%7Bvar%20dialog%20%3D%20document.createElement(%22h1%22)%3Bdialog.innerHTML%20%3D%20%22%3Cdiv%20style%3D'color%3Ared%3Bposition%3A%20fixed%3Btop%3A%200%3Bfont-size%3A%20100px%3Bmargin%3A%20120px%20auto%3Bbackground%3Awhitesmoke%3Bz-index%3A%201000%3Bwidth%3A%20100%25%3Btext-align%3A%20center%3B'%3EWorking...%3C%2Fdiv%3E%22%3Bdocument.getElementById(%22body-container%22).appendChild(dialog)%3Bfor%20(var%20i%20%3D%20buttons.length%20-%201%3B%20i%20%3E%3D%200%3B%20i%20--)%20%7BsetTimeout(function(j)%7Bbuttons%5Bj%5D.click()%3B%20console.log(j%20%2B%20'%20left')%3B%20if%20(j%20%3D%3D%200)%20alert(%22all%20done%22)%20%7C%7C%20dialog.parentElement.removeChild(dialog)%7D%2C2000*(buttons.length-i-1)%2C%20i)%3B%7D%7D%7D%7D)() | |
var buttons = document.querySelectorAll("button.addto-watch-later-button"); | |
var videos = document.querySelectorAll(".playlist-video-item"); | |
if (videos.length != buttons.length) { | |
alert("Some videos are already in watch later! Found " + videos.length + " videos but " + buttons.length + " buttons. Abort now."); | |
} else { | |
if (confirm("Add " + buttons.length + " videos?")) { | |
var dialog = document.createElement("h1"); | |
dialog.innerHTML = "<div style='color:red;position: fixed;top: 0;font-size: 100px;margin: 120px auto;background:whitesmoke;z-index: 1000;width: 100%;text-align: center;'>Working...</div>"; | |
document.getElementById("body-container").appendChild(dialog); | |
for (var i = buttons.length - 1; i >= 0; i --) { | |
setTimeout(function(j){buttons[j].click(); console.log(j + ' left'); if (j == 0) alert("all done") || dialog.parentElement.removeChild(dialog)}, | |
2000*(buttons.length-i-1), i); | |
} | |
} | |
} | |
tried loatroll's tip. 'add 0 videos?' every time
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works with minor change (.playlist-video-item to .pl-video)