Greasy Fork is available in English.

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

吔屎啦 梁非凡!

目前为 2019-08-14 提交的版本。查看 最新版本

// ==UserScript==
// @name         B站直播自动抢辣条二代by十六夜
// @namespace    http://tampermonkey.net/
// @version      1.9
// @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 = [];

                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){
                            link.text('这个不是辣条~' + mydate.toLocaleString());
                        }else{
                            number = /\/\d+/.exec(link_href);//取房间号
                            if(!isInArray(numberList, number)){
                                numberList.push(number);
                            }
                            link.text('辣条已抢~' + mydate.toLocaleString());
                        }
                        link.removeAttr('href');
                        link.removeAttr('class');
                    }
                });
                for(let n of numberList){//打开直播间
                    window.open('https://live.bilibili.com' + n + '?mode=Izayoi', '_blank');
                }
            }
        },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 () {
                if ($(".lottery-box .main").length > 0) {
                    $(".lottery-box .main").click();//点击抽奖
                    setTimeout(function () {
                        $(".popup-content-ctnr button").click()
                    }, time_get);

                    let titleArray = $(".lottery-box .title");
                    if(titleArray.length == 1){
                        if(titleArray.text().indexOf("已抽奖") >= 0){
                            setTimeout(function () {
                                window.close();//抽奖完毕关闭直播间
                            }, 500);
                        }
                    }else{
                        for(let i of titleArray){
                            if(i.text().indexOf("已抽奖") < 0){
                                return
                            }
                        }
                        window.close();//抽奖完毕关闭直播间
                    }
                }
            } , 100);
            setTimeout(function () {
                if($(".lottery-box .main").length < 0) {
                    window.close();//没有抽奖立即关闭直播间
                }
            }, 7000);
            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 () {
            if ($(".main").length > 0) {
                $(".popup-content-ctnr button").click();
                $(".main").click();
                setTimeout(function () {
                    $(".popup-content-ctnr button").click()
                    console.log('+1')
                }, time_get);
            }
        }, 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;
}
};