Raw Source
mestrenandi / IMDb Torrent Search button (TGx & EXT.TO)

// ==UserScript==
// @name             IMDb Torrent Search button (TGx & EXT.TO)
// @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          0.1
// @grant            none
// @license          MIT
// @downloadURL https://update.greasyfork.org/scripts/501803/IMDb%20Torrent%20Search%20button%20%28TGx%20%20EXTTO%29.user.js
// @updateURL https://update.greasyfork.org/scripts/501803/IMDb%20Torrent%20Search%20button%20%28TGx%20%20EXTTO%29.meta.js
// ==/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.position = "fixed";
        button.style.left = id === 'TGxSearchButton' ? "1.89%" : "15%"; // Adjusted position for the second button
        button.style.top = "12%"; // Same vertical position for both buttons
        button.style.zIndex = '9999';
        button.style.backgroundColor = "rgba(100, 100, 100, 0.8)"; // Background color with transparency
        button.style.color = "#fff"; // Text color
        button.style.border = "2px solid rgba(150, 150, 150, 0.6)"; // Border with transparency
        button.style.borderRadius = "5px"; // Rounded corners
        button.style.padding = "10px 20px"; // Padding
        button.style.fontSize = "14px"; // 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.9)";
            button.style.borderColor = "rgba(200, 200, 200, 0.8)";
        });

        button.addEventListener('mouseout', function() {
            button.style.backgroundColor = "rgba(100, 100, 100, 0.8)";
            button.style.borderColor = "rgba(150, 150, 150, 0.6)";
        });

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

        // Append the button to the body
        document.body.appendChild(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;
    }

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

    // Create ext.to search button
    createButton('ExtSearchButton', 'EXT Search', function() {
        const movieTitle = document.querySelector('h1').innerText;
        const query = movieTitle.split(' ').join('+');
        const searchURL = `https://ext.to/search/?order=size&sort=desc&q=${query}`;
        window.open(searchURL, '_blank');
    });

})();