Instant Torrent ID Opener

Instantly open TorrentBD torrents by numeric ID (plain number, TorrentID=*****) when pressing Enter.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Instant Torrent ID Opener
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Instantly open TorrentBD torrents by numeric ID (plain number, TorrentID=*****) when pressing Enter.
// @author       Sumbul⚡
// @match        https://www.torrentbd.net/*
// @match        https://www.torrentbd.org/*
// @match        https://www.torrentbd.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    window.addEventListener('load', () => {
        const searchBox = document.querySelector('input[name="kuddus_searchkey"]');

        if (!searchBox) {
            console.warn('TorrentBD ID Opener: Search box not found.');
            return;
        }
        function extractId(value) {
            if (/^\d+$/.test(value)) return value;
            const match = value.match(/(?:id|torrentid)=(\d+)/i);
            if (match) return match[1];

            return null;
        }
        function openTorrentById(id) {
            const url = `${location.origin}/torrents-details.php?id=${encodeURIComponent(id)}`;
            window.location.href = url;
        }
        searchBox.addEventListener('keydown', (e) => {
            if (e.key === 'Enter') {
                const value = searchBox.value.trim();
                const id = extractId(value);

                if (id) {
                    e.preventDefault();
                    openTorrentById(id);
                }
            }
        });
        searchBox.setAttribute('placeholder', 'Search Torrents or Enter ID / TorrentID');
    });
})();