From 51c7b11809ba38478485dc4dc28ba4b82d1c74f8 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Sun, 11 Feb 2024 19:48:52 -0800 Subject: [PATCH] Add js script for cleaning Watch Later --- clean-watch-later.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 clean-watch-later.js diff --git a/clean-watch-later.js b/clean-watch-later.js new file mode 100644 index 0000000..5f09627 --- /dev/null +++ b/clean-watch-later.js @@ -0,0 +1,43 @@ +setInterval(function() { + // Click on the treedots of first video in the list + document.querySelector('#contents button#button').click(); + + // Click on the "Save to playlist" button + var save2playlist = document.evaluate('//yt-formatted-string[contains(text(),"Save to playlist")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); + save2playlist.snapshotItem(0).click(); + + // search playlist with name wel + var checkboxLabel = document.evaluate( + '//tp-yt-paper-checkbox[@id="checkbox" and .//text()[contains(., "wel")]]', + document, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null + ).singleNodeValue; + + if (checkboxLabel) { + // Check if the descendant with id "checkmark" does not have the class "hidden" + var checkmarkDescendant = checkboxLabel.querySelector('div#checkmark'); + + if (checkmarkDescendant && checkmarkDescendant.classList.contains('hidden')) { + // Click on the checkboxLabel + checkboxLabel.click(); + console.log('Added video to playlist.'); + } + else { + console.log('Video is already in the playlist.'); + } + } + + // Wait for a second before the second click + setTimeout(function() { + document.querySelector('#contents button#button').click(); + }, 2000); + + // Click on the "Remove from watch later" button + var things = document.evaluate('//span[contains(text(),"Watch later")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); + for (var i = 0; i < things.snapshotLength; i++) { + things.snapshotItem(i).click(); + } + +}, 2000);