Greasy Fork

Greasy Fork is available in English.

Steam Gems-to-Price Helper

处理垃圾库存的好帮手 ╰( ̄▽ ̄)╭

当前为 2016-12-16 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Steam Gems-to-Price Helper
// @namespace    http://nota.moe/
// @version      0.1-alpha
// @description  处理垃圾库存的好帮手 ╰( ̄▽ ̄)╭
// @author       NotaStudio
// @match        *://steamcommunity.com/*/inventory/*
// @grant        none
// @run-at       document-end
// @license      GPLv3
// ==/UserScript==

/* 
 * ChangeLog
 * 20161216 0.1-alpha
 * 初次发布
 */

(function($) {
	console.log('Steam Gems-to-Price Helper 0.1-alpha\nCreated by Nota\n2016.12.16');

	let gemsCount,
		gemsPrice,
		gemsValue,
		valueSpan,
		localAmountToken;

	let parseAmount = (amount) => Number.parseFloat(amount.slice(2)); // 去除货币符号和空格

	let getGemsPrice = () => {
		let apiUrl = `https://steamcommunity.com/market/priceoverview/?appid=753&country=${window.g_strCountryCode}&currency=${window.currencyId}&market_hash_name=753-Sack%20of%20Gems`;
		$.get(apiUrl,((data) => {
			localAmountToken = data.lowest_price.slice(0,1);
			gemsPrice = parseAmount(data.lowest_price);
		}));
	};

	let main = (xhr) => {
		gemsCount = Number.parseFloat(xhr.responseJSON.goo_value);
		getGemsPrice();
		gemsValue = (gemsPrice / 1000 * gemsCount).toFixed(2);

		valueSpan = $('span.item_scrap_value:visible')[0]; // span.item_scrap_value 会对应两个 SPAN 元素,其中可见者则为当前宝珠价值
		valueSpan.innerHTML += `<span style="color:#FF0">&nbsp;&nbsp;&nbsp;&nbsp;约为${localAmountToken} ${gemsValue}</span>`;
	};

	let eventHandler = (event, xhr, settings) => {
		if (settings.url.match(/ajaxgetgoovalueforitemtype/)) // Steam 会在点击某一库存物品时进行 3 次 jQuery AJAX 请求.筛选出请求宝珠数量的那一次
			setTimeout(main(xhr), 1000);
	};

	$(document).ajaxComplete(eventHandler);

})(jQuery);