Created
January 22, 2025 15:07
-
-
Save koloved/df83a474b29877d6307eee366859e374 to your computer and use it in GitHub Desktop.
Автоматически исключает YouTube с на страницах яндекс видео
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Yandex Video - Smart YouTube Filter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Автоматически исключает YouTube с на страницах яндекс видео | |
// @author NN | |
// @match https://yandex.ru/video/* | |
// @match https://ya.ru/video/* | |
// @match https://yandex.com/video/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const REQUIRED_PARAMS = { | |
'from': 'tabbar', | |
'nohost': 'www.youtube.com' | |
}; | |
// Проверяем необходимость обновления | |
const currentUrl = new URL(window.location.href); | |
const searchParams = currentUrl.searchParams; | |
let needsReload = false; | |
for (const [param, value] of Object.entries(REQUIRED_PARAMS)) { | |
if (searchParams.get(param) !== value) { | |
searchParams.set(param, value); | |
needsReload = true; | |
} | |
} | |
// Умная перезагрузка с защитой от цикла | |
if (needsReload) { | |
const newUrl = currentUrl.toString(); | |
// Сохраняем оригинальный URL в sessionStorage | |
if (!sessionStorage.getItem('yandexVideoRedirect')) { | |
sessionStorage.setItem('yandexVideoRedirect', 'executed'); | |
window.location.replace(newUrl); | |
} else { | |
sessionStorage.removeItem('yandexVideoRedirect'); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment