B站直播自动抢辣条二代by十六夜

我的我的 都是我的

As of 2019-08-20. See the latest version.

// ==UserScript==
// @name         B站直播自动抢辣条二代by十六夜
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  我的我的 都是我的
// @author       逆回十六夜
// @match        https://live.bilibili.com/*
// @grant        none
// ==/UserScript==
var time_get = 100;// 点击抽奖的时间间隔单位毫秒
var time_flash = 10000;// 跳转到下个直播间的时间单位毫秒


$(document).ready(function(){//页面加载完毕执行
    StartPlunder();
});

function StartPlunder() {
    'use strict';
    var index,nowIndex;
    var LIVE_PLAYER_STATUS = window.localStorage["LIVE_PLAYER_STATUS"];

    var href = location.href;
    var id = /\/\d+/.exec(href);
    if(!id){return}
    if(id == '/6498960'){
        if (LIVE_PLAYER_STATUS.indexOf("flash") >= 0) {
            window.localStorage["LIVE_PLAYER_STATUS"]=window.localStorage["LIVE_PLAYER_STATUS"].replace("flash",'html5');
            window.location.reload();
            return
        }

        if(!getUrlParam('baidu')){
            window.open('https://www.baidu.com' ,'_blank');// 弹窗测试
        }

        setInterval(function (){//打开链接时钟
            var link = $(".msg-content .link");
            if (link.length > 0) {
                let numberList = [];
                let linkList = [];
                link.each(function(){
                    var link_href = $(this).attr('href');
                    if(link_href){
                        link_href = link_href.split('?')[0];
                        let number;
                        let mydate = new Date();
                        if(link_href.match(/\/\d+/) == null){
                            $(this).text('这个不是辣条~' + mydate.toLocaleString());
                        }else{
                            number = /\/\d+/.exec(link_href);//取房间号
                            if(!isInArray(numberList, number)){
                                numberList.push(number);
                                $(this).attr('number', number);
                                $(this).attr('delay', 55);//普通礼物延迟
                                if($(this).text().indexOf('小电视飞船') >= 0){
                                    $(this).attr('delay', 115);//小电视延迟
                                }
                                linkList.push($(this));
                                $(this).text('等待...~');
                            }else{
                                $(this).text('同上直播间~');
                            }
                        }
                        $(this).removeAttr('href');
                        $(this).removeAttr('class');
                    }
                });
                for(let l of linkList){//延迟打开直播间
                    let count = l.attr('delay');
                    console.log(l);
                    let index = setInterval(function () {
                        l.text('等待抽奖...~' + count.toString() + 'S');
                        count--;
                        if(count <= 0){
                            clearTimeout(index);//清除定时器
                            window.open('https://live.bilibili.com' + l.attr('number') + '?mode=Izayoi', '_blank');
                            let mydate = new Date();
                            link.text('辣条已抢~' + mydate.toLocaleString());
                        }
                    },1000);
                }
                console.log(linkList, numberList);
            }
        },10000);
        setInterval(function(){//重置直播间
            var href = location.href;
            if (href.indexOf('baidu') < 0){
                if(href.indexOf('?') >= 0){
                    href+='&baidu=off';
                }else{
                    href+='?baidu=off';
                }
            }
            location.href = href;
        },7200000);
    }else{
        if (LIVE_PLAYER_STATUS.indexOf("html5") >= 0) {
            window.localStorage["LIVE_PLAYER_STATUS"]=window.localStorage["LIVE_PLAYER_STATUS"].replace("html5",'flash');
            window.location.reload();
            return
        }
        if(getUrlParam("mode")){
            setInterval(function () {
                $(".main").click();//点击抽奖
                $(".draw-full-cntr .function-bar").click();//点击抽奖

            } , 100);

            setTimeout(function () {
                window.close();//超时关闭直播间
            },time_flash);
        }else{
            mode_old();
        }
    }

    function mode_old(){
        try {
            index = getUrlParam("index");
            nowIndex = parseInt(index)+1;
            if(nowIndex==12){
                nowIndex = 0;
            }
            if(isNaN(nowIndex))nowIndex=0;
        } catch (error) {
            nowIndex = 0;
        }
        setInterval(function () {
            $(".main").click();//点击抽奖
            $(".draw-full-cntr .function-bar").click();//点击抽奖
        }, 500);
        setInterval(function () {
            goTop(nowIndex);
        },time_flash);
    }

    function goTop(index){
        $.get("https://api.live.bilibili.com/rankdb/v1/Rank2018/getTop?type=master_realtime_hour&type_id=areaid_realtime_hour",function(data){
            var list = data.data.list;// [{id: ,link:}]
            var link = list[nowIndex].link;
            if(!link){
                link = '/55356';
            }
            var href=location.href;
            //
            if(href.match(/\/\d+/) != null){
                href=href.replace(/\/\d+/,link);
            }else{
                href='https://live.bilibili.com'+link;
            }
            //
            if(href.indexOf('index') >= 0){
                href = href.replace(/index=\d+/,'index='+nowIndex);
            }else{
                if(href.indexOf('?') >= 0){
                    href+='&index='+nowIndex;
                }else{
                    href+='?index='+nowIndex;
                }
            }
            //
            location.href = href;
        });
    }
    function isInArray(arr,value){
        for(var i = 0; i < arr.length; i++){
            if(value == arr[i]){
                return true;
            }
        }
        return false;
    }
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
};