Greasy Fork

Useful Links for Kinopoisk

Кнопка с ссылкой на HDRezka, Shikimori и Tragtorr для фильмов и аниме на Кинопоиске

目前为 2025-01-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         Useful Links for Kinopoisk
// @namespace    http://tampermonkey.net/
// @version      1.27
// @description  Кнопка с ссылкой на HDRezka, Shikimori и Tragtorr для фильмов и аниме на Кинопоиске
// @match        *://www.kinopoisk.ru/*
// @icon         https://www.kinopoisk.ru/favicon.ico
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function addHDRezkaButton() {
        const titleElement = document.querySelector('h1');
        const genresElement = document.querySelector('[data-test-id="encyclopedic-table"]');

        if (titleElement && genresElement && !document.querySelector('.hdrezka-button')) {
            const movieTitle = titleElement.innerText.trim();
            const genresText = genresElement.innerText.toLowerCase();
            const isAnime = genresText.includes('аниме');

            if (movieTitle) {
                const hdrezkaLink = `https://hdrezka.co/search/?do=search&subaction=search&q=${encodeURIComponent(movieTitle)}`;
                // Формируем правильную ссылку для поиска на Tragtorr
                const tragtorrLink = `http://tragtorr.in/search/${encodeURIComponent(movieTitle)}`;

                const buttonContainer = createButtonContainer();

                // Кнопка HDRezka с общей иконкой
                const hdrezkaButton = createButton('HDRezka', hdrezkaLink);
                buttonContainer.appendChild(hdrezkaButton);

                if (isAnime) {
                    // Удаляем информацию в скобках из названия
                    const cleanTitle = movieTitle.replace(/\s*\(.*?\)\s*/g, '').trim();
                    // Формируем правильную ссылку для поиска на Shikimori
                    const shikimoriLink = `https://shikimori.one/animes?search=${encodeURIComponent(cleanTitle)}`;
                    const shikimoriButton = createButton('Shikimori', shikimoriLink);
                    buttonContainer.appendChild(shikimoriButton);
                }

                // Кнопка Tragtorr
                const tragtorrButton = createButton('Tragtorr', tragtorrLink);
                buttonContainer.appendChild(tragtorrButton);

                titleElement.appendChild(buttonContainer);
            }
        }
    }

    function createButtonContainer() {
        const container = document.createElement('div');
        container.style.display = 'flex';
        container.style.marginTop = '10px';
        return container;
    }

    function createButton(text, link) {
        const buttonElement = document.createElement('button');

        buttonElement.innerHTML = `
            <span style="display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-right: 8px;">
                ${createCommonIcon()} <!-- Используем общую иконку -->
            </span>
            ${text}
        `;

        buttonElement.className = 'hdrezka-button';
        buttonElement.style.cssText = `
            height: 50px; color: black; background-color: #f2f2f2; border: none;
            border-radius: 25px; font-family: 'Roboto Condensed', sans-serif;
            font-size: 16px; font-weight: 600; cursor: pointer;
            display: flex; align-items: center; justify-content: center;
            padding: 0 25px; margin-right: 10px;
        `;

        buttonElement.onclick = () => window.open(link, '_blank');
        return buttonElement;
    }

    function createCommonIcon() {
        return `
           <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000000">
               <path d="M431.52-260.78H280q-90.98 0-155.1-64.11Q60.78-389 60.78-479.96q0-90.95 64.12-155.11 64.12-64.15 155.1-64.15h151.52v106H280.24q-47.27 0-80.36 33.02-33.1 33.03-33.1 80.2t33.1 80.2q33.09 33.02 80.36 33.02h151.28v106ZM307-435.48v-89.04h346v89.04H307Zm221.48 174.7v-106h151.28q47.27 0 80.36-33.02 33.1-33.03 33.1-80.2t-33.1-80.2q-33.09-33.02-80.36-33.02H528.48v-106H680q90.98 0 155.1 64.11 64.12 64.11 64.12 155.07 0 90.95-64.12 155.11-64.12 64.15-155.1 64.15H528.48Z"/>
           </svg>
        `;
    }

    const linkRoboto = document.createElement('link');
    linkRoboto.href = 'https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@600&display=swap';
    linkRoboto.rel = 'stylesheet';
    document.head.appendChild(linkRoboto);

    const observer = new MutationObserver(addHDRezkaButton);
    observer.observe(document.body, { childList: true, subtree: true });

    window.addEventListener('load', addHDRezkaButton);
})();