// ==UserScript== // @name Steam Gems-to-Price Helper // @namespace http://nota.moe/ // @version 0.3 // @description 处理垃圾库存的好帮手 ╰( ̄▽ ̄)╭ // @author NotaStudio // @match *://steamcommunity.com/*/inventory/* // @grant none // @run-at document-end // @license GPLv3 // @downloadURL none // ==/UserScript== /* * ChangeLog * 20161217 0.3 * 临时修复国区价格显示为美元的 bug * 20161217 0.2 * 修复价格显示为"约为 undefined NaN" 的 bug * 20161216 0.1-alpha * 初次发布 */ (function($) { console.log('Steam Gems-to-Price Helper 0.3\nCreated by Nota\n2016.12.17'); let gemsCount, gemsPrice, gemsValue, valueSpan, localAmountToken; let parseAmount = (amount) => Number.parseFloat(amount.slice(2)); // 去除货币符号和空格 let getGemsPrice = (xhr) => { gemsCount = Number.parseFloat(xhr.responseJSON.goo_value); // 获取当前物品可分解的宝珠数量 let apiUrl = `https://steamcommunity.com/market/priceoverview/?appid=753&country=CN¤cy=23&market_hash_name=753-Sack%20of%20Gems`; $.get(apiUrl,((data) => { localAmountToken = data.lowest_price.slice(0,1); gemsPrice = parseAmount(data.lowest_price); // 获取当前"一袋宝珠"价格 gemsValue = (gemsPrice / 1000 * gemsCount).toFixed(2); valueSpan = $('span.item_scrap_value:visible')[0]; // span.item_scrap_value 会对应两个 SPAN 元素,其中可见者则为当前宝珠价值 valueSpan.innerHTML += `    约为${localAmountToken} ${gemsValue}`; })); }; let eventHandler = (event, xhr, settings) => { if (settings.url.match(/ajaxgetgoovalueforitemtype/)) // Steam 会在点击某一库存物品时进行 3 次 jQuery AJAX 请求.筛选出请求宝珠数量的那一次 setTimeout((() => (getGemsPrice(xhr))), 250); }; $(document).ajaxComplete(eventHandler); })(jQuery);