Skip to content

Instantly share code, notes, and snippets.

@amarilindra
Last active April 28, 2023 07:34
Show Gist options
  • Save amarilindra/346a64bf0406fb1e618cab1f61506e8c to your computer and use it in GitHub Desktop.
Save amarilindra/346a64bf0406fb1e618cab1f61506e8c to your computer and use it in GitHub Desktop.
This code automates the process of unsubscribing from all YouTube channels. When the code runs, it will first fetch all the channels present in the user's YouTube account and then click the "Unsubscribe" button for each channel one by one. The code also logs the process and displays the number of channels unsubscribed out of the total number of …
(async function unsubscribeChannels() {
// Set delay time to wait for confirmation dialog
const UNSUBSCRIBE_DELAY_TIME = 2000
// Function to execute function after delay
const executeAfterDelay = (func, delay) => new Promise((resolve, reject) => {
setTimeout(() => {
func()
resolve()
}, delay)
})
// Get all channels and count number of channels
const channels = Array.from(document.getElementsByTagName(ytd - channel - renderer))
const numOfChannels = channels.length
console.log($ {
numOfChannels
}
channels found.)
// Unsubscribe from each channel and log the process
let unsubscribedChannels = 0
for (const channel of channels) {
channel.querySelector([aria - label ^= 'Unsubscribe from']).click()
await executeAfterDelay(() => {
document.getElementsByTagName(yt - confirm - dialog - renderer)[0].querySelector(#confirm - button).click()
console.log(Unsubscribed $ {
unsubscribedChannels + 1
}
/${numOfChannels})
unsubscribedChannels++
}, UNSUBSCRIBE_DELAY_TIME)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment