Steam - 添加搜索按鈕

在Steam商店頁面加上搜索按鈕

目前为 2022-04-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         Steam - 添加搜索按鈕
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  在Steam商店頁面加上搜索按鈕
// @author       CatTime
// @match        http*://store.steampowered.com/app/*
// @icon         https://store.steampowered.com/favicon.ico
// @grant        none
// @license      GNU GPLv3
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==

$(function () {
    var SiteSearchUrl = [//網站陣列請保持 名稱,搜索網址
        "IGG", "http://igg-games.com/?s=",
        "Online-Fix", "https://online-fix.me/index.php?do=search&subaction=search&story="
    ];
    var SSU = SiteSearchUrl;
    var btn = '';

    const appid = (window.location.pathname.match(/\/app\/(\d+)/) ?? [null, null])[1];
    if (appid === null) { return; }
    fetch(`https://store.steampowered.com/api/appdetails?appids=${appid}&l=english`)
        .then(async (response) => {
            if (response.ok) {
                const json = await response.json();
                const data = json[appid];
                if (data.success !== true) { return; }

                let { name: name_en, supported_languages, categories } = data.data;

                const t = setInterval(() => {
                    const ele_title = document.getElementById("appHubAppName");
                    if (ele_title != null) {
                        clearInterval(t);
                        name_en = pureName(name_en);

                        for (var i = 0; i < SSU.length; i += 2) {
                            btn = btn + '<a href="' + SSU[i + 1] + name_en + '" class="btn_green_steamui btn_medium" target="_blank"><span>' + SSU[i] + '</span></a>';
                        }
                        btn = '<div class="btn_addtocart">' + btn + '</div>';//加上外層div
                        $('.purchase_area_spacer').prepend(btn);//插入到目標的第一元素位置
                    }
                }, 500);


            } else {
                console.error(response.status);
            }
        })
        .catch((err) => {
            console.error(err);
        });



    function pureName(str) {
        return str.replace(/[《》™©®]/g, "");
    }
})();