GGn - Centered Add Torrent Link

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         GGn - Centered Add Torrent Link
// @version      1.0
// @description  Adds a horizontally centered "Add torrent" link in the Game Title row
// @author       stormlight
// @match        https://gazellegames.net/torrents.php?id=*
// @grant        none
// @run-at       document-end
// @namespace https://github.com/yourusername/tampermonkey-scripts
// ==/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();
    }
})();