IMDb Torrent Search button (TGx TorrentGalaxy)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();