Adds a button to directly remove videos from the "Watch Later" playlist on YouTube
当前为
// ==UserScript==
// @name YouTube Remove button from Playlists
// @namespace http://tampermonkey.net/
// @version 0.8
// @description Adds a button to directly remove videos from the "Watch Later" playlist on YouTube
// @author You
// @match https://www.youtube.com/playlist?list=WL
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function addRemoveButtons() {
document.querySelectorAll('ytd-playlist-video-renderer').forEach(video => {
if (!video.querySelector('.remove-button')) {
const button = document.createElement('button');
button.textContent = 'Удалить';
button.classList.add('remove-button');
button.style.marginLeft = '10px';
button.style.cursor = 'pointer';
button.addEventListener('click', async () => {
const menuButton = video.querySelector('#button');
menuButton.click();
await new Promise(resolve => setTimeout(resolve, 500)); // ждём, пока меню откроется
const menuItems = document.querySelectorAll('ytd-menu-service-item-renderer');
let removed = false;
menuItems.forEach(item => {
const textElement = item.querySelector('yt-formatted-string');
if (textElement && textElement.textContent.includes('Удалить из плейлиста "Смотреть позже"')) {
textElement.click();
removed = true;
}
});
if (!removed) {
alert('Не удалось удалить видео. Пожалуйста, попробуйте снова.');
}
});
video.querySelector('#meta').appendChild(button);
}
});
}
setInterval(addRemoveButtons, 1000); // добавляем кнопки каждые 1000 мс
})();