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); + } + }); + })();