-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
48 lines (40 loc) · 1.31 KB
/
content.js
File metadata and controls
48 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Remove all youtube subscriptions
let stopUnsubscribe = false;
let unsubscribeInterval;
chrome.runtime.onMessage.addListener((message) => {
if (message.action === 'startUnsubscribe') {
stopUnsubscribe = false;
startUnsubscribe();
} else if (message.action === 'stopUnsubscribe') {
stopUnsubscribe = true;
clearInterval(unsubscribeInterval);
}
});
function startUnsubscribe() {
i = 0;
unsubscribeInterval = setInterval(unsubscribeChannel, 500);
}
function unsubscribeChannel() {
if (stopUnsubscribe) {
clearInterval(unsubscribeInterval);
return;
}
const channelRenderers = Array.from(document.getElementsByTagName('ytd-channel-renderer'));
const channelCount = channelRenderers.length;
if (i < channelCount) {
const unsubscribeButton = channelRenderers[i].querySelector("[aria-label^='Unsubscribe from']");
if (unsubscribeButton) {
unsubscribeButton.click();
setTimeout(() => {
const confirmButton = document.getElementById('confirm-button').querySelector("[aria-label^='Unsubscribe'");
if (confirmButton) {
confirmButton.click();
const channelToRemove = channelRenderers[i];
channelToRemove.parentNode.removeChild(channelToRemove);
}
}, 300);
}
} else {
clearInterval(unsubscribeInterval);
}
}