Letterboxd Torrent Search button

Adds torrent search buttons before the IMDb button on the Letterboxd page

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name             Letterboxd Torrent Search button
// @description      Adds torrent search buttons before the IMDb button on the Letterboxd page
// @author           mestrenandi
// @namespace        mestrenandi
// @contributionURL  https://www.paypal.com/donate/?hosted_button_id=PGCMER56TKFFG
// @version          1.0
// @grant            none
// @license          MIT
// @match            https://letterboxd.com/film/*
// ==/UserScript==

(function() {
    'use strict';

    function createButton(id, innerHTML, clickHandler, glowColor) {
        const button = document.createElement('a');
        button.id = id;
        button.className = 'micro-button track-event';
        button.innerHTML = innerHTML;
        button.style.marginRight = "3px";
        button.style.borderColor = "#303840";
        button.style.transition = "box-shadow 0.3s ease-in-out";

        button.addEventListener('mouseover', function() {
            button.style.borderColor = "#9ab";
            button.style.boxShadow = `0 0 10px ${glowColor}`;
        });

        button.addEventListener('mouseout', function() {
            button.style.borderColor = "#303840";
            button.style.boxShadow = "none";
        });

        button.addEventListener('click', clickHandler);

        const imdbButton = document.querySelector('a[data-track-action="IMDb"]');
        if (imdbButton) {
            imdbButton.parentNode.insertBefore(button, imdbButton);
        }
    }

    function getIMDbId() {
        const imdbLink = document.querySelector('a[data-track-action="IMDb"]');
        if (imdbLink) {
            const url = new URL(imdbLink.href);
            const pathname = url.pathname;
            const segments = pathname.split('/');
            for (let i = 0; i < segments.length; i++) {
                if (segments[i].startsWith('tt')) {
                    return segments[i];
                }
            }
        }
        return null;
    }

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

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

})();