Rezka+

Добавляет кнопки под постерами на HDRezka для поиска фильмов на разных торрент-трекерах или других сайтах

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Rezka+
// @name:en      Rezka+
// @name:ru      Rezka+
// @name:uk      Rezka+
// @namespace    https://rezka.ag/
// @version      1.8.2
// @description:en Adds buttons under posters on HDRezka for searching movies on various torrent trackers and other sites.
// @description:ru Добавляет кнопки под постерами на HDRezka для поиска фильмов на разных торрент-трекерах или других сайтах.
// @description:uk Додає кнопки під постерами на HDRezka для пошуку фільмів на різних торрент-трекерах або інших сайтах.
// @description:be Дадае кнопкі пад постэрамі на HDRezka для пошуку фільмаў на розных торэнт-трекерах або іншых сайтах.
// @description:pl Dodaje przyciski pod plakatami na HDRezka do wyszukiwania filmów na różnych trackerach torrentowych lub innych stronach.
// @description:bg Добавя бутони под постерите на HDRezka за търсене на филми в различни торент тракери или други сайтове.
// @description:ro Adaugă butoane sub postere pe HDRezka pentru căutarea filmelor pe diferite trackere torrent sau alte site-uri.
// @description:ka HDRezka-ზე პოსტერების ქვეშ ღილაკებს ამატებს ფილმების ძებნისთვის სხვადასხვა ტორენტ ტრეკერებზე ან სხვა საიტებზე.
// @description:az HDRezka-da posterlərin altında filmləri müxtəlif torrent trekerlərində və ya digər saytlarda axtarmaq üçün düymələr əlavə edir.
// @description:kk HDRezka-да постерлердің астында фильмдерді әртүрлі торрент-трекерлерде немесе басқа сайттарда іздеу үшін батырмалар қосады.
// @description:uz HDRezka-da posterlar ostida filmlarni turli torrent-trekerlar yoki boshqa saytlarda qidirish uchun tugmalar qo'shadi.
// @author       CgPT & Vladimir0202
// @include      /^https?:\/\/.*rezk.*\/.*$/
// @icon         https://static.hdrezka.ac/templates/hdrezka/images/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @license MIT
// @description Добавляет кнопки  под постерами на HDRezka для поиска фильмов на разных торрент-трекерах или других сайтах
// ==/UserScript==

(function () {
    'use strict';

    // Получаем список трекеров из хранилища Tampermonkey или создаем дефолтный
    const savedTrackers = GM_getValue('rezkaTrackers', [
        { name: 'RuTracker', urlTemplate: 'https://rutracker.org/forum/tracker.php?nm={query}', icon: 'https://rutracker.org/favicon.ico' },
        { name: 'Kinozal.TV', urlTemplate: 'https://kinozal.tv/browse.php?s={query}', icon: 'https://kinozal.tv/pic/favicon.ico' },
        { name: 'RuTor', urlTemplate: 'http://rutor.info/search/0/0/100/0/{query}', icon: 'http://rutor.info/favicon.ico'},
        { name: 'NNM.Club', urlTemplate: 'https://nnmclub.to/forum/tracker.php?nm={query}', icon: 'https://nnmstatic.win/favicon.ico'},
        { name: 'Hurtom', urlTemplate: 'https://toloka.to/tracker.php?nm={queryEng}', icon: 'https://toloka.to/favicon.ico'},
        { name: 'КиноПоиск', urlTemplate: 'https://www.kinopoisk.ru/index.php?kp_query={query}', icon: 'https://www.google.com/s2/favicons?sz=64&domain=kinopoisk.ru'},
        { name: 'Kinorium', urlTemplate: 'https://ru.kinorium.com/search/?q={query}', icon: 'https://ru.kinorium.com/favicon.ico'},
        { name: 'Youtube', urlTemplate: 'https://www.youtube.com/results?search_query={query}', icon: 'https://www.youtube.com/favicon.ico'},
    ]);

    // Сохраняем трекеры в хранилище Tampermonkey
    function saveTrackers() {
        GM_setValue('rezkaTrackers', savedTrackers);
    }

    // Добавляем кнопку для добавления сайта
    function addNewTrackerButton(container) {
        const addButton = document.createElement('button');
        addButton.textContent = '+';
        addButton.title = 'Добавить новый сайт для поиска';
        addButton.style.width = '12px';
        addButton.style.height = '12px';
        addButton.style.border = '1px solid #ccc';
        addButton.style.backgroundColor = '#f0f0f0';
        addButton.style.borderRadius = '5px';
        addButton.style.display = 'flex';
        addButton.style.alignItems = 'center';
        addButton.style.justifyContent = 'center';
        addButton.style.cursor = 'pointer';

        addButton.addEventListener('mouseover', () => {
            addButton.style.transform = 'scale(1.1)';
            addButton.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.3)';
            addButton.style.backgroundColor = '#DFDCD8';
        });

        addButton.addEventListener('mouseout', () => {
            addButton.style.transform = 'scale(1)';
            addButton.style.boxShadow = 'none';
            addButton.style.backgroundColor = '#f0f0f0';
        });

        addButton.addEventListener('click', async () => {
            const name = prompt('Введите название сайта:');
            const urlTemplate = prompt('Введите URL шаблон (используйте {query} или {queryEng} для поиска):');

            if (name && urlTemplate) {
                // Извлечение домена из URL шаблона
                const domainMatch = urlTemplate.match(/^(https?:\/\/[^/]+)/);
                let icon = '';
                if (domainMatch) {
                    const faviconUrl = `${domainMatch[1]}/favicon.ico`; // Основной путь к favicon
                    try {
                        // Проверяем доступность favicon
                        const response = await fetch(faviconUrl, { method: 'HEAD' });
                        if (response.ok) {
                            icon = faviconUrl; // Если доступен, используем его
                        } else {
                            throw new Error('Favicon not found');
                        }
                    } catch (error) {
                        // Если favicon не найден, используем Google Favicon API
                        icon = `https://www.google.com/s2/favicons?domain=${domainMatch[1]}`;
                    }
                }

                // Добавляем сайт в трекеры
                savedTrackers.push({ name, urlTemplate, icon });
                saveTrackers();
                alert('Сайт успешно добавлен. Перезагрузите страницу, чтобы увидеть изменения.');
            }
        });

        container.appendChild(addButton);
    }

    // Основной процесс добавления кнопок
    const movieCards = document.querySelectorAll('.b-content__columns');

    movieCards.forEach(card => {
        // Извлекаем название фильма
        const titleElement = card.querySelector('.b-post__title');
        if (!titleElement) return;
        const title = titleElement.textContent.trim();

        const titleEngElement = card.querySelector('.b-post__origtitle');
        const titleEng = titleEngElement ? titleEngElement.textContent.trim() : '';

        // Извлекаем год из ссылки внутри .b-post__info
        const yearLink = document.querySelector('.b-post__info a[href*="/year/"]');
        let year = '';
        if (yearLink) {
            year = yearLink.textContent.trim().replace('года', '').trim();
        }

        // Создаем контейнер для кнопок
        const buttonContainer = document.createElement('div');
        buttonContainer.style.display = 'flex';
        buttonContainer.style.flexWrap = 'wrap';
        buttonContainer.style.gap = '5px';
        buttonContainer.style.marginTop = '10px';

        // Добавляем кнопки для каждого сайта
        savedTrackers.forEach(tracker => {
            const button = document.createElement('a');
            const query = encodeURIComponent(`${title} ${titleEng} ${year}`);
            const queryEng = encodeURIComponent(`${titleEng} ${year}`);
            const url = tracker.urlTemplate
            .replace('{query}', query)
            .replace('{queryEng}', queryEng);
            button.href = url;
            button.target = '_blank';
            button.title = tracker.name;
            button.style.width = '12px';
            button.style.height = '12px';
            //button.style.border = '1px solid #ccc';
            //button.style.backgroundColor = '#fff';
            button.style.borderRadius = '5px';
            button.style.backgroundImage = `url(${tracker.icon})`;
            button.style.backgroundSize = 'contain';
            button.style.backgroundRepeat = 'no-repeat';
            button.style.backgroundPosition = 'center';

            button.addEventListener('mouseover', () => {
            button.style.transform = 'scale(1.1)';
            button.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.3)';
            });

            button.addEventListener('mouseout', () => {
            button.style.transform = 'scale(1)';
            button.style.boxShadow = 'none';
            });

            buttonContainer.appendChild(button);
        });

        // Добавляем кнопку для добавления сайта
        addNewTrackerButton(buttonContainer);

        // Вставляем контейнер под постером
        const posterContainer = card.querySelector('.b-post__infotable_left');
        if (posterContainer) {
            posterContainer.appendChild(buttonContainer);
        }
    });

    console.log('Кнопки добавлены под постерами!');
})();