Skip to content

Instantly share code, notes, and snippets.

@almgwary
Created August 24, 2021 09:56
Show Gist options
  • Save almgwary/213d130b505fabbefd271ce37168ad42 to your computer and use it in GitHub Desktop.
Save almgwary/213d130b505fabbefd271ce37168ad42 to your computer and use it in GitHub Desktop.
let prevent;
const stop = () => {
prevent = true;
chrome.runtime.sendMessage({
type: "msg",
msg: "start again",
running: false
});
};
const start = () => {
const subs = document.querySelectorAll('#subscribe-button > ytd-subscribe-button-renderer > tp-yt-paper-button');
if (typeof subs === "undefined" || subs.length === 0) {
chrome.runtime.sendMessage({
type: "msg",
msg: "you dont have any subs",
running: false
});
return;
}
prevent = false;
chrome.runtime.sendMessage({
type: "msg",
msg: "click to stop",
running: true
});
const unSubscribe = (counter) => {
if (prevent) return;
if (counter < subs.length) {
setTimeout(() => {
subs[counter].scrollIntoView({
behavior: 'smooth',
block: 'start'
});
subs[counter].click();
setTimeout(() => {
const button = document.getElementById('confirm-button');
button.click();
unSubscribe(counter + 1);
}, 150 + counter);
}, 300 + counter);
return;
}
};
unSubscribe(0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment