Last active
December 14, 2021 14:21
-
-
Save AsP3X/ef54e5c1a7f4c8d5eb83da314dd0eeaf to your computer and use it in GitHub Desktop.
Removing all video inside of the youtubes watch later playlist.
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
var clearTimer; | |
function clearWatchList(interval) {clearTimer = setInterval(clearWatchLater, interval);} | |
function getButtonAttr() { | |
var menuName = ["Aktionsmenü", "Action menu"] | |
var buttons = document.querySelectorAll("#button"); | |
for (var i = 0; i < buttons.length; i++) { | |
var context = buttons[i].getAttribute("aria-label"); | |
if (menuName.includes(context)) | |
return buttons[i].getAttribute("aria-label"); | |
} | |
} | |
function getPlaylistName() { | |
var playlistElem_watchLater = document.querySelectorAll("#title > yt-formatted-string > a")[0].innerHTML; | |
var playlistElem = document.getElementById("text-displayed"); | |
if (playlistElem) { | |
return playlistElem.innerHTML; | |
} else { | |
return playlistElem_watchLater; | |
} | |
} | |
function getVideoCount() { | |
var elem = document.querySelectorAll("#stats > yt-formatted-string:nth-child(1) > span:nth-child(1)"); | |
if (!elem) return 0; | |
var count = elem[0].innerHTML; | |
return ((count - 1)); | |
} | |
function evaluate(playlistName) { | |
return document.evaluate(`//span[contains(text(),"${playlistName}")]`,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); | |
} | |
function killSwitch() { | |
clearInterval(clearTimer); | |
} | |
function clearWatchLater() { | |
var selectorLabel = getButtonAttr(); | |
var playlistName = getPlaylistName(); | |
var videos = getVideoCount(); | |
document.querySelector(`#primary button[aria-label="${selectorLabel}"]`).click(); | |
var things = evaluate(playlistName); | |
for (var i = 0; i < videos; i++) { | |
things.snapshotItem(i).click(); | |
if (i == videos) { | |
killSwitch(); | |
} | |
console.log(getVideoCount()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment