Greasy Fork

Greasy Fork is available in English.

Steam、Epic历史价格查询

跳转到SteamDB、EpicGamesDB

当前为 2024-05-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam、Epic历史价格查询
// @description  跳转到SteamDB、EpicGamesDB
// @author       shopkeeperV
// @namespace    http://greasyfork.icu/zh-CN/users/150069
// @version      1.0.3
// @match        https://store.steampowered.com/*
// @match        https://store.epicgames.com/*
// @grant        window.onurlchange
// ==/UserScript==

(function () {
    'use strict';
    let host = location.host;
    let path = location.pathname;
    let db_url;
    if (/steampowered/.test(host)) {
        let page_type;
        let title_eles;
        if (/app/.test(path)) {
            page_type = "app";
            title_eles = document.getElementsByClassName("apphub_AppName");
            let wrappers = document.getElementsByClassName("game_area_purchase_game_wrapper");
            for (let wrapper of wrappers) {
                let item_type;
                let item_id;
                let form = wrapper.getElementsByTagName("form")[0];
                let inputs = form.getElementsByTagName("input");
                for (let input of inputs) {
                    if (/subid|bundleid/.test(input.name)) {
                        if (/subid/.test(input.name)) {
                            item_type = "sub";
                        } else if (/bundleid/.test(input.name)) {
                            item_type = "bundle";
                        }
                        item_id = input.value;
                        break;
                    }
                }
                db_url = "https://steamdb.info/" + item_type + "/" + item_id + "/#pricehistory";
                wrapper.getElementsByTagName("h1")[0].appendChild(createASpan(db_url));
            }
        } else {
            if (/sub/.test(path)) {
                page_type = "sub";
            } else if (/bundle/.test(path)) {
                page_type = "bundle";
            } else return;
            title_eles = document.getElementsByClassName("pageheader");
        }
        let page_id = path.match(/\/([0-9]*?)\//i)[1];
        for (let title_ele of title_eles) {
            db_url = "https://steamdb.info/" + page_type + "/" + page_id + "/#pricehistory";
            title_ele.appendChild(createASpan(db_url));
        }
    }
    if (/epicgames/.test(host)) {
        let timer;
        handler();
        window.addEventListener('urlchange', () => {
            console.log("Epic历史价格查询:监听到地址变化。");
            handler();
        });

        function handler() {
            if (/\/p\//.test(location.pathname)) {
                let ele;
                timer = setInterval(() => {
                    console.log("Epic历史价格查询:正在获取页面id...");
                    ele = document.getElementById("_schemaOrgMarkup-Product");
                    if (ele) {
                        clearInterval(timer);
                        console.log("Epic历史价格查询:已清除定时器。");
                        let content = ele.textContent;
                        let id = content.match(/"sku":"([^"]*):([^"]*)"/)[2];
                        db_url = "https://epicgamesdb.info/p/" + id + "/" + path.split("/").pop();
                        document.getElementsByTagName("h1")[0].appendChild(createASpan(db_url));
                    }
                }, 500);
            }
        }
    }

    function createASpan(url) {
        let span = document.createElement("span");
        span.setAttribute("class", "history_price");
        span.textContent = "查价";
        span.style.cssText = "display:inline-block;margin-left:10px;color:yellow;cursor:pointer;";
        span.onclick = (e) => {
            window.open(url);
        };
        return span;
    }
})();