-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeleteYoutubePlaylists.user.js
100 lines (90 loc) · 2.5 KB
/
DeleteYoutubePlaylists.user.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ==UserScript==
// @name Delete YouTube Playlists Except First
// @namespace typpi.online
// @version 1.5
// @description Delete all YouTube playlists except the first one from YouTube Studio
// @author Nick2bad4u
// @license UnLicense
// @homepageURL https://userstyles.github.typpi.online
// @match https://studio.youtube.com/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// ==/UserScript==
(function () {
'use strict';
// Create and style the UI button
const uiButton =
document.createElement('button');
uiButton.innerText = 'Start Deleting Playlists';
uiButton.style.position = 'fixed';
uiButton.style.top = '10px';
uiButton.style.right = '10px';
uiButton.style.zIndex = '1000';
uiButton.style.padding = '10px 20px';
uiButton.style.backgroundColor = '#ff0000';
uiButton.style.color = '#ffffff';
uiButton.style.border = 'none';
uiButton.style.borderRadius = '5px';
uiButton.style.cursor = 'pointer';
document.body.appendChild(uiButton);
// Function to delete playlists
function deletePlaylists() {
// Get all menu buttons
const menuButtons = document.querySelectorAll(
'ytcp-icon-button#overflow-menu-button',
);
if (menuButtons.length > 1) {
let i = 1;
function deleteNextPlaylist() {
if (i < menuButtons.length) {
menuButtons[i].click();
setTimeout(() => {
const deleteButton = Array.from(
document.querySelectorAll(
'ytcp-text-menu yt-formatted-string.item-text',
),
).find(
(el) => el.innerText === 'Delete',
);
if (deleteButton) {
deleteButton.click();
setTimeout(() => {
const confirmButton =
document.querySelector(
'ytcp-button[id="confirm-button"]',
);
if (confirmButton) {
confirmButton.click();
i++;
setTimeout(
deleteNextPlaylist,
1000,
); // Wait for 1 seconds before the next deletion
}
}, 500);
} else {
i++;
setTimeout(
deleteNextPlaylist,
2000,
); // Move to next if delete button not found
}
}, 500);
} else {
uiButton.innerText =
'Deletion Complete';
}
}
deleteNextPlaylist();
} else {
alert(
'No playlists found or only one playlist present.',
);
}
}
// Add event listener to the button
uiButton.addEventListener('click', () => {
uiButton.innerText = 'Deleting Playlists...';
deletePlaylists();
});
})();