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

我的我的 都是我的

As of 2020-10-07 04:51:14 UTC. See the latest version.

// ==UserScript==
// @name         B站直播自动抢辣条二代by十六夜
// @namespace    http://tampermonkey.net/
// @version      2.0
// @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;
                        if(link_href.match(/\/\d+/) == null){
                            link.text('这个不是辣条~' + mydate.toLocaleString());
                        }else{
                            number = /\/\d+/.exec(link_href);//取房间号
                            if(!isInArray(numberList, number)){
                                numberList.push(number);
                                link.number = number;
                                linkList.push(link);
                                link.text('等待...~');
                            }else{
                                link.text('同上直播间~');
                            }
                        }
                        link.removeAttr('href');
                        link.removeAttr('class');
                    }
                });
                for(let l of linkList){//延迟打开直播间
                    let count = 60;
                    let index = setInterval(function () {
                        l.text('等待抽奖...~' + count.toString() + 'S');
                        count--;
                        if(count <= 0){
                            clearTimeout(index);//清除定时器
                            window.open('https://live.bilibili.com' + l.number.toString() + '?mode=Izayoi', '_blank');
                            let mydate = new Date();
                            link.text('辣条已抢~' + mydate.toLocaleString());
                        }
                    },1000);
                }
            }
        },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;
    }
};