// ==UserScript== // @name [buff/c5game/igxe]饰品比例筛选脚本 // @namespace http://tampermonkey.net/ // @icon https://store.steampowered.com/favicon.ico // @version 1.3 // @description 支持[buff/c5game/igxe]饰品比例筛选,支持多种筛选规则 // @author wsz987 // @match *://buff.163.com/market/* // @match *://buff.163.com/goods/* // @match *://www.c5game.com/* // @match *://www.igxe.cn/* // @match *://www.igxe.cn/product/* // @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js // @grant GM_getValue // @grant GM_setValue // @grant GM_openInTab // @grant GM_addStyle // @grant GM_listValues // @grant GM_deleteValue // @grant GM_notification // @grant GM_xmlhttpRequest // @supportURL https://keylol.com/t577669-1-1 // @downloadURL https://update.greasyfork.icu/scripts/399176/%5Bbuffc5gameigxe%5D%E9%A5%B0%E5%93%81%E6%AF%94%E4%BE%8B%E7%AD%9B%E9%80%89%E8%84%9A%E6%9C%AC.user.js // @updateURL https://update.greasyfork.icu/scripts/399176/%5Bbuffc5gameigxe%5D%E9%A5%B0%E5%93%81%E6%AF%94%E4%BE%8B%E7%AD%9B%E9%80%89%E8%84%9A%E6%9C%AC.meta.js // ==/UserScript== (function() { initWebConfig() const INIT={ RULES:[ { name:'全都要', key:'by_hbr_lsr', desc:'出售及求购都符合条件', func({ lsr, hbr },{ MIX_NUMBER, MAX_NUMBER }){ let sell_num = getVal(MIX_NUMBER), wbuy_num = getVal(MAX_NUMBER) if(lsr>1 || hbr>1) window.close() lsr>sell_num && window.close() hbr>wbuy_num && window.close() } }, { name:'仅出售', key:'by_lsr', desc:'仅依据出售比例 即低于理想比例', func({ lsr },{ MIX_NUMBER }){ lsr>1 && window.close() lsr>getVal(MIX_NUMBER) && window.close() } }, { name:'仅求购', key:'by_hbr', desc:'仅依据求购比例 即低于最高比例', func({ hbr },{ MAX_NUMBER }){ hbr>1 && window.close() hbr>getVal(MAX_NUMBER) && window.close() } } ], Header_DOM:{ KET_COMMAND:{ id:'KET_COMMAND', tips:'支持按键指令哦 A 上一页 D 下一页 W 居中 S 过滤 E 过滤后全部打开', name:'快捷指令提示', template(){ return `` } }, AUTH:{ id:'AUTH', tips:'作者: wsz987 此脚本于Keylol论坛免费发布且仅供学习参考 点击了解脚本 问题反馈 打赏 ', name:'auth', func(){ GM_openInTab("https://keylol.com/t577669-1-1") GM_notification( { text :'如果有用请帮忙加点体力(点这里)\r\n不介意打赏( ̄y▽, ̄)╭\r\n提交BUG请附上console输出', title :'饰品自动筛选脚本', highlight: true, timeout: 5000 }, function(){ GM_openInTab("https://keylol.com/t577669-1-1", { active: true }); } ) }, template(){ return `` } }, CONNECT_STATUS:{ id:'CONNECT_STATUS', tips:'社区连接状态检索', name:'社区访问', func(){ tryCatch(()=>{ let connectBtn = $('.connect-status-btn') connectBtn && GM_xmlhttpRequest({ url: "https://steamcommunity.com/market/", timeout: 15000, method: "get", onloadstart: function (event) { //readyState: 1 //status: 0 console.log("onloadstart", event); event.readyState==1 && connectBtn.html('响应中…') }, onload: function (res) { //status: 200 //statusText: "OK" //readyState: 4 console.log("onload", res); res && res.status == 200 && res.readyState && connectBtn.text('访问正常') }, onerror: function (err) { //readyState: 4 //status: 0 connectBtn.text('网络错误') console.log("检测steam连接性出错:连接错误", err); }, ontimeout: function (res) { connectBtn.text('请求超时') console.log("检测steam连接性出错:请求超时",res); } }) }) }, template(){ return `` } } }, DOM:{ RULES_TYPE:{ name:'筛选规则', tips:'筛选规则选择', defaultVal:1, key:'RULES_TYPE', foreignKey:'RULES', template(){ return ` ` } }, ON_SALE_COUNT:{ name:'在售数量', tips:'较大的基数便于快速出手 避免误差', defaultVal:300, key:'ON_SALE_COUNT', template(){ return `` } }, MIX_NUMBER:{ name:'出售比例', tips:'实质上是避免 出售-收购 比例差距过大 避免JS抬价而造成损失', defaultVal:0.7, key:'MIX_NUMBER', template(){ return `` } }, MAX_NUMBER:{ name:'求购比例', tips:'最终筛选不超过比例', defaultVal:0.75, key:'MAX_NUMBER', template(){ return `` } } }, Footer_DOM:{ PREV_PAGE:{ id:'PREV_PAGE', func(){ tryCatch(()=>$(webConfig.preBtn)[0].click()) }, template(){ return `` } }, RESET_BUTTON:{ id:'RESET_BUTTON', func(){ GM_listValues().map( name => GM_deleteValue(name) ) $('.card-body').children().remove() $('.card-body').html(INIT.render('DOM')) alert('重置成功') }, template(){ return `` } }, SYNC_DATA:{ id:'SYNC_DATA', tips:'同步最新数据 避免页面众多导致混乱', func(){ tryCatch(()=>{ $('.card-body').children().remove() $('.card-body').html(INIT.render('DOM')) }) }, template(){ return `` } }, NEXT_PAGE:{ id:'NEXT_PAGE', func(){ tryCatch(()=>$(webConfig.nextBtn)[0].click()) }, template(){ return `` } }, }, render(TYPE){ let Template='' Object.values(this[TYPE]).map(item=>{ if(TYPE==='DOM') Template+=item.template.call({...item,defaultVal: getVal(item),foreignKey :this[item.foreignKey] }) else { Template+=item.template() item.func && $(document).on('click', `#${item.id}`, ()=> { item.func() }); } }) return Template } } // 数据绑定 $(document).on('input', '#tool-card > .card-body input,#tool-card > .card-body select', ({target:{dataset:{ key },value}})=> { if(!value.toString()) return alert(`数据错误: "${key}" -- ${value}`) setVal(key,value) let actionDOM=document.querySelector(`.card-body span#${key}`) actionDOM && tryCatch(()=>actionDOM.innerText=getVal({key})) }); // DOM 挂载 $("body").append(`
${INIT.render('Header_DOM')}
${INIT.render('DOM')}
`) onkeydownListener(INIT) ondetailMountdedListener( data => execRules(INIT,data)) dargCard() })(); function dargCard(){ tryCatch(()=>{ $("#tool-card").mousedown(function() { $("#tool-card").on({ // 要移动拖拽的目标DOM mousedown: function(e){ var el = $(this); var os = el.offset(); var dx = e.pageX - os.left var dy = e.pageY - os.top; $(document).on('mousemove.drag', function(e){ el.offset({ top: e.pageY-dy, left: e.pageX-dx }); }); }, mouseup: function(e){ $(document).off('mousemove.drag'); }}) }) }) } function ondetailMountdedListener(callBack){ let detail = {} $(document).on("DOMNodeInserted",".detail-summ,.afkout .price", (e)=>{ let { innerText: value, className} = e.target //value.includes('Steam302') && alert(value) detail[className]= value - '' detail && detail.lsr && detail.hbr && callBack && callBack(detail) }) } function execRules({ DOM, RULES },data){ RULES[getVal(DOM.RULES_TYPE)].func(data,DOM) } function onkeydownListener({Footer_DOM:Event,DOM}){ tryCatch(()=>{ document.onkeydown=function(event){ var e = event || window.event || arguments.callee.caller.arguments[0]; // S if(e && e.keyCode==83){ middle() filter(DOM,Event) } // D if(e && e.keyCode==68){ Event.NEXT_PAGE.func() } // A if(e && e.keyCode==65){ Event.PREV_PAGE.func() } // W if(e && e.keyCode==87){ middle(); } // E if(e && e.keyCode==69){ filter(DOM,Event) openALLInTab() } } }) } function middle(){ tryCatch(()=>{ const { goodsContainer } =webConfig const Rules =['buff.163.com/market/','igxe.cn/market/','c5game.com/'] if(Rules.some(rule=>location.href.includes(rule))){ //if(!location.href.includes('buff.163.com/market/')||!location.href.includes('product')||!location.href.includes('www.c5game.com/dota/')){ if($(goodsContainer).width()>$(window).height()){ $(this).scrollTop($(goodsContainer).offset().top) }else{ $(this).scrollTop($(goodsContainer).offset().top+($(window).height()-$(goodsContainer).width())/2); } } }) } function initWebConfig(){ let config={} switch(location.host){ case "buff.163.com": config={ goodsContainer:'.market-card', onSaleCount:'.f_Bold.c_Gray', goodsItemHref:"ul[class^='card_']>li:not(.script_no)>a", goodsCount:20, preBtn:'.page-link.prev', nextBtn:'.page-link.next', currentGoodsNode:(el)=>el.parentNode.parentNode } break; case "www.igxe.cn": config={ goodsContainer:'.list', onSaleCount:'.info .stock', goodsItemHref:'.list a.item:not(.script_no)', goodsCount:20, preBtn:'.btn-prev', nextBtn:'.btn-next', currentGoodsNode:(el)=>el.parentNode.parentNode } break; case "www.c5game.com": config={ goodsContainer:'#market_index .list', onSaleCount:'.count', goodsItemHref:'.list .el-col:not(.script_no) a.mb20', goodsCount:42, preBtn:'.btn-prev', nextBtn:'.btn-next', currentGoodsNode:(el)=>el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode } c5game_goodsDetailPageFix() c5game_listenListDataLoad() break; } if(JSON.stringify(config) == "{}") console.error('script config init error') else window.webConfig = config } function openALLInTab(){ for(let i of $(webConfig.goodsItemHref)){ i?.href && GM_openInTab(i?.href) } } function filter({ON_SALE_COUNT},Event){ let { onSaleCount, goodsCount,currentGoodsNode }=webConfig let n=0 Array.from($(onSaleCount)).filter(x=>{ if(eval(x.innerHTML.replace(/[^0-9]/g, ''))>=parseInt(getVal(ON_SALE_COUNT))) return ++n; currentGoodsNode(x).className += ' script_no' }) if(n==goodsCount){ Event.NEXT_PAGE.func() } } function c5game_listenListDataLoad(){ tryCatch(()=>{ const mutation = new MutationObserver(function(mutationRecoards, observer) { if(mutationRecoards[0]?.oldValue=="list el-loading-parent--relative"){ console.log('c5game list data loaded'); $('.script_no').removeClass('script_no') } }) mutation.observe(document.querySelector("#market_index > ul.list"), { attributes: true, characterDataOldValue :true, attributeFilter: ['class'], attributeOldValue: true }); }) } function c5game_goodsDetailPageFix(){ tryCatch(()=>{ let href = document.querySelector("div.bottom-info > a")?.attributes?.href?.value $("body").append(``) $("body").append("
") $("body").append(``) $(document).on("DOMNodeInserted",".onsale-table", (e)=>{ let firstPrice = $('.onsale-table-item .text-price:first').text() $('tbody.scriptFix .ft-orange:first span').text(firstPrice) }) }) } function setVal(key,val){ console.log('setVal',key,val) GM_setValue(key,val) } function getVal({key,defaultVal}){ return GM_getValue(key,defaultVal) - '' } function tryCatch(callBack){ try{ callBack && callBack() }catch(e){ console.log(e) } } GM_addStyle(` #tool-card{ z-index:998; position:fixed; left:10px; top:400px; background-color: #0f0e17; color:#a7a9be; display: flex; flex-direction: column; padding: 0.75rem 1rem 0.4rem; font-size: 1rem; font-weight: 600; border-radius: 7px; border: 2px solid #ff8906; min-width:160px; } .card-header label{ margin-bottom: 0.2rem; } .card-body{ display: flex; flex-direction: column; } .card-footer{ display: flex; justify-content: space-around; margin-top: 0.3rem; } #tool-card button{ background-color: #ff8906; color:#fffffe; padding: 0.3rem 0.5rem; border:none; border-radius: 3px; font-size: 1rem; font-weight: 600; cursor: pointer; } #tool-card input, #tool-card button{ margin-bottom: 0.2rem; } #tool-card button:active{ position: relative; top: 1px; } .card-body input{ color: #fffffe; background-color: transparent; border: none; font-weight: 600; font-size: 1rem; border-bottom: 0.1rem solid #ff8906; text-align: center; min-width:59px; } .card-body label{ display: flex; align-items: center; justify-content: space-around; } .card-body select{ color: #fffffe; background-color: transparent; border: none; font-weight: 600; font-size: 1rem; border-bottom: 0.1rem solid #ff8906; text-align-last:center; } .card-body option{ background-color: #0f0e17; color: #a7a9be; text-align:center; } .connect-status{ display: flex; align-items: center; justify-content: space-around; margin-top: 0.2rem; } .connect-status-btn{ margin-bottom: 0 !important; color:#0f0e17 !important; } .syncData-btn{ margin-bottom: 0.2rem !important; } .syncData-btn button{ height: 100%; display: flex; align-items: center; } #AUTH{ color: #0f0e17 !important; } .script_no{ display:none !important; } .hero-fix{ position: absolute; top: 25%; right: 30%; color:white; font-weight: bold; z-index:999; } `)