// ==UserScript== // @name 网易BUFF价格比例(找挂刀)插件 // @namespace http://pronax.wtf/ // @version 2021-3-14 15:48:17 // @description 你的挂刀得力助手,有问题反馈可以直接发邮件给我(funkyturkey@yeah.net)在greasy上发issue也可以,不过可能响应比较慢 // @copyright 2020, Pronax // @author Pronax // @license MIT // @match https://buff.163.com/market/goods* // @match https://buff.163.com/market/?game=csgo* // @match https://buff.163.com/market/?game=dota2* // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function () { 'use strict'; // -------------------------------------------------------自定义参数--------start-------------------------------------- // 比例取值最小范围,小于等于这个值的比例会直接渲染成最小值渐变色 const min_range = 0.63; // 市场页面的渐变色 // 最大值渐变色,比例越接近最大值(默认是1)会越趋近这个颜色,格式:['r','g','b'] 或者 "r,g,b" var market_color_high = "80,39,255"; // 最小值渐变色,比例越接近最小值(默认是0.63)会越趋近这个颜色,格式:['r','g','b'] 或者 "r,g,b" var market_color_low = "255,30,30"; // 排序规则会记住上一次的选择,你只需要将对应的英文字母替换到等号后面分号前面就可以改成固定规则: // 按buff比例从低到高 按buff比例从高到低 按求购比例从低到高 按求购比例从高到低 // buff-sort.asc buff-sort.desc order-sort.asc order-sort.desc // 示例: var needSort = buff-sort.asc; var needSort = GM_getValue("sortRule"); // -------------------------------------------------------自定义参数--------end--------------------------------------- // 处理成数组 if (!Array.isArray(market_color_high)) market_color_high = market_color_high.split(","); if (!Array.isArray(market_color_low)) market_color_low = market_color_low.split(","); const steanOrderScaleTemp = ""; const steanOrderCountTemp = ""; function getUrlParam(name, url) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var result if (url) { result = url.substr(34).match(reg); //匹配目标参数 } else { result = window.location.search.substr(1).match(reg); //匹配目标参数 } if (result != null) return unescape(result[2]); return null; //返回参数值 } function sortGoods(sortRule, isAsc) { $("#j_list_card>ul>li").sort(function (a, b) { let av = $(a).attr(sortRule) - 0; let bv = $(b).attr(sortRule) - 0; if (av > bv) { return isAsc ? 1 : -1; } else if (av < bv) { return isAsc ? -1 : 1; } return 0; }).appendTo("#j_list_card>ul"); } // 保留2位小数 function roundToTwo(num, upOrDown) { // upOrDown为true时四舍五入 return upOrDown ? Math.round((num * 100) + 0.5) / 100 : Math.round((num * 100)) / 100; } function getWithoutFeePrice(originPrice, upOrDown) { return roundToTwo(originPrice / 1.15, upOrDown); } function getScale(originPrice, withFeePrice, upOrDown) { return roundToTwo(originPrice / (withFeePrice / 1.15), upOrDown); } function gradient(max, min, f) { if (typeof max === "string") { max *= 1; } if (typeof min === "string") { min *= 1; } if (f >= 1 || f <= min_range) { f = f >= 1 ? 1 : 0; } else { f = (f - min_range) / (1 - min_range); } return max >= min ? f * (max - min) + min : (1 - f) * (min - max) + max; } function paintingGradient(scale, target, position, targetTemplate) { var template; if (targetTemplate) { template = targetTemplate; } else { template = ''; } let red = gradient(market_color_high[0], market_color_low[0], scale); let green = gradient(market_color_high[1], market_color_low[1], scale); let blue = gradient(market_color_high[2], market_color_low[2], scale); switch (position) { case 1: $(target).before($(template).css("color", "rgb(" + red + "," + green + "," + blue + ")").text(scale)); break; case 2: $(target).prepend($(template).css("color", "rgb(" + red + "," + green + "," + blue + ")").text(scale)); break; case 3: $(target).append($(template).css("color", "rgb(" + red + "," + green + "," + blue + ")").text(scale)); break; case 4: $(target).after($(template).css("color", "rgb(" + red + "," + green + "," + blue + ")").text(scale)); break; default: $(target).append($(template).css("color", "rgb(" + red + "," + green + "," + blue + ")").text(scale)); } } function getItemId(steamLink, url) { return new Promise(function (resolve, reject) { let buff_item_id = getUrlParam("goods_id", url); let steam_item_id = GM_getValue(buff_item_id); if ((!steam_item_id) || steam_item_id.length > 20 || steam_item_id == buff_item_id) { GM_xmlhttpRequest({ url: steamLink, method: "get", onload: function (res) { if (res.status == 200) { let html = res.response; let start = html.indexOf("Market_LoadOrderSpread( ") + 24; let end = html.indexOf(" ); // initial load"); if (start == 24 || end == -1) { reject({ status: 404, statusText: "物品不在货架上" }); } steam_item_id = html.slice(start, end); GM_setValue(buff_item_id, steam_item_id); resolve(steam_item_id); } else { reject(res); } }, onerror: function (err) { reject(err); } }); } else { resolve(steam_item_id); } }); } function getSteamOrderList(steamLink, url) { return new Promise(function (resolve, reject) { getItemId(steamLink, url).then(function onFulfilled(itemId) { GM_xmlhttpRequest({ url: window.location.protocol + "//steamcommunity.com/market/itemordershistogram?country=CN&language=schinese¤cy=23&item_nameid=" + itemId + "&two_factor=0", method: "get", onload: function (res) { if (res.status == 200) { resolve(JSON.parse(res.response)); } else { console.log("访问steamorder列表出错:", res); reject(res); } }, onerror: function (err) { console.log("访问steamorder列表出错:", err); reject(err); } }); }).catch(function onRejected(err) { console.log('获取itemID错误:', err); reject(err); }); }); } function updateProgressBar(bar, progress, option) { let widthP = Math.round(bar.width() / document.body.clientWidth * 100); switch (option) { case "set": bar.width(progress + "%"); break; default: case "add": widthP += progress; bar.width(widthP + "%"); break; case "sub": widthP -= progress; bar.width(widthP < 0 ? 0 : widthP + "%"); break; } if (widthP >= 120) { bar.fadeOut(500); } } // 商品详情 window.buff_csgo_goods_scale_plugin_load = function (steam_price) { // 检测商品是否加载完成 if ($("#market-selling-list").length == 0) { setTimeout(buff_csgo_goods_scale_plugin_load, 100); return; } if ($("#market-selling-list").hasClass("calculated")) { return; } let price_list = $(".f_Strong"); let isLogined = price_list[0].getAttribute("id") == "navbar-cash-amount"; if (!steam_price) { steam_price = parseFloat($(price_list[isLogined ? 1 : 0]).text().split("(")[0].slice(1)); } let basic_price = getWithoutFeePrice(steam_price, true); for (let i = isLogined ? 2 : 1; i < price_list.length; i++) { let seller_price = price_list[i].innerText.slice(2); let scale = roundToTwo(seller_price / basic_price); if (i == (isLogined ? 2 : 1)) { $(".detail-summ>a").prop("href", $(".detail-summ>a").prop("href") + "?buffPrice=" + seller_price); $(".f_Strong .hide-usd")[0].innerText = basic_price; let color; switch (true) { case scale > 0.9: color = "#a0ffc5"; break; case scale > 0.8: color = "#b8ff8a"; break; case scale > 0.74: color = "#fff054"; break; case scale > 0.67: color = "#ff7e15"; break; default: color = "#ff0049"; break; } if ($(".good_scale").length == 0) { $(price_list[isLogined ? 1 : 0]).append($("" + scale + "")); let steamLink = document.getElementsByClassName("detail-summ")[0].lastElementChild.href; getSteamOrderList(steamLink).then(function onFulfilled(json) { $(".detail-cont").append("
下一页