Steam - 添加搜索按鈕

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

目前為 2023-04-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Steam - 添加搜索按鈕
// @namespace    http://tampermonkey.net/
// @version      0.6
// @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 () {

    // 1. 定義包含名稱和網址的陣列
    const websites = [
        { name: "igg-games", url: "http://igg-games.com/?s={1}" },
        { name: "online-fix", url: "https://online-fix.me/index.php?do=search&subaction=search&story={1}" },
        { name: "PSearchEngine", url: "https://cse.google.com/cse?cx=20c2a3e5f702049aa" }
    ];
    const appid = (window.location.pathname.match(/\/app\/(\d+)/) ?? [null, null])[1];
    if (appid === null) { return; }
    let appName;
    //2.使用fetch取回英文名稱
    fetch(`https://store.steampowered.com/api/appdetails?appids=${appid}&l=english`)
        .then(response => response.json())
        .then(data => {
            if (data[appid].success) {
                appName = data[appid].data.name;
                // 3.定義{0}{1}字串陣列
                const args = [appid, appName];
                // 4. 在網頁 div.purchase_area_spacer 後面插入多個按鈕
                const purchaseAreaSpacer = document.querySelector("div.purchase_area_spacer");
                const button = document.createElement("div");
                button.classList.add("btn_addtocart");
                for (let i = 0; i < websites.length; i++) {
                    const website = websites[i];
                    const link = document.createElement("a");
                    link.classList.add("btn_green_steamui", "btn_medium");
                    var url = website.url;
                    url = url.replace(/{(\d)}/g, (match, index) => args[index]);

                    link.setAttribute("href", url);
                    link.setAttribute("target", "_blank");
                    const span = document.createElement("span");
                    span.textContent = website.name;
                    link.appendChild(span);
                    button.appendChild(link);

                }
                purchaseAreaSpacer.insertAdjacentElement("afterend", button);
            }
        })
        .catch(error => console.error(error));

})();


QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址