How I automated subscribing to 1000+ YouTube channels using JavaScript

Simple ways to utilize your javascript knowledge

So, I had a new google account and I wanted all my old channels which I had subscribed to in my old account. The simple way was to just open the account’s channel page and subscribe to all the channels one by one by manually clicking them. 🤷‍♂️

Initially, I started by manually clicking the subscribe button for every channel that was there in my old account. It was time-consuming and a boring task.

And then I got the idea to use my JavaScript skills to automate this task. So, I quickly wrote a small script (it took me less than an hour) to automate this task. 😁

Here’s how it looks in action ⚡️

youtube-auto-subscriber.gif

The JavaScript ✨

const allChannelsBox = document.querySelectorAll("#channel");
let totalUnsubscribedChannels = 0;
let count = 0;
let sleep = 0;
//for counting totalUnsubscribedChannels
allChannelsBox.forEach(function (channel, index) {
    if (channel.children[1].innerText === "SUBSCRIBE") {
        totalUnsubscribedChannels++;
    }
});
//for clicking all unsubscribed Channels
allChannelsBox.forEach(function (channel, index) {
    if (channel.children[1].innerText === "SUBSCRIBE") {
        setTimeout(function () {
            count++;
            console.log(
                "Current Channel ->" +
                    channel.children[0].children["title"].innerText
            );
            channel.children[1].children[0].children[0].click();
            console.log(
                "Subscribed! 😎" +
                    count +
                    "out of" +
                    totalUnsubscribedChannels +
                    "channels"
            );
        }, sleep);
        sleep += 30000;
    }
});

That’s it. I know this is a very small thing. But to me applying my knowledge to solve problems is something I really love. I totally enjoyed the coding part.❤️

Here’s the GitHub link to it. Please feel free to fork or raise a pull request. Any contribution or suggestions are welcome.😊