IMDb Torrent Search button (TGx TorrentGalaxy)

Adds a torrent search button in the top left corner of the IMDb page

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name             IMDb Torrent Search button (TGx TorrentGalaxy)
// @description      Adds a torrent search button in the top left corner of the IMDb page
// @namespace        mestrenandi
// @author           mestrenandi
// @contributionURL  https://www.paypal.com/donate/?hosted_button_id=PGCMER56TKFFG
// @match            https://www.imdb.com/*
// @version          2.1.1
// @grant            none
// @license          MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create a button with the specified properties
    function createButton(id, innerHTML, clickHandler) {
        const button = document.createElement('button');
        button.id = id;
        button.innerHTML = innerHTML;
        button.style.display = "inline-block";
        button.style.marginRight = "0.5rem"; // Space between buttons
        button.style.backgroundColor = "rgba(100, 100, 100, 0.0)"; // Background color with transparency
        button.style.color = "#fff"; // Text color
        button.style.border = "0.5px solid rgba(150, 150, 150, 0.6)"; // Border with transparency
        button.style.borderRadius = "1rem"; // Rounded corners
        button.style.padding = ".18rem .75rem"; // Padding
        button.style.fontSize = ".875rem"; // Font size
        button.style.fontFamily = "Arial, sans-serif"; // Font family
        button.style.cursor = "pointer"; // Pointer cursor on hover
        button.style.transition = "background-color 0.3s, border-color 0.3s"; // Smooth transition

        // Add hover effects
        button.addEventListener('mouseover', function() {
            button.style.backgroundColor = "rgba(150, 150, 150, 0.32)";
        });

        button.addEventListener('mouseout', function() {
            button.style.backgroundColor = "rgba(100, 100, 100, 0.0)";
        });

        // Add click event handler
        button.addEventListener('click', clickHandler);

        return button;
    }

    // Get movie ID for TGx search
    function getMovieId() {
        let movieId;
        let x = window.location.pathname;
        let arr = x.split('/');

        for (let i = 0; i < arr.length; i++) {
            if (arr[i].substring(0, 2) === 'tt' || arr[i].substring(0, 2) === 'TT') {
                movieId = arr[i];
            }
        }
        return movieId;
    }

    // Wait for the title element to be available
    function waitForTitleAndAddButtons() {
        const titleElement = document.querySelector('.hoBFcD');

        if (titleElement) {
            const buttonContainer = document.createElement('div');

            // Create TGx search button
            const movieId = getMovieId();
            if (movieId) {
                const tgxButton = createButton('TGxSearchButton', 'TGx Search', function() {
                    const searchURL = `https://torrentgalaxy.to/torrents.php?search=${movieId}&sort=size&order=desc`;
                    window.open(searchURL, '_blank');
                });
                buttonContainer.appendChild(tgxButton);
            }

            // Insert the button container above the title element
            titleElement.parentNode.insertBefore(buttonContainer, titleElement);
        } else {
            // Retry after a short delay if the title element is not yet available
            setTimeout(waitForTitleAndAddButtons, 100);
        }
    }

    waitForTitleAndAddButtons();
})();