From 65bd885723ff2430212310ccfbfd9ba94322da8c Mon Sep 17 00:00:00 2001 From: lukas91 Date: Tue, 11 Mar 2025 11:59:41 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20LE:=20Delete=20NoPopular=20Video.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LE: Delete NoPopular Video.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/LE: Delete NoPopular Video.js b/LE: Delete NoPopular Video.js index d17b0dc..fbf774e 100644 --- a/LE: Delete NoPopular Video.js +++ b/LE: Delete NoPopular Video.js @@ -1,8 +1,8 @@ // ==UserScript== // @name LE: Delete NoPopular Video // @namespace http://tampermonkey.net/ -// @version 2025-01-04 -// @description try to take over the world! +// @version 2025-03-11 +// @description Удаляет непопулярные видео на YouTube. // @author LE // @match https://www.youtube.com/watch?v=* // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com @@ -11,23 +11,40 @@ // ==/UserScript== (function() { + let lastUrl = location.href; - setTimeout(() => { + function deleteNoPopularVideos() { document.querySelectorAll(`span.inline-metadata-item.style-scope.ytd-video-meta-block`).forEach(span => { const text = span.textContent.trim(); - // Проверяем, соответствует ли текст нужному шаблону - if (/^\d+\sпросмотр*/.test(text)) { + if (/^\d+\sпросмот*/.test(text)) { let parent = span; - // Поднимаемся по дереву, пока не найдем while (parent && parent.tagName !== 'YTD-COMPACT-VIDEO-RENDERER') { parent = parent.parentElement; } - // Удаляем найденный элемент if (parent) { parent.remove(); } } }); - }, 5000); // Задержка в миллисекундах (5000 = 5 секунд) + } -})(); \ No newline at end of file + function startScript(vTime) { + setTimeout(deleteNoPopularVideos, vTime); + } + + + // Запускаем при загрузке страницы + startScript(5000); + startScript(10000); + startScript(20000); + + // Следим за изменением URL (например, при переходе по видео без полной перезагрузки страницы) + const observer = new MutationObserver(() => { + if (location.href !== lastUrl) { + lastUrl = location.href; + startScript(); + } + }); + + observer.observe(document.body, { childList: true, subtree: true }); +})();