-
Notifications
You must be signed in to change notification settings - Fork 0
/
unsubscribe.js
59 lines (47 loc) · 2.18 KB
/
unsubscribe.js
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
49
50
51
52
53
54
55
56
57
58
59
// To nuke all your Youtube channels subscriptions
// Go to https://www.youtube.com/feed/channels
// Open Developer Console
// Copy and Paste this file's contents and Press Enter
// Refresh the page and repeat the process until all subscriptions are removed
async function scrollToBottom() {
window.scrollTo(0, document.documentElement.scrollHeight);
await delay(1000);
if (window.innerHeight + window.scrollY < document.documentElement.scrollHeight) {
await scrollToBottom();
}
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function unsubscribe(item) {
await item.click();
// const unsubscribeXPath = '//*[@id="items"]/ytd-menu-service-item-renderer[4]/tp-yt-paper-item'
const unsubscribeXPath = '//*[contains(text(), "Unsubscribe")]'
var unsubscribeSnapshot = document.evaluate(unsubscribeXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (unsubscribeSnapshot.singleNodeValue)
unsubscribeSnapshot.singleNodeValue.click();
else
console.log("Element not found.");
const confirmXPath = '//*[@id="confirm-button"]/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]'
const messageXPath = '//*[@id="scrollable"]/yt-formatted-string'
var result = document.evaluate(confirmXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (result.singleNodeValue) {
result.singleNodeValue.click();
console.log(document.evaluate(messageXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent, "Yes")
} else
console.log("Element not found.");
}
async function unsubscribeAll(snapshot) {
for (let i = 0; i <= snapshot.snapshotLength; i++) {
await unsubscribe(snapshot.snapshotItem(i));
await delay(1000);
}
}
try {
await scrollToBottom();
console.log("Scrolling complete!");
} catch (error) {
console.log("Error", error)
}
var snapshot = document.evaluate('//*[@id="notification-preference-button"]/ytd-subscription-notification-toggle-button-renderer-next/yt-button-shape/button', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
await unsubscribeAll(snapshot)