处理垃圾库存的好帮手 ╰( ̄▽ ̄)╭
当前为
// ==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}¤cy=${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"> 约为${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);