From 0ffb1f7c26f78ce87882d7df5cbf452a40d0c9c8 Mon Sep 17 00:00:00 2001 From: lukas91 Date: Tue, 11 Mar 2025 12:00:52 +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 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/LE: Delete NoPopular Video.js b/LE: Delete NoPopular Video.js index fbf774e..b2b2f0e 100644 --- a/LE: Delete NoPopular Video.js +++ b/LE: Delete NoPopular Video.js @@ -1,7 +1,7 @@ // ==UserScript== // @name LE: Delete NoPopular Video // @namespace http://tampermonkey.net/ -// @version 2025-03-11 +// @version 2025-01-04 // @description Удаляет непопулярные видео на YouTube. // @author LE // @match https://www.youtube.com/watch?v=* @@ -12,6 +12,7 @@ (function() { let lastUrl = location.href; + let tabActivatedOnce = false; function deleteNoPopularVideos() { document.querySelectorAll(`span.inline-metadata-item.style-scope.ytd-video-meta-block`).forEach(span => { @@ -32,7 +33,6 @@ setTimeout(deleteNoPopularVideos, vTime); } - // Запускаем при загрузке страницы startScript(5000); startScript(10000); @@ -42,9 +42,20 @@ const observer = new MutationObserver(() => { if (location.href !== lastUrl) { lastUrl = location.href; - startScript(); + startScript(5000); } }); observer.observe(document.body, { childList: true, subtree: true }); + + // Запуск скрипта, если вкладка была открыта в фоне и на неё переключились + document.addEventListener(`visibilitychange`, () => { + if (!tabActivatedOnce && document.visibilityState === `visible`) { + tabActivatedOnce = true; + setTimeout(() => { + startScript(3000); + }, 3000); + } + }); + })();