Greasy Fork

来自缓存

Greasy Fork is available in English.

Steam市场买卖价格小工具

try to take over the world!

当前为 2020-03-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         Steam市场买卖价格小工具
// @namespace    http://pronax.wtf/
// @version      0.3.8
// @description  try to take over the world!
// @author       Pronax
// @include      *://steamcommunity.com/market/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(
        ".price_tool_input{width:4.5rem;height:1rem}.price_tool_div{position:fixed;border-radius:5px;padding:.5rem;right:.6rem;top:35%;background-color:rgba(0,0,0,0.4)}.price_tool_input_div{margin:.2rem 0}"
    );
    GM_addStyle(
        ".market_listing_their_price>span.market_table_value,.market_listing_my_price>span.market_table_value,.market_listing_num_listings>span.market_table_value{font-size:100%}"
    );

    var demo_price_tool =
        "<div class='price_tool_div market_listing_filter_contents'><form onsubmit='return false' id='price_tool_form'><div class='price_tool_input_div'><label for='real_price'><b>现实价格</b></label><input type='radio' name='lock' alt='锁定此值' value='1' onchange='document.getElementById(\"lock_m2\").checked = document.getElementById(\"lock_m1\").checked' /><input type='number' step='0.01' min='0' class='price_tool_input filter_search_box' name='real_price' id='real_price' placeholder='现实价格' /></div><div class='price_tool_input_div'><label for='scale'><b>汇率比例</b></label><input type='radio' name='lock' alt='锁定此值' value='2' checked='checked' onchange='document.getElementById(\"lock_m2\").checked = document.getElementById(\"lock_m1\").checked' /><input type='number' step='0.01' min='0' max='1' class='price_tool_input filter_search_box' name='scale' id='scale' placeholder='汇率比例' /></div><div class='price_tool_input_div'><label for='money_receive'><b>收到的钱</b></label><input type='radio' name='lock' id='lock_m1' alt='锁定此值' value='3' onchange='document.getElementById(\"lock_m2\").checked = this.checked' /><input type='number' step='0.01' min='0' class='price_tool_input filter_search_box' name='money_receive' id='money_receive' placeholder='收到的钱' /></div><div class='price_tool_input_div'><label for='money_pays'><b>支付价格</b></label><input type='radio' name='lock_f' id='lock_m2' alt='锁定此值' value='3' onchange='document.getElementById(\"lock_m1\").checked = this.checked' /><input type='number' step='0.01' min='0' class='price_tool_input filter_search_box' name='money_pays' id='money_pays' placeholder='支付价格' /></div></form><span class='pagebtn' onclick='document.getElementById(\"searchResults_btn_prev\").click()'>&lt;</span><span class='pagebtn' onclick='document.getElementById(\"searchResults_btn_next\").click()' style='float: right;'>&gt;</span></div>"

    document.getElementById("BG_bottom").insertAdjacentHTML("beforeEnd", demo_price_tool);

    var real_price = document.getElementById("real_price");
    var scale = document.getElementById("scale");

    var saved_scale = GM_getValue("price_tool_scale");
    if(saved_scale!=null){
        scale.value = saved_scale;
    }

    var money_receive = document.getElementById("money_receive");
    var money_pays = document.getElementById("money_pays");
    var lock = document.getElementById("price_tool_form").lock;

    real_price.onchange = function() {
        if (lock.value == 2) {
            money_receive.value = Math.round(this.value / scale.value * 100) / 100;
            money_pays.value = Math.round(money_receive.value * 115) / 100;
        } else {
            scale.value = Math.round(this.value / money_receive.value * 100) / 100;
        }
    }

    scale.onchange = function() {
        GM_setValue("price_tool_scale",this.value);
        if (lock.value == 3) {
            real_price.value = Math.round(money_receive.value / 0.0115) / 100;
        } else {
            money_receive.value = Math.round(real_price.value / this.value * 100) / 100;
            money_pays.value = Math.round(money_receive.value * 115) / 100;
        }
    }

    money_receive.onchange = function() {
        money_pays.value = Math.round(this.value * 115) / 100;
        if (lock.value == 2) {
            real_price.value = Math.round(this.value * scale.value * 100) / 100;
        } else {
            scale.value = Math.round(real_price.value / this.value * 100) / 100;
        }

    }

    money_pays.onchange = function() {
        money_receive.value = (Math.round(this.value / 0.0115) + 1) / 100;
        if (lock.value == 2) {
            real_price.value = Math.round(money_receive.value * scale.value * 100) / 100;
        } else {
            scale.value = Math.round(real_price.value / this.value * 100) / 100;
        }
    }

    console.log("买卖价格插件加载成功--Pronax");

})();