Kinorium +

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

目前为 2025-03-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         Kinorium +
// @namespace    https://kinorium.com/
// @version      1.7.1
// @description  Добавляет кнопки под постерами фильмов на Kinorium для поиска на трекерах и других сайтах
// @author       CgPT & Vladimir0202
// @include      /^https?:\/\/.*kinorium.*\/.*$/
// @icon         https://ru.kinorium.com/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    console.log('Kinorium+ Search script started');

    const savedTrackers = GM_getValue('kinoriumTrackers', [
        { 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: 'HDRezka', urlTemplate: 'https://hdrezka.ag/search/?do=search&subaction=search&q={query}', icon: 'https://statichdrezka.ac/templates/hdrezka/images/favicon.ico' },
        { name: 'Kinopoisk', urlTemplate: 'https://www.kinopoisk.ru/index.php?kp_query={query}', icon: 'https://www.kinopoisk.ru/favicon.ico' },
    ]);

    function saveTrackers() {
        GM_setValue('kinoriumTrackers', savedTrackers);
    }

    function extractMovieData() {
        const titleElement = document.querySelector('.film-page__title-text.film-page__itemprop');
        const title = titleElement ? titleElement.textContent.trim() : '';

        const titleEngElement = document.querySelector('.film-page__orig_with_comment');
        const titleEng = titleEngElement ? titleEngElement.textContent.trim() : '';

        const yearElement = document.querySelector('.film-page__date a[href*="years_min="]');
        const year = yearElement ? yearElement.textContent.trim() : '';

        console.log(`Extracted movie data: Title: "${title}", Original Title: "${titleEng}", Year: "${year}"`);

        return { title, titleEng, year };
    }

    function addNewTrackerButton(container) {
        const addButton = document.createElement('button');
        addButton.textContent = '+';
        addButton.title = 'Добавить новый сайт для поиска';
        addButton.style.width = '19px';
        addButton.style.height = '19px';
        addButton.style.fontWeight = 'bold';
        addButton.style.fontSize = '15px';
        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('click', async () => {
            const name = prompt('Введите название сайта:');
            const urlTemplate = prompt('Введите URL шаблон (используйте {query} или {queryEng} для поиска):');

            if (name && urlTemplate) {
                const domainMatch = urlTemplate.match(/^(https?:\/\/[^/]+)/);
                let icon = domainMatch ? `${domainMatch[1]}/favicon.ico` : '';
                savedTrackers.push({ name, urlTemplate, icon });
                saveTrackers();
                alert('Сайт успешно добавлен. Перезагрузите страницу, чтобы увидеть изменения.');
            }
        });

        container.appendChild(addButton);
    }

    function addSearchButtons() {
        const { title, titleEng, year } = extractMovieData();
        if (!title) {
            console.warn('Title not found, skipping button creation');
            return;
        }

        const buttonContainer = document.createElement('div');
        buttonContainer.style.display = 'flex';
        buttonContainer.style.flexWrap = 'wrap';
        buttonContainer.style.gap = '5px';
        buttonContainer.style.marginTop = '10px';
        buttonContainer.style.marginBottom = '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 = '20px';
            button.style.height = '20px';
            button.style.borderRadius = '5px';
            button.style.backgroundImage = `url(${tracker.icon})`;
            button.style.backgroundSize = 'contain';
            button.style.backgroundRepeat = 'no-repeat';
            button.style.backgroundPosition = 'center';

            buttonContainer.appendChild(button);
        });

        addNewTrackerButton(buttonContainer);

        const targetElement = document.querySelector('.film-page__status-button.setStatusButtons');
        if (targetElement) {
            targetElement.after(buttonContainer);
            console.log('Search buttons added successfully');
        } else {
            console.warn('Target element for buttons not found');
        }
    }

    addSearchButtons();
})();