// ==UserScript== // @name CSGO Market Tool // @namespace https://coding.net/u/sffxzzp // @version 2.05 // @description A script that displays float value and stickers of guns in market list. // @author sffxzzp // @match *://steamcommunity.com/market/listings/730/* // @icon https://store.steampowered.com/favicon.ico // @grant GM_xmlhttpRequest // @connect metjm.net // @connect api.csgofloat.com // @downloadURL none // ==/UserScript== (function() { var util = (function () { function util() {} util.xhr = function (xhrData) { return new Promise(function(resolve, reject) { if (!xhrData.xhr) { GM_xmlhttpRequest({ method: xhrData.method || "get", url: xhrData.url, data: xhrData.data, responseType: xhrData.type || "", timeout: 3e4, onload: function onload(res) { return resolve({ response: res, body: res.response }); }, onerror: reject, ontimeout: reject }); } else { var xhr = new XMLHttpRequest(); xhr.open( xhrData.method || "get", xhrData.url, true ); if (xhrData.method === "POST") { xhr.setRequestHeader( "content-type", "application/x-www-form-urlencoded; charset=utf-8" ); } if (xhrData.cookie) xhr.withCredentials = true; xhr.responseType = xhrData.responseType || ""; xhr.timeout = 3e4; xhr.onload = function(ev) { var evt = ev.target; resolve({ response: evt, body: evt.response }); }; xhr.onerror = reject; xhr.ontimeout = reject; xhr.send(xhrData.data); } }); }; util.createElement = function (data) { var node; if (data.node) { node = document.createElement(data.node); if (data.content) { this.setElement({node: node, content: data.content}); } if (data.html) { node.innerHTML = data.html; } } return node; }; util.setElement = function (data) { if (data.node) { for (let name in data.content) { data.node.setAttribute(name, data.content[name]); } if (data.html!=undefined) { data.node.innerHTML = data.html; } } }; return util; })(); var csgomt = (function () { function csgomt() {} csgomt.prototype.parseResult = function (result) { console.log(result); let retResult = {"floatvalue": result.iteminfo.floatvalue.toFixed(14)}; let stickerConts = result.iteminfo.stickers; if (stickerConts.length > 0) { let stickerText = "印花:"; for (let i=0;i=0) { let dopplerText = "多普勒:"; let dopplerRe = /phase\d/gi; dopplerText += result.iteminfo.imageurl.match(dopplerRe)[0]; retResult.dopplerText = dopplerText; } console.log(retResult); return retResult; } csgomt.prototype.getFloatValue = function (node) { let _this = this; util.xhr({ url: "https://api.csgofloat.com/?url="+node.getAttribute("link") }).then(function (result) { result = JSON.parse(result.body); if (result.iteminfo) { node.parentNode.parentNode.onclick = function () {}; let finalResult = _this.parseResult(result); node.innerHTML = ""+finalResult.floatvalue+""; node.className="btn_green_white_innerfade btn_small"; let nameList = node.parentNode.parentNode.parentNode.getElementsByClassName('market_listing_item_name_block')[0]; if (finalResult.hasOwnProperty('stickerText')) { let stickerWear = util.createElement({node: "span", content: {class: "market_listing_game_name", style: "display: block; color: silver;"}, html: finalResult.stickerText}); nameList.appendChild(stickerWear); } if (finalResult.hasOwnProperty('dopplerText')) { let dopplerPhase = util.createElement({node: "span", content: {class: "market_listing_game_name", style: "display: block; color: silver;"}, html: finalResult.dopplerText}); nameList.appendChild(dopplerPhase); } localStorage.setItem(node.id, JSON.stringify(finalResult)); } else { node.innerHTML = "查询失败"; } }); }; csgomt.prototype.addButton = function () { let oriButtonDiv = document.getElementById('market_buyorder_info').children[0]; let oriButton = document.getElementById('market_commodity_buyrequests'); let newButton = util.createElement({node: "div", content: {style: "float: right; padding-right: 10px;"}, html: "清除本地缓存"}); newButton.onclick = function () { localStorage.clear(); alert("清理完毕!"); }; oriButtonDiv.insertBefore(newButton, oriButton); }; csgomt.prototype.addBanner = function () { let listBanner = document.getElementsByClassName('market_listing_table_header')[0]; let nameBanner = listBanner.children[2]; let childBanner = util.createElement({node: "span", content:{style: "padding-left: 4vw;"}}); nameBanner.appendChild(childBanner); childBanner = util.createElement({node: "a", content: {id: "getAllFloat", class: "btn_darkblue_white_innerfade btn_small"}, html: "查询所有物品磨损"}); childBanner.onclick = function() { var subButton = document.getElementsByClassName('floatvalue_button'); for (var i=0;i 3) {return false;} this.addBanner(); this.addStyle(); let itemDetails = g_rgAssets[730][2]; let itemListInfo = g_rgListingInfo; let itemInfo = {}; let reStickers = /(https+:\/\/.+?\.png)/gi; let reStickerDes = /
.{2,4}\: (.+?)<\/center>/; for (var listingid in itemListInfo) { itemInfo[itemListInfo[listingid].asset.id] = {}; } for (var assetid in itemDetails) { itemInfo[assetid].link = itemDetails[assetid].actions[0].link.replace("%assetid%", assetid); itemInfo[assetid].nametag = itemDetails[assetid].hasOwnProperty('fraudwarnings')?itemDetails[assetid].fraudwarnings[0]:''; let sticker = '
'; let stickerInfo = itemDetails[assetid].descriptions[itemDetails[assetid].descriptions.length-1].value; if (stickerInfo.length > 1) { let stickerImgs = stickerInfo.match(reStickers); let stickerDes = stickerInfo.match(reStickerDes)[1].split(', '); for (let i=0;i'; } } else { sticker += ''; } itemInfo[assetid].sticker = sticker + '
'; } let itemList = document.getElementsByClassName('market_recent_listing_row'); for (let i=0;i'+savedItem.floatvalue+''}); if (savedItem.hasOwnProperty('stickerText')) { let stickerWear = util.createElement({node: "span", content: {class: "market_listing_game_name", style: "display: block; color: silver;"}, html: savedItem.stickerText}); nameList.appendChild(stickerWear); } if (savedItem.hasOwnProperty('dopplerText')) { let dopplerPhase = util.createElement({node: "span", content: {class: "market_listing_game_name", style: "display: block; color: silver;"}, html: savedItem.dopplerText}); nameList.appendChild(dopplerPhase); } } else { floatButton = util.createElement({node: "span", content: {style: "width: 15%;", class: "market_listing_right_cell market_listing_action_buttons market_listing_wear"}, html: ''}); floatButton.onclick = function () { let clickedButton = this.children[0].children[0]; util.setElement({node: clickedButton, html: "磨损查询中…"}); _this.getFloatValue(clickedButton); }; } itemList[i].insertBefore(floatButton, nameList); } }; csgomt.prototype.run = function () { var _this = this; this.load(); this.addButton(); this.addPageCtl(); var csgoinv = document.getElementById("searchResultsRows"); var observer = new MutationObserver(function (recs) { for (let i=0;i