Steam/GOG Game Torrent Search Modal

Shows a modal window with buttons for searching games on torrent sites with links to sources of information about games: Steam, GOG, trackers, wikis, etc.

// ==UserScript==
// @name         Steam/GOG Game Torrent Search Modal
// @namespace    GPT
// @version      1.0.6
// @author       Wizzergod
// @description  Shows a modal window with buttons for searching games on torrent sites with links to sources of information about games: Steam, GOG, trackers, wikis, etc.
// @description:ru  Показывает модальное окно с кнопками для поиска игр на торрент-сайтах со ссылками на источники информации об играх: Steam, GOG, трекеры, вики и прочее
// @match        *://store.steampowered.*/app/*
// @exclude      *://steamcommunity.*/*
// @match        *://www.gog.com/*/game/*
// @match        *://store.steampowered.*/*
// @match        *://*.steampowered.*/*
// @exclude      *://*.steampowered.com/bundle/*
// @match        *://steamcommunity.com/app/*
// @icon         https://bit.ly/3Jj2YMu
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @grant        GM_addStyle
// @grant        GM_openInTab
// @run-at       document-body
// @license      MIT

// ==/UserScript==

(function () {
    'use strict';

    // --- Styles ---
    GM_addStyle(`
        #gameLinksModal {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background-color: rgba(0,0,0,0.75);
            z-index: 9999;
            display: none;
            justify-content: center;
            align-items: center;
        }
        #gameLinksModalContent {
            background: #1b1d23;
            color: white;
            padding: 20px;
            border-radius: 12px;
            max-height: 90vh;
            overflow-y: auto;
            width: 700px;
            box-shadow: 0 0 20px #000;
            position: relative;
        }
        #gameLinksModalContent h2 {
            margin-top: 0;
            font-size: 1.5em;
        }
        .gameLinkSection {
            margin-top: 20px;
        }
        .gameLinkSection h3 {
            margin: 0 0 10px;
            border-bottom: 1px solid #444;
            padding-bottom: 5px;
            font-size: 1.2em;
        }
        .gameLinkBtn {
            display: inline-block;
            padding: 8px 14px;
            margin: 4px;
            border-radius: 6px;
            text-decoration: none;
            font-size: 13px;
            font-weight: bold;
            transition: background 0.3s;
        }
        .steamBtn { background: #5c7e10; color: white; }
        .steamBtn:hover { background: #4b670d; }

        .gogBtn { background: #0058a3; color: white; }
        .gogBtn:hover { background: #004080; }

        .torrentBtn { background: #6e35a3; color: white; }
        .torrentBtn:hover { background: #582980; }

        .otherBtn { background: #444; color: white; }
        .otherBtn:hover { background: #333; }

        #closeGameLinksModal {
            float: right;
            background: #ffffff12;
            border: none;
            color: white;
            font-size: 40px;
            cursor: pointer;
            margin-top: -25px;
            margin-right: -5px;
            border-radius: 0 0 6px 6px;
            padding: 1px 15px;
            transition: background 0.3s;
            box-shadow: 0 0 10px rgba(0,0,0,0.5);
        }
        #closeGameLinksModal:hover { background: #4b670d; }
        #openGameLinksBtn {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background: #008669;
            color: white;
            padding: 12px 16px;
            border-radius: 10px;
            font-size: 20px;
            border: none;
            cursor: pointer;
            z-index: 9999;
            box-shadow: 0 0 10px rgba(0,0,0,0.5);
        }
    `);

    // --- Modal ---
    const modal = document.createElement("div");
    modal.id = "gameLinksModal";
    modal.innerHTML = `
        <div id="gameLinksModalContent">
            <button id="closeGameLinksModal">&times;</button>
            <h2>🎮 Steam/GOG Game Torrent Search, and more</h2>
            <div id="gameLinksContainer"></div>
        </div>
    `;
    document.body.appendChild(modal);

    const openBtn = document.createElement("button");
    openBtn.id = "openGameLinksBtn";
    openBtn.textContent = "☰";
    document.body.appendChild(openBtn);

    const modalContent = modal.querySelector("#gameLinksModalContent");

    document.getElementById("closeGameLinksModal").onclick = () => {
        modal.style.display = "none";
    };

    // Close unwindow
    modal.addEventListener("click", (e) => {
        if (!modalContent.contains(e.target)) {
            modal.style.display = "none";
        }
    });

openBtn.onclick = () => {
    let title = "";

    // Steam name
    const steamName1 = document.querySelector('span[itemprop="name"]')?.innerText?.trim();
    const steamName2 = document.querySelector('#appHubAppName.apphub_AppName')?.innerText?.trim();

    // GOG name
    const gogTitle = document.querySelector('.productcard-basics__title')?.innerText?.trim();

    if (steamName1) {
        title = steamName1;
    } else if (steamName2) {
        title = steamName2;
    } else if (gogTitle) {
        title = gogTitle;
    } else {
        title = document.title.split('on Steam')[0].trim();
    }

    // Clean Game title
    title = cleanTitle(title);

    const html = buildLinks(title);
    document.getElementById("gameLinksContainer").innerHTML = html;
    modal.style.display = "flex";
};

// Clean Game title
function cleanTitle(rawTitle) {
    return rawTitle
        .replace(/[\u2122\u00AE\u00A9]/g, '')
        .replace(/[:@|™®©\[\]{}()"“”‘’«»\-–—_+=*~#^%$!?,.<>\\\/]/g, '')
        .replace(/\s{2,}/g, ' ')
        .trim();
}


    function getColorClass(groupName) {
        if (groupName.includes('Steam')) return 'steamBtn';
        if (groupName.includes('GOG')) return 'gogBtn';
        if (groupName.includes('Torrent')) return 'torrentBtn';
        return 'otherBtn';
    }

    function buildLinks(title) {
        const encTitle = encodeURIComponent(title);
        const gameappid = document.querySelector('[data-appid]')?.getAttribute('data-appid') ||
                          document.querySelector('[data-miniprofile-appid]')?.getAttribute('data-miniprofile-appid') || '';

        const sections = {
            '🔰 Steam': [
                { label: 'STEAMDB (SteamAppID)', url: `https://steamdb.info/app/${gameappid}` },
                { label: 'STEAMDB (GameTitle)', url: `https://steamdb.info/search/?a=all&q=${encTitle}` },
                { label: 'Card Exchange', url: `https://www.steamcardexchange.net/index.php?gamepage-appid-${gameappid}` },
            ],
            '💫 GOG': [
                { label: 'Gogdb', url: `https://www.gogdb.org/products?search=${encTitle}` },
                { label: 'Freegogpcgames', url: `https://freegogpcgames.com/?s=${encTitle}` },
                { label: 'Gog-games', url: `https://gog-games.to/?q=${encTitle}` },
                { label: 'Gogunlocked', url: `https://gogunlocked.com/?s=${encTitle}` }
            ],
            '✨ Torrents': [
                { label: '⭐Rutracker', url: `https://rutracker.org/forum/tracker.php?nm=${encTitle}` },
                { label: '⭐Nnmclub', url: `https://nnmclub.to/forum/tracker.php?nm=${encTitle}` },
                { label: '⭐Catorrent', url: `https://catorrent.org/index.php?do=search&subaction=search&story=${encTitle}` },
                { label: '⭐Gamestracker', url: `https://gamestracker.org/search/?q=${encTitle}` },
                { label: '⭐repack-games', url: `https://repack-games.ru/index.php?do=search&subaction=search&story=${encTitle}` },
                { label: '⭐Byrut', url: `https://thebyrut.org/?do=search&subaction=search&story=${encTitle}` },
                { label: '⭐Hisgames', url: `https://hisgames.org/search?searchphrase=all&searchword=${encTitle}` },
                { label: '⭐Igrovaya', url: `https://igrovaya.org/?do=search&subaction=search&story=${encTitle}&todo=igrovuha.org` },
                { label: '⭐Thelastgame.ru', url: `https://thelastgame.ru/?s=${encTitle}` },
                { label: '⭐Thelastgame.org', url: `https://thelastgame.org/?do=search&subaction=search&story=${encTitle}` },
                { label: 'Torrentdownloads.pro', url: `https://www.torrentdownloads.pro/search/?search=${encTitle}` },
                { label: 'Torrentdownload.info', url: `https://www.torrentdownload.info/search?q=${encTitle}` },
                { label: '1337x', url: `https://1337x.to/search/${encTitle}/1/` },
                { label: 'Thepiratebay', url: `https://thepiratebay.org/search.php?cat=401&q=${encTitle}` }
            ],
            '🧩 Another': [
                { label: 'PCGamingWiki (SteamAppID)', url: `https://www.pcgamingwiki.com/api/appid.php?appid=${gameappid}` },
                { label: 'PCGamingWiki (GameTitle)', url: `https://www.pcgamingwiki.com/w/index.php?search=${encTitle}` },
                { label: 'Small-games.info', url: `https://small-games.info/?go=search&search_text=${encTitle}` },
                { label: 'Old-games', url: `https://www.old-games.ru/catalog/?gamename=${encTitle}` },
                { label: 'Cs.rin', url: `https://cs.rin.ru/forum//search.php?st=0&sk=t&sd=d&sr=topics&terms=any&sf=titleonly&keywords=${encTitle}` },
                { label: 'F95zone - Adult 18+', url: `https://f95zone.to/search/search?keywords=${encTitle}` }
            ]
        };

        return Object.entries(sections).map(([group, links]) => {
            const colorClass = getColorClass(group);
            return `
                <div class="gameLinkSection">
                    <h3>${group}</h3>
                    ${links.map(src => `<a class="gameLinkBtn ${colorClass}" target="_blank" rel="noopener noreferrer" href="${src.url}">${src.label}</a>`).join('')}
                </div>
            `;
        }).join('');
    }
})();