Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save koloved/df83a474b29877d6307eee366859e374 to your computer and use it in GitHub Desktop.
Save koloved/df83a474b29877d6307eee366859e374 to your computer and use it in GitHub Desktop.
Автоматически исключает YouTube с на страницах яндекс видео
// ==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