Greasy Fork

Greasy Fork is available in English.

buff_dota懒人找饰品

buff doat饰品的过滤查找

目前为 2020-04-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         buff_dota懒人找饰品
// @namespace    http://tampermonkey.net/
// @icon      	 https://store.steampowered.com/favicon.ico
// @version      0.1
// @description  buff doat饰品的过滤查找
// @author       wsz987
// @match        *://buff.163.com/market/*
// @match        *://buff.163.com/market/goods?goods_id=*
// @require      https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @supportURL   https://keylol.com/t563920-1-1
// ==/UserScript==


/*A 上一页
S 居中且过滤
D 下一页
W 居中
E 过滤后全部打开*/

(function() {
    'use strict';
    window.onload=function(){
        middle();
        filter().then(btn());
        try{
            document.onkeydown=function(event){
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if(e && e.keyCode==83){
                    middle();
                    filter();
                }
                if(e && e.keyCode==68){
                    nextpage();
                }
                if(e && e.keyCode==65){
                    prevpage();
                }
                if(e && e.keyCode==87){
                    middle();
                }
                if(e && e.keyCode==69){
                    filter().then(allopen());
                }
            }
        }catch(e){console(e)}
    }
    if(window.location.href.indexOf('buff.163.com/market/goods?goods_id=')>-1){
        window.onload=function(){
            setTimeout(choice,5000);
        }
    }
})();

function btn(){
    var li = "<div id='addBtn' style='cursor:pointer;z-index:998;position:fixed;left:10px;top:200px;font-size:100%'>A 上一页<br/>S 居中且过滤<br/>D 下一页<br/>W 居中<br/>E 过滤后全部打开</div>";
    var Btn = "<div id='addBtn' style='cursor:pointer;z-index:998;position:fixed;text-align: center;left:10px;top:300px;font-size:250%'>过滤</div>";
    var next = "<div id='nextpage' style='cursor:pointer;z-index:998;position:fixed;text-align: center;left:10px;top:350px;font-size:250%'>下一页</div>";
    $("body").append(li,Btn,next);
    document.getElementById('addBtn').onclick=function(){
        filter();
    }
    document.getElementById('nextpage').onclick=function(){
        nextpage();
    }
}

function middle(){  //居中
    try{
        if($('.market-card').width()>$(window).height()){
            $(this).scrollTop($('.market-card').offset().top)
        }else{
            $(this).scrollTop($('.market-card').offset().top+($(window).height()-$('.market-card').width())/2);
        }
    }catch(e){console(e)}
}

function choice(){    //余额比例设置
    var hbr=$(".hbr")[0],lsr=$(".lsr")[0];  //lsr最低出售价比例  hbr最高收购价比例
    if(lsr.innerText>0.7){
        if(hbr.innerText>0.71){   //设置最低余额比例过滤--按最高收购价
            window.close();
        }
    }else{
        if(hbr.innerText>0.72){
            window.close();
        }
    }
}

function filter(){     //过滤
    return new Promise(resolve => {
        var c="",n=0,l=document.getElementsByClassName("l_Right f_12px f_Bold c_Gray"),i=l.length-1;
        for(i;i>=0;i--){
            c=l[i].innerHTML.replace(/件在售/g, '');
            if(c<300){                                  //设置最少在售数量
                console.log("个被过滤");
                l[i].parentNode.parentNode.remove();
                ++n;
            }
            if(n==20){
                nextpage();
            }
        }
    });
}

function nextpage(){
    try{
        document.getElementsByClassName("page-link next")[0].click();
        try{
            setTimeout(filter,3000);
        }catch(e){console(e)}
    }catch(e){console(e)}
}

function prevpage(){
    try{
        document.getElementsByClassName("page-link prev")[0].click();
    }catch(e){console(e)}
}

function allopen(){
    try{
        var i=0,l=$('.lazy')
        for(i;i<l.length;i++){
            window.open(l[i].parentNode.href,i);
        }
    }catch(e){console(e)}
}