Skip to content

Instantly share code, notes, and snippets.

@AsP3X
Last active December 14, 2021 14:21

Revisions

  1. AsP3X revised this gist Dec 14, 2021. 1 changed file with 41 additions and 10 deletions.
    51 changes: 41 additions & 10 deletions clearWatchLater.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,57 @@
    var clearTimer;
    function clearWatchList(interval) {clearTimer = setInterval(clearWatchLater, interval);}
    function getButtonAttr() {
    var elemArray = document.querySelectorAll("#button");
    return elemArray[37].getAttribute("aria-label");
    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");
    return playlistElem.innerHTML;

    if (playlistElem) {
    return playlistElem.innerHTML;
    } else {
    return playlistElem_watchLater;
    }
    }

    function clearWatchLater(buttonName, fieldName) {
    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 = document.evaluate(`//span[contains(text(),"${playlistName}")]`,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    if (things.snapshotLength = 0) {killSwitch()}
    for (var i = 0; i < things.snapshotLength; i++) {
    var things = evaluate(playlistName);

    for (var i = 0; i < videos; i++) {
    things.snapshotItem(i).click();
    if (i == videos) {
    killSwitch();
    }
    console.log(getVideoCount());
    }

    }
    function killSwitch() {
    clearInterval(clearTimer);
    }
  2. AsP3X revised this gist Dec 14, 2021. 1 changed file with 15 additions and 2 deletions.
    17 changes: 15 additions & 2 deletions clearWatchLater.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,21 @@
    var clearTimer;
    function clearWatchList(interval) {clearTimer = setInterval(clearWatchLater, interval);}
    function getButtonAttr() {
    var elemArray = document.querySelectorAll("#button");
    return elemArray[37].getAttribute("aria-label");
    }

    function getPlaylistName() {
    var playlistElem = document.getElementById("text-displayed");
    return playlistElem.innerHTML;
    }

    function clearWatchLater(buttonName, fieldName) {
    document.querySelector('#primary button[aria-label="Aktionsmenü"]').click();
    var things = document.evaluate('//span[contains(text(),"Später ansehen")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    var selectorLabel = getButtonAttr();
    var playlistName = getPlaylistName();

    document.querySelector(`#primary button[aria-label="${selectorLabel}"]`).click();
    var things = document.evaluate(`//span[contains(text(),"${playlistName}")]`,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    if (things.snapshotLength = 0) {killSwitch()}
    for (var i = 0; i < things.snapshotLength; i++) {
    things.snapshotItem(i).click();
  3. AsP3X created this gist Dec 13, 2021.
    13 changes: 13 additions & 0 deletions clearWatchLater.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    var clearTimer;
    function clearWatchList(interval) {clearTimer = setInterval(clearWatchLater, interval);}
    function clearWatchLater(buttonName, fieldName) {
    document.querySelector('#primary button[aria-label="Aktionsmenü"]').click();
    var things = document.evaluate('//span[contains(text(),"Später ansehen")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    if (things.snapshotLength = 0) {killSwitch()}
    for (var i = 0; i < things.snapshotLength; i++) {
    things.snapshotItem(i).click();
    }
    }
    function killSwitch() {
    clearInterval(clearTimer);
    }