Greasy Fork

Greasy Fork is available in English.

c5 extension

tiao zhan G fat

当前为 2017-11-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         c5 extension
// @namespace    out
// @version      0.1
// @description  tiao zhan G fat
// @author       out
// @match        *://www.c5game.com/*
// @grant        GM_xmlhttpRequest
// @require     https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @connect     steamcommunity.com
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    $(document).ready(function(){
        if($(".right_steam").length!==0){
            var hash_name = $(".right_steam a").attr("href").slice(47);
            GM_xmlhttpRequest({
                method: "GET",
                url: "http://steamcommunity.com/market/priceoverview/?currency=23&appid=730&market_hash_name="+hash_name,
                onload: addprice
            });
        }
        function addprice(res){
            if(res.responseText!=="null"){
                var d =  JSON.parse(res.responseText);
                console.log(res.responseText);
                if(d.success){
                    var steam_price = getFloat(d.lowest_price);
                    var text = "Steam参考价:"+d.lowest_price+" 税后:"+(steam_price/1.15).toFixed(2);
                    if($(".sale-item-lists span.ft-orange").lenght!==0){
                        var c5_price=getFloat($(".sale-item-lists span.ft-orange:first").text());
                        text += "("+(c5_price*1.15/steam_price).toFixed(1)+"折)";
                    }
                    $(".right_steam a").text(text);
                }
            }
        }
        function getFloat(str){
            var xs = str.length-str.indexOf(".");
            console.log(xs);
            console.log(str);
            return parseFloat(str.replace(/[^0-9]/ig,""));
        }
    });
})();