Torrent Game Copier

Adds unique, styled copy buttons to each torrent group on the right side with improved text formatting.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torrent Game Copier
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds unique, styled copy buttons to each torrent group on the right side with improved text formatting.
// @author       SleepingGiant
// @license      MIT
// @match        https://gazellegames.net/torrents.php*
// @exclude      https://gazellegames.net/torrents.php*id=*
// @exclude      https://gazellegames.net/torrents.php*action=basic*
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    // Function to create a styled button element
    function createStyledButton(text, formatFunction, torrentId, groupName, groupYear) {
        let button = document.createElement('button');
        button.textContent = text;
        button.style.display = 'block';
        button.style.padding = '5px 10px';
        button.style.backgroundColor = '#007BFF';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '4px';
        button.style.cursor = 'pointer';
        button.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
        button.style.marginBottom = '20px';

        // Ensure the text stays within the button box
        button.style.whiteSpace = 'nowrap';
        button.style.overflow = 'hidden';
        button.style.textOverflow = 'ellipsis';
        button.style.width = '100%';

        button.onclick = function() {
            let formattedText = formatFunction(torrentId, groupName, groupYear);
            GM_setClipboard(formattedText);
            button.textContent = 'Copied!';
        };

        button.onmouseover = function() {
            button.style.backgroundColor = '#0056b3';
        };
        button.onmouseout = function() {
            button.style.backgroundColor = '#007BFF';
        };

        return button;
    }

    // Function for ByGenre format
    function byGenreFormat(torrentId, groupName, groupYear) {
        return `[url=https://gazellegames.net/torrents.php?id=${torrentId}]${groupName} ${groupYear}[/url]`;
    }

    // Function for TitleChain/Name format
    function titleChainFormat(torrentId, groupName) {
        return `[url=https://gazellegames.net/torrents.php?id=${torrentId}]${groupName}[/url]`;
    }

    // Attach styled buttons to each #displayname element
    document.querySelectorAll('#displayname').forEach(el => {
        let groupName = el.querySelector('#groupname a').textContent.trim();
        let groupYear = el.querySelector('#groupyear') ? el.querySelector('#groupyear').textContent.trim() : '';
        let linkElement = el.querySelector('#groupname a');
        let torrentId = new URLSearchParams(linkElement.href.split('?')[1]).get('id');

        if (torrentId) {
            let buttonContainer = document.createElement('div');
            buttonContainer.style.display = 'flex';
            buttonContainer.style.flexDirection = 'column';

            let byGenreButton = createStyledButton('ByGenre', byGenreFormat, torrentId, groupName, groupYear);
            let titleChainButton = createStyledButton('TitleChain/Name', titleChainFormat, torrentId, groupName);
            buttonContainer.appendChild(byGenreButton);
            buttonContainer.appendChild(titleChainButton);

            el.parentNode.insertBefore(buttonContainer, el.nextSibling);
        }
    });
})();