Created
April 18, 2022 02:31
-
-
Save gustavothecoder/ed432753d320e1c1e745de036e9f7bbf to your computer and use it in GitHub Desktop.
YouTube subscription cleaner
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
/** | |
* This script will remove all your YouTube subscriptions loaded in the channels page, | |
* if you really want to remove all your subscriptions, you need to scroll to the bottom of | |
* the page to load all channels. | |
* | |
* Follow this steps to run the script: | |
* 1. Open the subscriptions list (https://www.youtube.com/feed/channels) | |
* 2. Scroll down until you see all the channels you want to unsubscribe | |
* 3. Open your browser console | |
* 4. Paste the code below into the console and press enter | |
* 5. That's it, now you just have to wait for the script to finish | |
*/ | |
let channel, | |
elements, | |
unsubscriberInterval, | |
promise, | |
index; | |
const channelBatches = document.querySelectorAll("[id='grid-container']"); | |
console.log('channel batches count: ' + channelBatches.length); | |
const unsubscriber = (resolve) => { | |
if (index >= elements.length - 1) { | |
clearInterval(unsubscriberInterval); | |
resolve(true); | |
} | |
channel = elements[index].querySelector( | |
"yt-formatted-string#text.ytd-channel-name" | |
).text.runs[0].text; | |
console.log("unsubscribing from " + channel); | |
console.log("progress: (" + (index + 1) + "/" + elements.length + ")"); | |
elements[index].querySelector("[aria-label^='Unsubscribe from']").click(); | |
setTimeout(() => { | |
document.getElementById("confirm-button").click(); | |
}, 2000); | |
index++; | |
}; | |
const batchUnsubscriber = (batch) => { | |
return new Promise((resolve) => { | |
elements = batch.getElementsByClassName( | |
"ytd-expanded-shelf-contents-renderer" | |
); | |
unsubscriberInterval = setInterval(() => unsubscriber(resolve), 3000); | |
}); | |
}; | |
const main = async (batchIndex) => { | |
if (batchIndex >= channelBatches.length) return; | |
index = 0; | |
await batchUnsubscriber(channelBatches[batchIndex]).then(() => | |
main(batchIndex + 1) | |
); | |
}; | |
main(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment