Greasy Fork

来自缓存

Greasy Fork is available in English.

c5 extension

买买买

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

// ==UserScript==
// @name         c5 extension
// @namespace
// @version      0.4
// @description  买买买
// @author       out
// @match        *://www.c5game.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @require      https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @connect      steamcommunity.com
// @namespace out
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    $(document).ready(function(){
        GM_addStyle(".price > div{margin:5px 0px;width:100px;font-size:14px;}"
                    +".price span{float:right;}"
                    +".price > div:nth-child(1) span{color:#e46409;}"
                    +".price > div:nth-child(2) span{color:#7ccc35;}"
                    +".price > div:nth-child(3) span{color:#1ee44a;}"
                   );
        if($(".right_steam").length!==0){

            var href = $(".right_steam a").attr("href");
            var match = href.match(/\/steamcommunity\.com\/market\/listings\/([0-9]+)\//);
            var hash_name = href.slice(match[1].length+44);
            var appid = match[1];
            GM_xmlhttpRequest({
                method: "GET",
                url: "http://steamcommunity.com/market/priceoverview/?currency=23&appid="+appid+"&market_hash_name="+hash_name,
                onload: addprice
            });
        }
        function addprice(res){
            if(res.responseText!=="null"){
                var d =  JSON.parse(res.responseText);
                if(d.success){
                    $("div.hero > span:first").hide();
                    $("div.hero > div.right_steam").css("float","none");
                    var steam_price = getFloat(d.lowest_price);
                    var $pinfo = $("<div class=\"price\"><div>最低:<span></span></div><div>税后:<span></span></div><div>比例:<span id=\"zq\"></span></div></div>");
                    $pinfo.find("span:eq(0)").text(steam_price.toFixed(2));
                    $pinfo.find("span:eq(1)").text((steam_price/1.15).toFixed(2));
                    if($(".sale-item-lists span.ft-orange").lenght!==0){
                        calcratio(steam_price);
                    }
                    $("div.hero").css("margin","5px 0px");
                    $("div.hero").parent().append($pinfo);
                }
                else{
                }
            }
        }
        function getFloat(str){
            if(str.indexOf(".")!=-1){
                var xs = str.length-str.indexOf(".")-1;
                var price = parseFloat(str.replace(/[^0-9]/ig,""));
                while(xs){
                    price/=10;
                    xs--;
                }
                return price;
            }
            return parseFloat(str.replace(/[^0-9]/ig,""));
        }
        function calcratio(p){
            var t = setInterval(function(){
                var c5_price = getFloat($(".sale-item-lists span.ft-orange:first").text());
                if(c5_price){
                    $("#zq").text((c5_price*1.15/p).toFixed(2));
                    clearInterval(t);
                   }
            },500);
        }
    });
})();