-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-watch.js
More file actions
44 lines (35 loc) · 1.19 KB
/
content-watch.js
File metadata and controls
44 lines (35 loc) · 1.19 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
// Remove all youtube watch later
let stopRemoving = false;
chrome.runtime.onMessage.addListener(async (message) => {
if (message.action === 'startNewAction') {
stopRemoving = false;
await removeWatches();
} else if (message.action === 'stopNewAction') {
stopRemoving = true;
}
});
async function removeWatches() {
try {
while (!stopRemoving) {
const video = document.querySelector('ytd-playlist-video-renderer');
if (!video) {
break;
}
const actionButton = video.querySelector('#primary button[aria-label="Action menu"]');
if (actionButton) {
actionButton.click();
await sleep(250);
const removeButtons = Array.from(document.querySelectorAll('yt-formatted-string'))
.filter((button) => button.textContent.includes('Remove from'));
for (const button of removeButtons) {
button.click();
await sleep(250);
}
}
}
} catch (error) {
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}