Greasy Fork

Greasy Fork is available in English.

Steam Price Exchanger

Exchange price on steam

当前为 2020-09-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         Steam Price Exchanger
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Exchange price on steam
// @author       lzt
// @match        https://store.steampowered.com/*
// @grant        GM_xmlhttpRequest
// @connect      qq.ip138.com
// @run-at        document-end
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var rub = null
    var ars = null

    GM_xmlhttpRequest({
        method: "get",
        url: 'https://qq.ip138.com/hl.asp?from=RUB&to=CNY&q=1',
        responseType: 'document',
        onload: function(r) {
            rub = parseFloat(r.response.getElementsByTagName('tr')[2].childNodes[2].innerText);
            console.log(rub + " RUB/CNY");
            fillprice(rub, 'pуб');
        }
    });

    GM_xmlhttpRequest({
        method: "get",
        url: 'https://qq.ip138.com/hl.asp?from=ARS&to=CNY&q=1',
        responseType: 'document',
        onload: function(r) {
            ars = parseFloat(r.response.getElementsByTagName('tr')[2].childNodes[2].innerText);
            console.log(ars + " ARS/CNY");
            fillprice(ars, 'ARS');
        }
    });
    function fillprice(rate, unit){
        var lists = document.evaluate("//*[contains(text(), '" + unit + "')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null )
        for(let i = 0; i < lists.snapshotLength; i++) {
            var re = new RegExp(unit == "ARS"?"ARS\\$?\\s*[0-9.,]+":"[0-9.,]+\\s*pуб.?", "ig")
            var s = lists.snapshotItem(i).firstChild.nodeValue.match(re)
            if (s != null) {
                for(let j = 0; j < s.length; j++) {
                    var price = s[j].replace(".", "")
                    price = price.replace(",", ".")
                    price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/))*rate).toString()
                    lists.snapshotItem(i).firstChild.nodeValue = lists.snapshotItem(i).firstChild.nodeValue.replace(s[j], s[j] + "(" + price + ")")
                }
            }
        }
    }
})();