Steam - 添加搜索按鈕

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

当前为 2022-04-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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, "");
    }
})();