Gazelle Games - Centered Add Torrent Link

Adds a horizontally centered "Add torrent" link in the Game Title row

当前为 2025-11-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Gazelle Games - Centered Add Torrent Link
// @namespace    https://github.com/yourusername/tampermonkey-scripts
// @version      1.0
// @description  Adds a horizontally centered "Add torrent" link in the Game Title row
// @author       You
// @match        https://gazellegames.net/torrents.php?id=*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function getGroupIdFromUrl() {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get('id');
    }

    function addTorrentLink() {
        const displayNameElement = document.getElementById('display_name');

        if (!displayNameElement) return;

        if (displayNameElement.querySelector('a[href*="upload.php?groupid="]')) return;

        const groupId = getGroupIdFromUrl();
        if (!groupId) return;

        const addTorrentLink = document.createElement('a');
        addTorrentLink.href = `upload.php?groupid=${groupId}`;
        addTorrentLink.textContent = '[Add torrent]';

        // **Only** positioning styles and site color variable
        addTorrentLink.style.position = 'absolute';
        addTorrentLink.style.left = '50%';
        addTorrentLink.style.transform = 'translateX(-50%)';
        addTorrentLink.style.fontSize = 'inherit';
        addTorrentLink.style.color = 'var(--lightBlue)';
        addTorrentLink.style.textDecoration = 'inherit';

        // Ensure h2 is a positioning container
        const currentPosition = window.getComputedStyle(displayNameElement).position;
        if (currentPosition === 'static') {
            displayNameElement.style.position = 'relative';
        }

        displayNameElement.appendChild(addTorrentLink);
    }

    function waitForElement() {
        if (document.getElementById('display_name')) {
            addTorrentLink();
        } else {
            setTimeout(waitForElement, 100);
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', waitForElement);
    } else {
        waitForElement();
    }
})();