Kinopoisk Redirect

Show a button on the page to redirect from kinopoisk.ru to C_X

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kinopoisk Redirect
// @namespace    https://t.me/johannmosin
// @version      1.1
// @description  Show a button on the page to redirect from kinopoisk.ru to C_X
// @author       Johann Mosin
// @match        https://www.kinopoisk.ru/*/*
// @license      MIT
// @grant        GM_addStyle
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Function to create and append the button
    function createAndAppendButton(containerClass, providedButtonClass) {
        // Check if the button already exists
        if (document.querySelector('button.redirect-button')) {
            return;
        }

        // Create a button element
        var button = document.createElement('button');
        button.textContent = 'Смотреть на C_X';
        button.className = 'redirect-button'; // Add a class to the button

        // Copy the classes from the provided button
        var providedButton = document.querySelector(providedButtonClass);
        var classes = providedButton.className.split(' ');

        // Apply the copied classes to the new button
        classes.forEach(function(className) {
            button.classList.add(className);
        });

        // Attach an event listener to the button
        button.addEventListener('click', function() {
            // Get the current URL
            var currentUrl = window.location.href;

            // Extract the type and id from the URL
            var parts = currentUrl.split('/');
            var type = parts[3];
            var id = parts[4];

            // Construct the new URL
            var newUrl = 'https://w2.kpfr.wiki/' + type + '/' + id + '/';

            // Redirect to the new URL
            window.location.href = newUrl;
        });

        // Append the button to the container
        document.querySelector(containerClass).appendChild(button);
    }

    // Check which container class the page contains and create the button accordingly
    function checkForButtons() {
        if (document.querySelector('div.styles_buttonsContainer__HREZO')) {
            createAndAppendButton('div.styles_buttonsContainer__HREZO', '.styles_button__tQYKG .style_root__BmiQ7 button');
        } else if (document.querySelector('div.styles_buttonsContainer__i6y3F')) {
            createAndAppendButton('div.styles_buttonsContainer__i6y3F', '.styles_button__Q82i0 .watch-online-button .kinopoisk-watch-online-button');
        }
    }

    // Use MutationObserver to check for changes in the DOM
    var observer = new MutationObserver(checkForButtons);
    observer.observe(document.body, { childList: true, subtree: true });

    // Run the checkForButtons function initially
    checkForButtons();
})();