暗黑修仙小帮手

暗黑修仙小小小帮手

// ==UserScript==
// @name         暗黑修仙小帮手
// @namespace    http://119.91.99.233:8088/
// @version      1.7.7
// @description  暗黑修仙小小小帮手
// @author       iuv@ixx
// @match        http://119.91.99.233:8088/*
// @icon         https://www.google.com/s2/favicons?domain=99.233
// @grant        unsafeWindow
// @license      MIT
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @require https://greasyfork.org/scripts/447160-enhance-tool-i/code/Enhance%20Tool%20I.js?version=1069297
// @require      https://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

(function() {
    var ms ={};
    ms["初始大陆"] = ["东部矿坑,50,25","封魔谷,50,50","血色森林,0,50"]
    ms["盟重土城"] = ["镇妖塔一层,104,97","盟重矿区,98,97","祖玛寺庙一层,180,180"]
    ms["盟重矿区"] = ["盟重土城,0,0","小智,25,25"]
    ms["东部矿坑"] = ["初始大陆,0,20","矿坑北,20,0","矿坑东,40,20"]
    ms["矿坑北"] = ["东部矿坑,10,40","矿坑深处,10,0"]
    ms["矿坑深处"] = ["矿坑北,0,10"]
    ms["矿坑东"] = ["东部矿坑,0,10","神秘坑道,20,0"]
    ms["神秘坑道"] = ["矿坑东,0,1","神秘人,30,1"]
    ms["血色森林"] = ["初始大陆,30,0","血色之证,15,15","环境调查员,1,30"]
    ms["封魔谷"] = ["封魔战场,15,15","封魔矿区,0,15","盟重土城,30,30"]
    ms["封魔矿区"] = ["阴暗洞窟,0,25,1","封魔道,25,50"]
    ms["阴暗洞窟"] = ["封魔矿区,40,5","卡金宝宝,0,5"]
    //ms["封魔道"] = ["封魔道,0,30"]
    ms["封魔道"] = ["霸者大厅,0,30"]
    ms["封魔战场"] = ["终结之地,25,25","兽人锻造大师,50,25"]
    ms["终结之地"] = ["封魔战场,10,10","封魔谷,25,50"]
    ms["镇妖塔一层"] = ["镇妖塔二层,50,50"]
    ms["镇妖塔二层"] = ["镇妖塔三层,50,50"]
    ms["镇妖塔三层"] = ["镇妖塔四层,50,50"]
    ms["镇妖塔四层"] = ["镇妖塔五层,50,50"]
    ms["镇妖塔五层"] = ["镇妖塔六层,50,50"]
    ms["镇妖塔六层"] = ["镇妖塔七层,50,50"]
    ms["镇妖塔七层"] = ["镇妖塔八层,50,50"]
    ms["镇妖塔八层"] = ["镇妖塔九层,50,50"]
    ms["镇妖塔九层"] = ["镇妖塔十层,50,50"]
    ms["祖玛寺庙一层"] = ["祖玛寺庙二层,0,0"]
    ms["祖玛寺庙二层"] = ["祖玛寺庙三层,0,0","祖玛寺庙一层,20,20"]
    ms["祖玛寺庙三层"] = ["祖玛寺庙四层,0,0","祖玛寺庙二层,20,20"]
    ms["祖玛寺庙四层"] = ["祖玛寺庙五层,0,0","祖玛寺庙三层,30,30"]
    ms["祖玛寺庙五层"] = ["祖玛寺庙六层,0,0","祖玛寺庙四层,30,30"]
    ms["祖玛寺庙六层"] = ["祖玛寺庙七层,0,0","祖玛寺庙五层,30,30"]
    ms["祖玛寺庙七层"] = ["祖玛寺庙六层,10,10"]
    ms["霸者大厅"] = []
    ms["镇妖塔十层"] = []
    var YWXL = ["5,5","95,5","95,16","5,16","5,27","95,27","95,38","5,38","5,49","95,49","95,60","5,60","5,71","95,71","95,82","5,82","5,93","95,93","95,100","5,100"];
    function byId(id){
        return document.getElementById(id);
    }
    function byClass(id){
        return document.getElementsByClassName(id);
    }
    // 寻路
    var DS = [];
    function depixx(target,now,idx){
        var base = [];
        if(idx>=0){
            base = DS[idx].slice();
        }
        Object.keys(ms).forEach(function (key) {
            var list = ms[key];
            for(var i = 0; i<list.length;i++){
                var b = false;
                for(var j=0;j<base.length;j++){
                    if(target == base[j].split(",")[0]){
                        b = true;
                    }
                }
                if(b){return}
                if(target == list[i].split(",")[0]){
                    var tmp = base.slice();
                    tmp.push(list[i]);
                    DS.push(tmp)
                    // 如果已经是当前地图
                    if( now == target){
                        return;
                    } else if(",初始大陆,封魔谷,盟重土城,".indexOf(key)>0){//判断key是不是传送石之地
                        DS[DS.length-1].push(key);
                        return;
                    }
                    depixx(key,now,DS.length-1);
                }
            }
        });
    }
    // 自动寻路
    unsafeWindow.autoGo = function autoGo(target,cb){
        byId("ixxmap").style.display='none';
        if(!target){return}
        DS=[];
        var now = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[0];
        if(now == target){
            if(cb){
                cb();
            };
            return
        }
        depixx(target, now,-1);
        var steps =[];var minStep = 100000;
        for(var i=0;i<DS.length;i++){
            var list = DS[i];
            var last = list[list.length-1].split(",")[0];
            if(last == now || ",初始大陆,封魔谷,盟重土城,".indexOf(last)>0){
                if(list.length<minStep){
                    minStep = list.length;
                    steps = list;
                } else if(list.length == minStep && last == now){
                    minStep = list.length;
                    steps = list;
                }
            }
        }
        //console.log(steps)
        if(steps.length == 0){
            alert("呃...无法从"+now+"寻路到"+target);
            return;
        }
        if(target == "霸者大厅"){
            steps.splice(1, 0, "封魔道,0,30");
        }
        var st = steps.pop();
        // 如果最后是使用,分隔则说明是从当前地图可以直接过去,否则是使用传送石
        if(",初始大陆,封魔谷,盟重土城,".indexOf(st.split(",")[0]) < 0){// 不用使用
            autoZL(steps,cb);
        } else { // 使用传送
            if(now != st){
                var ret = unsafeWindow.chuansong(st.split(",")[0]+"回城石");
                if(!ret){return}
            }
            setTimeout(autoZL, 800, steps, cb);
        }
    }
    var ZDD = 0;
    // 自动走路
    function autoZL(steps,cb){
        ZDD = 0;
        var cs = [];
        var parent = "abc";
        for(var i=steps.length-1;i>=0;i--){
            var step = steps[i];
            cs.push(['()=>{unsafeWindow.gogo("'+step+'");}','()=>{var nows = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":");var now = nows[0];if(now=="封魔道"&&"'+step+'".indexOf("霸者大厅")>=0){if(ZDD<8){ZDD++;console.log(ZDD);return false;}};console.log(now);if(!parent){return false;};return "'+parent+'" == "abc" || "'+parent+'".indexOf(now)>=0;}',1500])
            parent = step;
        }
        if(cb){
            cs.push([cb,'()=>{var nows = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":");var now = nows[0];return now == "'+parent.split(",")[0]+'" || "abc"=="'+parent+'"}',1500]);
        }
        setTimeout(ixx, 1000, cs, 0);
    }
    // cmds is [run, check, time, param]
    function ixx(cmds, i){
        var cmd = cmds[i]
        //console.log(cmd)
        if(cmds.length<=i){
            return;
        }
        if(cmd[1] && !eval("("+cmd[1]+")()")){
            setTimeout(ixx, cmd[2], cmds, i);
            return;
        } else {
            eval("("+cmd[0]+")()");
            setTimeout(ixx, cmd[2], cmds, i+1);
        }
    }
    // 传送方法(使用传送石)
    unsafeWindow.chuansong = function chuansong(map){
        var equips = byClass("equip");
        var goods = equips[equips.length-1].getElementsByClassName("ant-list-item ant-list-item-no-flex");
        for(var i= 0;i<goods.length;i++){
            var name = goods[i].innerText.split(" x")[0];
            if(map == name){
                goods[i].getElementsByTagName("a")[2].click();
                setTimeout(refMap,800);
                return 1;
            }
        }
        alert("没有"+map+"的传送石了!");
        return 0;
    }
    // 刷新可去地图
    function refMap(){
        // 现在的地图
        var txt = "";
        var now = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[0];
        // 获取可以走过去的地图
        var nextmap = ms[now];
        if(nextmap){
            for(var i= 0; i<nextmap.length;i++){
                txt += "<button onclick='window.gogo(\""+nextmap[i]+"\",)'>"+nextmap[i].split(',')[0]+"</button>&nbsp;"
            }
        }
        byId("mv").innerHTML = txt;
    }
    // 去下一个地图
    unsafeWindow.gogo = function gogo(nextmap){
        byClass("ant-card-body")[3].getElementsByClassName("ant-tabs-tab")[0].click();
        var nexts = nextmap.split(",");
        // 设置坐标
        var ips = byClass("ant-card-body")[2].getElementsByTagName("input");
        ips[0].value = nexts[1];
        ips[0].dispatchEvent(new Event('input'));
        ips[1].value = nexts[2];
        ips[1].dispatchEvent(new Event('input'));
        setTimeout(function(){
            var btns = byClass("ant-card-body")[2].getElementsByTagName("button");
            btns[btns.length-1].click();
        }, 500);
        var btnidx = 0;
        if(nexts.length==4){
            btnidx = nexts[3];
        }
        var cs = [];
        cs.push([()=>{byClass("ant-card-body")[3].getElementsByClassName("ant-list-item")[0].getElementsByTagName("a")[1].click();},'()=>{return byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[1] == "'+nexts[1]+','+nexts[2]+'"}',1000]);
        cs.push([()=>{},()=>{return byClass("ant-modal-content").length>0},100])
        cs.push(['()=>{byClass("ant-modal-content")[0].getElementsByTagName("button")['+btnidx+'].click();}',()=>{return byClass("ant-modal-content").length>0},300])
        cs.push([()=>{refMap()},()=>{return byClass("ant-modal-content").length==0},300]);
        ixx(cs,0);
    }
    // 找妖王
    var YWID;
    var YWIDX;
    unsafeWindow.findYw = function findYw(){
        if(!YWIDX){
            YWIDX=0;
            var i = YWIDX++;
            if(byId("ywsort").checked){
                i = YWXL.length-i-1;
            }
            ywxls = YWXL[i].split(",");
            ppx(ywxls[0],ywxls[1]);
            YWID = setInterval(findYw,650);
        } else {
            // 判定是否停止
            var btns = byClass("ant-card-body")[2].getElementsByTagName("button");
            if(btns[btns.length-1].innerText.indexOf("虾")>0){
                if(YWIDX>=YWXL.length){
                    unsafeWindow.findYwStop();
                    return;
                }
                i = YWIDX++;
                if(byId("ywsort").checked){
                    i = YWXL.length-i-1;
                }
                var ywxls = YWXL[i].split(",");
                ppx(ywxls[0],ywxls[1]);
            }
            // 判定是否有妖王
            if(byId("map").innerText.indexOf(" 妖王")>=0){
                unsafeWindow.findYwStop();
                alert("找到了Q_Q");
            }
            return;
        }
    }
    unsafeWindow.findYwStop = function findYwStop(){
        YWIDX=0;
        clearInterval(YWID);
        var btns = byClass("ant-card-body")[2].getElementsByTagName("button");
        if(btns[btns.length-1].innerText.indexOf("虾")<0){
            btns[btns.length-1].click();
        }
    }
    // 皮皮虾
    function ppx(x,y){
        // 设置坐标
        var ips = byClass("ant-card-body")[2].getElementsByTagName("input");
        ips[0].value = x;
        ips[0].dispatchEvent(new Event('input'));
        ips[1].value = y;
        ips[1].dispatchEvent(new Event('input'));
        setTimeout(function(){
            var btns = byClass("ant-card-body")[2].getElementsByTagName("button");
            btns[btns.length-1].click();
        }, 500);
    }
    // 挖宝
    unsafeWindow.wb = function wb(){
        // 查询日志
        var now = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[0];
        var logs = byClass("ant-drawer-body")[0].getElementsByTagName("p");
        if(logs.length>0 && logs[logs.length-1].innerText.split("藏宝图上的坐标位于").length>1){
            var log = logs[logs.length-1].innerText.split("藏宝图上的坐标位于");
            var target = log[1].split("的")[0];
            if(now != target){
                setTimeout(wb, 1000);
                return;
            }
            var xy = log[1].split("的")[1];
            var x = xy.split(",")[0];
            var y = xy.split(",")[1];
            ppx(x,y);
            var cs = [];
            cs.push([()=>{
                 // 点使用
                var equips = byClass("equip");
                var goods = equips[equips.length-1].getElementsByClassName("ant-list-item ant-list-item-no-flex");
                for(var i= 0;i<goods.length;i++){
                    var name = goods[i].innerText.split(" x")[0];
                    if("藏宝图" == name){
                        goods[i].getElementsByTagName("a")[2].click();
                        setTimeout(wbs,1500);
                        return;
                    }
                }
            },'()=>{return byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[1] == "'+xy+'"}',1000]);
            ixx(cs,0);
        } else {
            // 点使用
            var equips = byClass("equip");
            var goods = equips[equips.length-1].getElementsByClassName("ant-list-item ant-list-item-no-flex");
            for(var i= 0;i<goods.length;i++){
                var name = goods[i].innerText.split(" x")[0];
                if("藏宝图" == name){
                    goods[i].getElementsByTagName("a")[2].click();
                    return;
                }
            }
            alert("没有藏宝图了!");
        }
    }
    // 寻路地图
    unsafeWindow.wbs = function wbs(){
        // 点使用
        var equips = byClass("equip");
        var goods = equips[equips.length-1].getElementsByClassName("ant-list-item ant-list-item-no-flex");
        for(var i= 0;i<goods.length;i++){
            var name = goods[i].innerText.split(" x")[0];
            if("藏宝图" == name){
                goods[i].getElementsByTagName("a")[2].click();
                setTimeout(function(){
                    var logs = byClass("ant-drawer-body")[0].getElementsByTagName("p");
                    if(logs.length>0 && logs[logs.length-1].innerText.split("藏宝图上的坐标位于").length>1){
                        var log = logs[logs.length-1].innerText.split("藏宝图上的坐标位于");
                        var target = log[1].split("的")[0];
                        unsafeWindow.autoGo(target, unsafeWindow.wb);
                    }
                },1500);
                return;
            }
        }
        alert("没有藏宝图了!");

    }
    // dps显示
    var DPS=0;
    unsafeWindow.dps = function dps(){
        var aps = byClass("ant-tabs-tabpane ant-tabs-tabpane-active")[0].getElementsByTagName("p");
        if(aps.length<20){
            return;
        }
        //计算是物理还是法术
        var wgs = aps[14].innerText.split(":")[1].split("-");
        var wgjl = aps[16].innerText.split(":")[1].split("%")[0];
        var wgbl = aps[17].innerText.split(":")[1].split("%")[0];
        var fgs = aps[19].innerText.split(":")[1].split("-");
        var fgjl = aps[21].innerText.split(":")[1].split("%")[0];
        var fgbl = aps[22].innerText.split(":")[1].split("%")[0];
        var d = 0;
        if(wgs.length==1){
            return
        }
        if(parseInt(wgs[1])>parseInt(fgs[1])){
            d = (parseInt(wgs[0])+parseInt(wgs[1]))/2*parseInt(wgjl)*parseInt(wgbl)/10000;
        } else {
            d = (parseInt(fgs[0])+parseInt(fgs[1]))/2*parseInt(fgjl)*parseInt(fgbl)/10000;
        }
        d = d.toFixed(2);
        var txt = ""+d;
        if(DPS == d){
            return;
        }
        if(DPS!=0){
            var dx = d-DPS;
            dx = dx.toFixed(2);
            if(d>DPS){
                txt += "<span style='color: red;'>&nbsp;&nbsp;+"+dx+"</span>"
            } else {
                txt += "<span style='color: green;'>&nbsp;&nbsp;"+dx+"</span>"
            }
        }
        DPS = d;
        byId("dps").innerHTML=txt;
    }
    // 显示吸蓝吸血属性
    function xhxm(){
        var ps = byClass("ant-tabs-tabpane ant-tabs-tabpane-active")[0].getElementsByTagName("p");
        if(ps.length<14){
            return;
        }
        var equips = byClass("equip");
        var zbs = equips[equips.length%2].getElementsByClassName("ant-list")[0].getElementsByClassName("ant-list-item");
        if(!zbs || zbs.length==0){
            return;
        }
        var xmp = 0;
        var xhp = 0;
        for(var i=0;i<zbs.length;i++){
            var mps = zbs[i].innerText.split("MP窃取+");
            if(mps.length==2){
                xmp+=parseInt(mps[1].split("%")[0]);
            }
            var hps = zbs[i].innerText.split("HP窃取+");
            if(hps.length==2){
                xhp+=parseInt(hps[1].split("%")[0]);
            }
        }
        $("#ixxxmp").html(xmp+"%");
        $("#ixxxhp").html(xhp+"%");
    }
    // 升级时间显示
    function upLevel(){
        dps();
        xhxm();
        //console.log("upup...");
        var ps = byClass("ant-tabs-tabpane ant-tabs-tabpane-active")[0].getElementsByTagName("p");
        if(ps.length<4){
            return;
        }
        var title = ps[3].getAttribute("title")
        if(title){
            var all = title.split("/")[1];
            var now = title.split("/")[0];
            var xl =  ps[4].innerText.split(":")[1];
            xl = xl.split("/")[0];
            var txt = "";
            if(xl>0) {
                var mins = (all-now)/xl;
                if(mins>60){
                    mins = mins/60;
                    txt += mins.toFixed(2)+"小时";
                } else {
                    txt += mins.toFixed(2)+"分钟";
                }
            }
            byId("levelUp").innerHTML=txt;
        }
    }
    // 初始化升级法宝
    function initfb(){
        byClass("ant-card-body")[0].getElementsByClassName("ant-tabs-tab")[0].click();
        var ps = byClass("fb")[0].getElementsByTagName("p");
        var options = "";
        for(var i=2;i<ps.length;i++){
            options += "<option value='"+i+"'>"+ps[i].innerText.split(":")[0];+"<option>";
        }
        byId("ixxfb").innerHTML = options;
        byId("ixxfb2").innerHTML = options;
        var fbv = unsafeWindow.localStorage.getItem("fbv");
        if(fbv){
            byId("ixxfb").value = unsafeWindow.localStorage.getItem("fbidx");
            byId("ixxfbeq").value = unsafeWindow.localStorage.getItem("fbeq");
            byId("ixxfbipt").value = fbv;
        }
        var fbv2 = unsafeWindow.localStorage.getItem("fbv2");
        if(fbv2){
            byId("ixxfb2").value = unsafeWindow.localStorage.getItem("fbidx2");
            byId("ixxfbeq2").value = unsafeWindow.localStorage.getItem("fbeq2");
            byId("ixxfbipt2").value = fbv2;
        }
    }
    // 自动升法宝
    var fbId;
    unsafeWindow.ixxAutoFb = function ixxAutoFb(){
        var ixxfbcb = byId("ixxfbcb").checked;
        // 开启
        if(ixxfbcb){
            var idx = byId("ixxfb").value;
            var eq = byId("ixxfbeq").value;
            var v = byId("ixxfbipt").value;
            if(v){
                unsafeWindow.localStorage.setItem("fbidx", idx);
                unsafeWindow.localStorage.setItem("fbeq", eq);
                unsafeWindow.localStorage.setItem("fbv", v);
            }
            var idx2 = byId("ixxfb2").value;
            var eq2 = byId("ixxfbeq2").value;
            var v2 = byId("ixxfbipt2").value;
            if(v2){
                unsafeWindow.localStorage.setItem("fbidx2", idx2);
                unsafeWindow.localStorage.setItem("fbeq2", eq2);
                unsafeWindow.localStorage.setItem("fbv2", v2);
            } else {
                unsafeWindow.localStorage.removeItem("fbidx2");
                unsafeWindow.localStorage.removeItem("fbeq2");
                unsafeWindow.localStorage.removeItem("fbv2");
            }
            fbId = setInterval(autoFb, 30000);//30秒检查一次
            console.log(fbId);
        } else { // 关闭
            clearInterval(fbId);
        }
    }
    var FBNUM = 1;
    function autoFb(){
        var logtxt="<div>";
        var d = new Date();
        // 点击升级
        var up = byId("bility").nextSibling.nextSibling.getElementsByTagName("a")[0];
        var ass = byId("bility").nextSibling.nextSibling.nextSibling.nextSibling.nextSibling;
        if(up){
            up.click();
            setTimeout(autoFb, 1500);
        } else if(ass.innerText){
            var idx = byId("ixxfb").value;
            var ps = byClass("fb")[0].getElementsByTagName("p")[idx].innerText.split("+");
            var eq = byId("ixxfbeq").value;
            var v = byId("ixxfbipt").value;
            var idx2 = byId("ixxfb2").value;
            var ps2 = byClass("fb")[0].getElementsByTagName("p")[idx2].innerText.split("+");
            var eq2 = byId("ixxfbeq2").value;
            var v2 = byId("ixxfbipt2").value;
            var as = ass.getElementsByTagName("a");
            logtxt += d.getHours()+":"+d.getMinutes()+" 第"+(FBNUM++)+"次,设置1:"+v+",当前1:"+ps[1];
            if((eq==1 && ps.length>1 && parseFloat(ps[1])>parseFloat(v))||(eq==0 && (ps.length==1||parseFloat(ps[1])<parseFloat(v)))){
                if(v2){
                    logtxt += ",设置2:"+v2+",当前2:"+ps2[1];
                    if((eq2==1 && ps2.length>1 && parseFloat(ps2[1])>parseFloat(v2))||(eq2==0 && (ps2.length==1||parseFloat(ps2[1])<parseFloat(v2)))){
                        as[1].click();
                        logtxt += ",结果:<span style='color:green'>升级<span>";
                        FBNUM=1;
                    } else {
                        logtxt += ",结果:<span style='color:red'>不升级<span>";
                        as[0].click();
                    }
                } else {
                    as[1].click();
                    logtxt += ",结果:<span style='color:green'>升级<span>";
                    FBNUM=1;
                }
            } else {
                logtxt += ",结果:<span style='color:red'>不升级<span>";
                as[0].click();
            }
            logtxt +="</div>";
            $("#ixxlog").append(logtxt);
        }

    }
    var gjId;
    // 自动检查挂机
    unsafeWindow.ixxAutoGj = function autoGj(){
        var ixxgj = byId("ixxgj").checked;
        var gjmap = byId("ixxgjmap").value;
        if(!ms[gjmap]){
            alert("输入的挂机地图有误");
            byId("ixxgj").checked = false;
            return;
        }
        if(ixxgj){
            //记录挂机参数
            var ipts = byClass("ant-card-body")[5].getElementsByTagName("input");
            unsafeWindow.localStorage.setItem("gjmap",gjmap);
            if(ipts.length>1){
                unsafeWindow.localStorage.setItem("ipts5",ipts[5].checked);
                unsafeWindow.localStorage.setItem("ipts6",ipts[6].checked);
                unsafeWindow.localStorage.setItem("ipts7",ipts[7].checked);
                unsafeWindow.localStorage.setItem("ipts9",ipts[9].checked);
                unsafeWindow.localStorage.setItem("ipts11",ipts[11].checked);
                unsafeWindow.localStorage.setItem("ipts8",ipts[8].value);
                unsafeWindow.localStorage.setItem("ipts10",ipts[10].value);
                unsafeWindow.localStorage.setItem("ipts12",ipts[12].value);
            }
            gjId = setInterval(gj, 300000); //每五分钟检查一次
        } else {
            clearInterval(gjId);
        }
    }
    // 检查挂机方法
    function gj(){
        var gjmap = byId("ixxgjmap").value;
        var now = byClass("carddd")[2].getElementsByClassName("ant-card-head-title")[0].innerText.split(":")[0];
        var btns = byClass("ant-btn ant-btn-primary");
        var btn = btns[btns.length-1];
        // 打妖王、鸡蛋和皮卡丘时不检测挂机
        if(now.indexOf("妖王")>=0 || byId("map").innerText.indexOf("皮卡丘")>=0 || byId("map").innerText.indexOf("基尔加丹")>=0){
            return;
        }
        // 如果不在挂机地图且挂机中
        if(gjmap != now && btn.innerText == "停止挂机"){
            // 先停止
            btn.click();
            // 去挂机地图
            unsafeWindow.autoGo(gjmap, function(){
                var btns = byClass("ant-btn ant-btn-primary");
                var btn = btns[btns.length-1];
                // 开始挂机
                btn.click();
            });
        }
        console.log(gjmap+"...gjgjgj");
    }
    // 自动卖灵法
    var lfId;
    unsafeWindow.ixxAutoLf = function autoLf(){
        var ixxlf = byId("ixxlf").checked;
        if(ixxlf){
            lfId = setInterval(sellEquip, 600000); //每十分钟启动一次
        } else {
            clearInterval(lfId);
        }
    }
    //自动卖灵法
    function sellEquip(){
        console.log("卖灵法..")
        var data = {equipIds: ["2", "3"]};
        $.ajax({
            url: '/api/sellUnlockEquipId',
            data: JSON.stringify(data),
            contentType: 'application/json',
            type: "post",
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                if(data.status == 200){
                    setTimeout(function(){
                        var equips = byClass("equip");
                        equips[equips.length%2].getElementsByTagName("button")[3].click();
                    }, 1000);
                }
            }
        });
    }
    // 后台运行
    function backgroundRun(){
        console.log("启用后台运行功能...");
        // 后台运行js设置,防止节能影响定时任务
        const chromeVersion = /Chrome\/([0-9.]+)/.exec(window?.navigator?.userAgent)?.[1]?.split('.')[0];
        if (chromeVersion && parseInt(chromeVersion, 10) >= 88) {
            const videoDom = document.createElement('video');
            const hiddenCanvas = document.createElement('canvas');

            videoDom.setAttribute('style', 'display:none');
            videoDom.setAttribute('muted', '');
            videoDom.muted = true;
            videoDom.setAttribute('autoplay', '');
            videoDom.autoplay = true;
            videoDom.setAttribute('playsinline', '');
            hiddenCanvas.setAttribute('style', 'display:none');
            hiddenCanvas.setAttribute('width', '1');
            hiddenCanvas.setAttribute('height', '1');
            hiddenCanvas.getContext('2d')?.fillRect(0, 0, 1, 1);
            videoDom.srcObject = hiddenCanvas?.captureStream();
        }
    }
    // 查看升级法宝日志
    var LOG_STATUS = true;
    unsafeWindow.viewLog = function viewLog(){
        if(LOG_STATUS){
            $("#ixxlog").show();
            LOG_STATUS = false;
        } else {
            $("#ixxlog").hide();
            LOG_STATUS = true;
        }
    }
    // 查看算命装备对应
    var SM_STATUS = true;
    unsafeWindow.viewSm = function viewSm(){
        if(SM_STATUS){
            $("#ixxsm").show();
            SM_STATUS = false;
        } else {
            $("#ixxsm").hide();
            SM_STATUS = true;
        }
    }
    // 全选择装备
    var GOODS_STATUS = true;
    unsafeWindow.allGoods = function allGoods(){
        var equips = byClass("equip");
        var ips = equips[equips.length%2].getElementsByTagName("input");
        for(var i=0;i<ips.length;i++){
            if(ips[i].checked != GOODS_STATUS){
                setTimeout(function(ips,i){
                    ips[i].dispatchEvent(new MouseEvent("click"));
                },50, ips,i);
            }
        }
        setTimeout(function(){
        var lis = equips[equips.length%2].getElementsByClassName("ant-list-item");
        for(i= 0;i<lis.length;i++){
                $(lis[i]).css({
                    "display": "inline-block",
                    "margin-left": "5px",
                    "width": "180px",
                    "vertical-align": "top",
                    "border-bottom": "0px",
                    "border-top": "1px solid #f0f0f0"
                });
        }},1000);
        GOODS_STATUS = !GOODS_STATUS;
    }
    // 保存装备方案
    unsafeWindow.saveZb = function saveZb(){
        var r=confirm("确定要更新方案吗?")
        if (r==false)
        {
            return;
        }
        $.ajax({
            url: '/api/getEquip',
            contentType: 'application/json',
            type: "get",
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                // 获取装备方案
                var ixxzb=$("input[name='ixxzb']:checked").val();
                // 判断已装备id
                if(data.status == 200){
                    var ids = ",";
                    var list = data.data.equipList;
                    for(var i=0;i<list.length;i++){
                        if(list[i].status == 1){
                            ids += list[i]._id+",";
                        }
                    }
                    unsafeWindow.localStorage.setItem("ixxzbfa"+ixxzb, ids);
                } else {
                    alert("保存失败,请重试!");
                }
            }
        });
    }
    // 应用装备方案
    unsafeWindow.applyZb = function applyZb(f){
        if(!f){
            var equips = byClass("equip");
            var ips = equips[equips.length%2].getElementsByTagName("input");
            if(ips[ips.length-1].checked){
                ips[ips.length-1].dispatchEvent(new MouseEvent("click"));
            }
            equips[equips.length%2].getElementsByTagName("button")[3].click();
            setTimeout(applyZb, 1500, 1);
            return;
        }
        // 获取装备方案
        var ixxzb=$("input[name='ixxzb']:checked").val();
        var ids = unsafeWindow.localStorage.getItem("ixxzbfa"+ixxzb);
        if(!ids){return}
        $.ajax({
            url: '/api/getEquip',
            contentType: 'application/json',
            type: "get",
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                // 判断已装备id
                if(data.status == 200){
                    var list = data.data.equipList;
                    var t = 1200;
                    var idx = 0;
                    var zb;
                    for(var i=0;i<list.length;i++){
                        if(list[i].status == 0 && ids.indexOf(list[i]._id)>0){
                            if(!zb){
                                var equips = byClass("equip");
                                zb = equips[equips.length%2].getElementsByClassName("ant-list")[1].getElementsByClassName("ant-list-item")[idx].getElementsByTagName("a");
                                continue;
                            }
                            setTimeout(function(id,name){
                                var data = {id: id};
                                $.ajax({
                                    url: '/api/equip',
                                    data: JSON.stringify(data),
                                    contentType: 'application/json',
                                    type: "post",
                                    beforeSend: function (request) {
                                        request.setRequestHeader("token", localStorage.token);
                                    },
                                    success: function (data) {
                                        if(data.status == 200){
                                            console.log("更换装备:"+name+" 成功!");
                                        }
                                    }
                                });
                            },t,list[i]._id,list[i].name);
                            t = t+1200;
                        }
                        if(list[i].status == 0){
                            idx++;
                        }
                    }
                    // 刷新装备
                    setTimeout(function(){
                        console.log("更换装备:"+zb[0].innerText+" 成功!");
                        zb[zb.length-1].click();
                        alert("换装完毕");
                    }, t+1000);
                } else {
                    alert("应用失败,请重试!");
                }
            }
        });

    }
    // 未装备列表展示
    var ZBLIST = [false, false]
    unsafeWindow.zbList = function zbList(idx){
        var equips = byClass("equip");
        var div = equips[equips.length%2].getElementsByClassName("ant-spin-container")[idx]
        var lis = equips[equips.length%2].getElementsByClassName("ant-list-item");
        if(!ZBLIST[idx]){
            $(div).css({
                "position": "fixed",
                "left": "450px",
                "top": "100px",
                "height": "800px",
                "width": "1024px",
                "z-index": 1000,
                "background": "#fff",
                "overflow": "auto",
                "border": "double 4px cadetblue"
            });
            for(var i= 0;i<lis.length;i++){
                $(lis[i]).css({
                    "display": "inline-block",
                    "margin-left": "5px",
                    "width": "180px",
                    "vertical-align": "top",
                    "border-bottom": "0px",
                    "border-top": "1px solid #f0f0f0"
                });
            }
        } else {
            $(div).attr("style","");
            for(i= 0;i<lis.length;i++){
                $(lis[i]).attr("style","");
            }
        }
        ZBLIST[idx] = !ZBLIST[idx];
    }
    // 换宝图
    var HBTID;
    unsafeWindow.hbt = function hbtStart(){
        if(HBTID){
            clearInterval(HBTID);
        } else {
            HBTID = setInterval(hbt,500);
        }
    }
    // 换宝图,一直换完
    function hbt(){
        if(byClass("ant-modal-content").length>0){
            byClass("ant-modal-content")[0].getElementsByTagName("button")[1].click();
        } else {
            var npcs = byClass("ant-card-body")[3].getElementsByClassName("ant-list-item");
            for(var i=0;i<npcs.length;i++){
                if(npcs[i].innerText.indexOf("寻宝大师x10")>0){
                    npcs[i].getElementsByTagName("a")[1].click();
                }
            }
        }
    }
    function init(){
        var href = window.location.href;
        if( href.indexOf("login")>0){
            setTimeout(init,1500);
            return;
        }
        // 切换物品
        byClass("ant-card ant-card-bordered carddd")[1].getElementsByClassName("ant-tabs-tab")[1].click();
        var name = byClass("ant-card-head")[0];
        var html = "<div>";
        html += "<div id='ixxmap' style='display:none;position: fixed; left: 200px; top: 10px;z-index:9999; width: 300px; background: #aaa;'>";
        Object.keys(ms).forEach(function (key) {
            html += "<button style='margin-bottom:6px;margin-right:6px;' onclick='window.autoGo(\""+key+"\")'>"+key+"</button>";
        });
        html += "<button onclick='window.autoGo()'>关闭</button></div>";
        html += "<div id='ixxlog' style='display:none;position: fixed; left: 240px; top: 10px;z-index:9999; width: 560px; height:500px; font-size:14px; background: #eee;overflow:auto'>日志:<br></div>";
        html += "<div id='ixxsm' style='display:none;position: fixed; left: 240px; top: 10px;z-index:9999; width: 300px; height:300px; font-size:14px; background: #eee;overflow:auto'>装备列表:<br/>轩辕圣剑-物理武器 <br/>巫月神杖-法术武器 <br/>云霓彩带-头盔 <br/>岚金火链-手套(物) <br/>碎梦涵光-手套(法) <br/>九天霜华-戒指(物) <br/>寒玉龙勾-戒指(法) <br/>游火灵炎-项链(物) <br/>天星奇光-项链(法) <br/>朱雀战衣-衣服 <br/>凌波金莲-鞋子 <br/>千彩流光-腰带</div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>升级:<span id='levelUp' style='width:80px;'></span><a href='javascript:window.dps()'>DPS</a>:<span id='dps'></span></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>传送:<button onclick='window.chuansong(\"初始大陆回城石\");'>初始大陆</button>&nbsp;<button onclick='window.chuansong(\"封魔谷回城石\");'>封魔谷</button>&nbsp;<button onclick='window.chuansong(\"盟重土城回城石\");'>盟重土城</button>&nbsp;</div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'><a href='javascript:window.refMap()'>移动</a>:<span id='mv'></span></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>其他:<button onclick=\"document.getElementById('ixxmap').style.display='';\">寻路</button>&nbsp;&nbsp;<button onclick='viewSm()'>算命</button>&nbsp;&nbsp;<button onclick='window.hbt()'>换宝图</button>&nbsp;&nbsp;</div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>法宝:<select id='ixxfb' style='width:50px;'></select><select style='width:40px;' id='ixxfbeq'><option value='0'>小于</option><option value='1'>大于</option></select><input style='width:30px;' id='ixxfbipt' value='0.1'><button onclick='viewLog()'>日志</button></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>并且<select id='ixxfb2' style='width:50px;'></select><select style='width:40px;' id='ixxfbeq2'><option value='0'>小于</option><option value='1'>大于</option></select><input style='width:30px;' id='ixxfbipt2' >开启<input  type='checkbox' onclick='window.ixxAutoFb()' id='ixxfbcb'></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>挂机:<input value='镇妖塔四层' id='ixxgjmap' style='width:60px' /><input  type='checkbox' onclick='window.ixxAutoGj()' id='ixxgj'>&nbsp;&nbsp;卖灵法:<input  type='checkbox' onclick='window.ixxAutoLf()' id='ixxlf'></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>妖王:反<input id='ywsort' type='checkbox' />&nbsp;<button onclick='findYw()'>找妖王</button>&nbsp;<button onclick='findYwStop();'>停止</button></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>换装:<input name='ixxzb' type='radio' value='0'/>主&nbsp;<input name='ixxzb' type='radio' value='1'/>备&nbsp;<input name='ixxzb' type='radio' value='2'/>移&nbsp;<button onclick='saveZb()'>保存</button>&nbsp;&nbsp;&nbsp;<button onclick='applyZb();'>应用</button></div>";
        html += "<div style='font-size:12px;margin-bottom:6px;'>装备:<button onclick='window.allGoods()'>装备</button>&nbsp;&nbsp;<button onclick='window.zbList(0)'>已装备</button>&nbsp;&nbsp;<button onclick='window.zbList(1)'>未装备</button></div>";
        html += "</div>";
        name.innerHTML += html;
        refMap();
        setInterval(upLevel, 5000);
        // 点击日志
        byClass("ant-card-body")[4].getElementsByTagName("a")[0].click();
        // 点击法宝
        byClass("ant-card-body")[0].getElementsByClassName("ant-tabs-tab")[2].click();
        setTimeout(function(){byClass("ant-drawer-close")[0].click();}, 800);
        unsafeWindow.refMap = refMap;
        // 设置挂机参数
        var gjmap = unsafeWindow.localStorage.getItem("gjmap");
        if(gjmap){
            byId("ixxgjmap").value = gjmap;
        }
        var ipts = byClass("ant-card-body")[5].getElementsByTagName("input");
        if(ipts.length>1){
            if(unsafeWindow.localStorage.getItem("ipts5")=="true"){
                ipts[5].dispatchEvent(new MouseEvent('click'));
            }
            if(unsafeWindow.localStorage.getItem("ipts6")=="true"){
                ipts[6].dispatchEvent(new MouseEvent('click'));
            }
            if(unsafeWindow.localStorage.getItem("ipts7")=="true"){
                ipts[7].dispatchEvent(new MouseEvent('click'));
            }
            if(unsafeWindow.localStorage.getItem("ipts9")=="true"){
                ipts[9].dispatchEvent(new MouseEvent('click'));
            }
            if(unsafeWindow.localStorage.getItem("ipts11")=="true"){
                ipts[11].dispatchEvent(new MouseEvent('click'));
            }
            ipts[8].value = unsafeWindow.localStorage.getItem("ipts8");
            ipts[10].value = unsafeWindow.localStorage.getItem("ipts10");
            ipts[12].value = unsafeWindow.localStorage.getItem("ipts12");
            ipts[8].dispatchEvent(new Event('input'));
            ipts[10].dispatchEvent(new Event('input'));
            ipts[12].dispatchEvent(new Event('input'));
        }
        setTimeout(initfb,1000);
        backgroundRun();
        var ps = byClass("ant-tabs-tabpane ant-tabs-tabpane-active")[0].getElementsByTagName("p");
        $(ps[12]).append("<p>MP窃取:<span id='ixxxmp'></span></p><p>HP窃取:<span id='ixxxhp'></span></p>");
    }
    console.log("init...");
    setTimeout(init,1500);
})();