自动辣条机

totalLatiao = 0;
upzhu = "";
badScanCnt = 0;
tmHandle = -1;
normalRoom = /[0-9]{3,}/


function work() {
    xx = document.getElementsByClassName("room-card-ctnr");
    //if(xx.length<89)reach();//return setTimeout(reach,1000);
    lst = [];
    for (i = 0; i < xx.length; i++) {
        tt = xx[i].getElementsByTagName("span");
        if (tt.length == 4 && tt[0].innerText == "正在抽奖") {
            console.log(tt[2].innerText + " " + upzhu);
            if (tt[2].innerText != upzhu && xx[i].href) {
                //return console.log("jump to "+xx[i].href);
                lst.push(xx[i].href);
                //window.location = xx[i].href;
            }
        }
    }
    console.log(lst);
    if (lst.length > 0) {
        return window.location.href = lst[Math.round(Math.random() * lst.length)];

    }
    else window.location.href = xx[0].href;
}

function scro(pos) {
    window.scrollTo(0, pos);
}

function reach() {
    tt = document.getElementsByClassName("area-detail-ctnr m-auto");
    window.scrollBy(0, 20000);
    if (tt.length < 9) {
        for (i = 0; i < tt.length; i++)
            setTimeout(scro, 50 + i * 150, tt[i].offsetTop);
        return setTimeout(reach, tt.length*150);
    }
    setTimeout(work, 500);
}
function genInfo(name, num) {
    if (name == "")
        return "已自动点击 " + totalLatiao + " 个礼物,等待下一个";
    return "已自动点击 " + totalLatiao + " 个礼物,下一个 " + name + " 老板。预计还有 " + num + " 个";

}

function showBox(info) {
    xx = document.getElementById("stealBox");
    if (xx) xx.innerText = info;
}
function showInfo(info) {
    tm = new Date();
    xx = document.getElementById("stealInfo");
    if (xx) xx.innerText += tm.toLocaleTimeString() + ":" + info + "\n\r";
    xx.scrollBy(0, 1000);
}

Count = new Map();
Url = new Map();

function getChat() {
    lst = document.getElementById("chat-items");
    Aim = "";
    showInfo("检查" + lst.childNodes.length + "条弹幕中的广播信息");
    for (var i = lst.childNodes.length - 1; i >= 0; i--) {
        if (lst.childNodes[i].style.border != "") {
            ll = lst.childNodes[i].childNodes[3].childNodes[1];
            
            if (ll.href != "" && ll.href != undefined) {
                ngf=0;
                if (ll.childNodes.length == 4) {
                    verb = ll.childNodes[1].innerText;

                    if (verb[0] == "投" || verb[0] == "送" || verb[0] == "在") {

                        console.log(ll.childNodes[3].innerText);
                        if (verb == "在") ngf = 1;
                        else ngf = eval(ll.childNodes[3].innerText.split("个")[0]);

                    }

                }
                else if (ll.childNodes.length == 5) {
                    verb = ll.childNodes[2].innerText;
                    if (verb == '夺得') {
                        console.log(ll.childNodes[4].innerText);
                        ngf = 1;
                        name = ll.childNodes[0].innerText;

                    }
                }
                name = ll.childNodes[2].innerText;
                if (Count.has(name)) Count.set(name, Count.get(name) + ngf);
                else {
                    Count.set(name, ngf);
                    Url.set(name, ll.href.split("?")[0]);
                }
            }
        }
        lst.removeChild(lst.childNodes[i]);
    }

}

function nxt(mgf) {

    getChat();
    hh = "";
    for (let key of Count.keys()) {
        nn = Count.get(key);
        //console.log(key+","+nn+","+mgf);
        hh += '(' + key + '=>' + nn + ') ';
        if (nn > mgf) {
            mgf = nn;
            Aim = key;
        }
    }
    if (hh) showInfo("广播礼物:" + hh);
    if (Aim != "") {
        window.location.href = Url.get(Aim);
    }
    //else console.log("未找到更优的房间");
}



function simple() {
    console.log("清理无用组件");
    ls = ["player-ctnr left-container p-relative z-player-ctnr"];
    for (i in ls) {
        //console.log(ls[i]);
        xx = document.getElementsByClassName(ls[i])[0];
        if (xx) xx.style.display = "none"; //xx[0].parentNode.removeChild(xx[0]);
        else return setTimeout(simple, 2000);
    }
    ls = ["rank-list-vm", "chat-msg-bubble-vm", "chat-gift-bubble-vm", "penury-gift-msg", "sections-vm", "link-footer-vm", "link-navbar-vm", "rank-list-vm"];
    for (i in ls) {
        //console.log(ls[i]);
        yy = document.getElementById(ls[i]);
        if (yy) yy.style.display = "none";// yy.parentNode.removeChild(yy);
        else return setTimeout(simple, 2000);
    }
}

function auto(waitTime) {
    //模拟真人点一下2233
    cc = document.getElementsByClassName("haruna-canvas")[0];
    if (cc) cc.click();
    gg = document.getElementsByClassName("chat-draw-area-cntr")[0];

    if (gg && (zz = gg.getElementsByClassName("count")[0]) && zz.innerText) {

        badScanCnt = 0;
        waitTime = 10;
        //99+的情况,不用考虑别的直播间
        if (zz.innerText.length < 3) nxt(eval(zz.innerText) * 2);

        //领奖按钮
        jj = document.getElementsByClassName("function-bar")[0];
        //已经可以领了
        if (jj && jj.childNodes[2].style.display != "none") {
            jj.childNodes[2].click();
            document.title = "<Thank you! " + upzhu + ">";
            totalLatiao += 1;
            showBox(genInfo(gg.getElementsByClassName("gift-sender-info")[0].childNodes[1].innerText, zz.innerText));
            if (tmHandle != -1) clearTimeout(tmHandle);
            tmHandle = setTimeout(auto, 200, waitTime);
            return null;
            //document.getElementById("stealInfo").innerText = "Wait to get latiao";
        }
        //下一个等一下才能领
        else if (jj) {
            getChat();
            showBox(genInfo(gg.getElementsByClassName("gift-sender-info")[0].childNodes[1].innerText, zz.innerText));
            tm = jj.childNodes[1].innerHTML;
            n = (eval(tm[0] + tm[1]) * 60 + eval(tm[3] + tm[4]));
            n = Math.min(n, waitTime);
            if (tmHandle != -1) clearTimeout(tmHandle);
            tmHandle = setTimeout(auto, 1000 * n, waitTime);
            return null;
        }
        //极有可能是在领完一大堆礼物后进到这 有点击按钮但无礼物
        else {
            getChat();
            showBox(genInfo("", 0));
            if (tmHandle != -1) clearTimeout(tmHandle);
            tmHandle = setTimeout(auto, 1000 * waitTime, waitTime);
            return null;
        }
        return null;
    }
    showInfo("未扫描到礼物,当前扫描间隔:" + waitTime + "秒,已连续空扫描 " + badScanCnt + " 次");
    nxt(0);
    //当前房间无礼物,也无礼物广播
    //坏扫描 每4次连续的 使得等待时间增加
    badScanCnt += 1;
    if (badScanCnt > 2) {
        document.title = "<Come on, " + upzhu + ">";
    }
    waitTime += ((badScanCnt & 3) == 3 ? 5 : 0);
    showBox(genInfo("", 0));

    //刷过了很多礼物,给个机会再多等会
    if (Math.random() * (20 + totalLatiao) < totalLatiao) {
        console.log("让我们再等一会");

    }
    else {
        if (badScanCnt > 4 && Math.random() * 50 < waitTime) window.location.href = "https://live.bilibili.com/?" + upzhu;
    }
    if (tmHandle != -1) clearTimeout(tmHandle);
    tmHandle = setTimeout(auto, 1000 * waitTime, waitTime);

}


function steal() {
    document.title = "<Hello, " + upzhu + ">";
    if (document.getElementsByTagName("article").length > 0) window.location.href = "https://live.bilibili.com/?";
    xx = document.createElement("div");
    yy = document.getElementsByClassName('chat-control-panel')[0];
    if (yy == undefined) return setTimeout(steal, 1000);

    yy.appendChild(xx);
    xx.setAttribute("style", "padding: 10px;    color: rgb(255, 255, 255);    background: rgb(59, 173, 229);box-shadow: inset 0px -9px 8px 2px #7a8198;");
    xx.setAttribute("id", "stealBox");
    xx.innerText = "正在初始化";
    zz = document.createElement("div");
    yy.appendChild(zz);
    zz.setAttribute("id", "stealInfo");
    zz.setAttribute("style", "    background: rgb(255, 255, 255);    height: 150px;    padding: 10px;    overflow-y: scroll;");



    yy = document.getElementById("aside-area-vm");
    yy.style.height = "500px";
    yy.style.width = "40%";
    yy.style.left = "30%";
    console.clear()
    auto(10);
}

uu = window.location.href.split("com/")[1];
if (uu[0] == "?") {
    upzhu = decodeURI(uu.substr(1));
    console.log("avoid " + upzhu);
    reach();
}
else if (normalRoom.test(uu)) {
    setTimeout(simple, 2000);
    upzhu = document.title.split(" - ")[1];
    setTimeout(steal, 2000);
}
else window.location.href = "https://live.bilibili.com/?";

评论

此博客中的热门博文

自动辣条机帮助