-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
76 lines (64 loc) · 2.15 KB
/
script.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Get all video elements from the playlist and transform them to array
let videos = document.getElementsByTagName('ytd-playlist-video-renderer')
videos = Array.prototype.slice.call(videos)
// Skip set amount of videos from the beginning (optional)
const skipVideoAmount = 0
videos = videos.slice(0 - videos.length + skipVideoAmount)
// Filter videos for only authors you want to delete (optional)
const authors = ['CHANNEL_NAME']
videos = videos.filter(video => {
const author = getAuthorOfVideo(video)
if (authors.indexOf(author) != -1) return false
return true
})
// Get remove button from popup
function getDeleteBtnFromPopup() {
const popup = document.getElementsByTagName('ytd-popup-container')
const popupBtns = popup[0].getElementsByTagName('ytd-menu-service-item-renderer')
return popupBtns[2]
}
// Open popup for specific video
function openPopupForVideo(video) {
const btnOuter = video.getElementsByTagName('ytd-menu-renderer')[0]
btnOuter.click()
btnOuter.getElementsByTagName('yt-icon-button')[0].click()
}
// Get author of the video
function getAuthorOfVideo(video) {
return video.getElementsByClassName('yt-formatted-string')[0].innerText
}
// Wait for set amount of miliseconds synchronously (currently unneeded)
function synchronousWait(ms) {
const start = Date.now()
let now = start;
while (now - start < ms) {
now = Date.now();
}
}
// Remove the specified video
function removeVideo(video) {
video.scrollIntoView()
const author = getAuthorOfVideo(video)
if (authors.indexOf(author) != -1) {
console.log(`Video by ${author} is okay`)
return
}
console.log(`Attempting to remove video by ${author}`)
openPopupForVideo(video)
let removeBtn = getDeleteBtnFromPopup()
if (!removeBtn) {
console.error(`Process error - remove button wasn't found`)
console.error(video)
}
else {
removeBtn.click()
document.body.click()
console.log('Remove attempt successful')
}
}
// Remove all videos asynchronously
for (let i = 0; i < videos.length; i++) {
setTimeout(() => {
removeVideo(videos[i])
}, i * 1000)
}