Greasy Fork

Greasy Fork is available in English.

Steam市场买卖价格小工具

try to take over the world!

目前为 2020-02-28 提交的版本。查看 最新版本

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

(function() {
    'use strict';

GM_addStyle(
		".price_tool_input{width:6rem;height:1rem;margin:.2rem .2rem 0 0}.price_tool_div{position:fixed;border-radius:5px;padding:.2rem;padding-left:.5rem;right:.6rem;top:35%;background-color:rgba(0,0,0,0.2)}"
	);
	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%}"
	);
	GM_addStyle(".market_listing_price_without_fee{display:none;position:relative;top:-1.05rem;color:#7caf38}");
	var demo_price_tool =
		"<div class=\"price_tool_div market_listing_filter_contents\"><div><label for=\"real_price\"><b>现实价格</b></label><input type=\"number\" step=\"0.01\" min=\"0\" class=\"price_tool_input filter_search_box\"	 name=\"real_price\" id=\"real_price\" placeholder=\"现实价格\" /></div><div><label for=\"scale\"><b>汇率比例</b></label><input type=\"number\" step=\"0.01\" min=\"0\" max=\"1\" class=\"price_tool_input filter_search_box\"	 name=\"scale\" id=\"scale\" placeholder=\"汇率比例\" /></div><div><label for=\"money_receive\"><b>收到的钱</b></label><input type=\"number\" step=\"0.01\" min=\"0\" class=\"price_tool_input filter_search_box\"	 name=\"money_receive\" id=\"money_receive\" placeholder=\"收到的钱\" /></div><div><label for=\"money_pays\"><b>支付价格</b></label><input type=\"number\" step=\"0.01\" min=\"0\" class=\"price_tool_input filter_search_box\"	 name=\"money_pays\" id=\"money_pays\" placeholder=\"支付价格\" style=\"margin-bottom: 0.2rem;\" /></div></div>"
	document.getElementById("BG_bottom").insertAdjacentHTML("beforeEnd", demo_price_tool);
	
	
	var real_price = document.getElementById("real_price");
	var scale = document.getElementById("scale");
	var money_receive = document.getElementById("money_receive");
	var money_pays = document.getElementById("money_pays");
	
	var saved_scale = GM_getValue("price_tool_scale");
	if(saved_scale!=null){
		scale.value = saved_scale;
	}else{
		scale.value = 0.65;
		GM_setValue("price_tool_scale",0.65);
	}
	
	real_price.onchange = function(){
		money_receive.value = Math.round(this.value/scale.value*100)/100;
		money_pays.value = Math.round(money_receive.value*115)/100;
	}
	
	scale.onchange = function(){
		GM_setValue("price_tool_scale",this.value);
		if(real_price.value!=null){
			money_receive.value = Math.round(real_price.value/this.value*100)/100;
			money_pays.value = Math.round(money_receive.value*115)/100;
		}else{
			real_price.value = Math.round(money_receive.value*scale.value*100)/100;
		}
	}
	
	money_receive.onchange = function(){
		money_pays.value = Math.round(this.value*115)/100;
		real_price.value = Math.round(this.value*scale.value*100)/100;
	}
	
	money_pays.onchange = function(){
		money_receive.value = (Math.round(this.value/0.0115)+1)/100;
		real_price.value = Math.round(money_receive.value*scale.value*100)/100;
	}
	
	setTimeout(function() {
		var value_list = document.getElementsByClassName("market_table_value");
		for (var i = 0; i < value_list.length; i++) {
			var cell = value_list[i];
			var with_fee = cell.children[0];
			var without_fee = cell.children[2];
			cell.onmouseenter = function() {
				without_fee.style.display = "block"
				with_fee.style.cssText = "position: relative;top: 1.05rem;";
			};
			cell.onmouseleave = function() {
				without_fee.style.display = "none"
				with_fee.style.cssText = "";
			}
		}
		console.log("买卖价格插件加载成功--Pronax");
	}, 1000);
	console.log("买卖价格插件进行加载");

})();