Delete YouTube Playlists Except First

Delete all YouTube playlists except the first one from YouTube Studio

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Delete YouTube Playlists Except First
// @namespace    typpi.online
// @version      1.6
// @description  Delete all YouTube playlists except the first one from YouTube Studio
// @author       Nick2bad4u
// @license      UnLicense
// @homepageURL  https://github.com/Nick2bad4u/UserStyles
// @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();
	});
})();