自动抢辣条二代by十六夜

功能一:随便打开个直播间自动刷小时榜直播间优点可以抢到舰长等不全区广播的道具缺点占用资源多抢不到小时榜以外的礼物功能二:打开指定直播间https://live.bilibili.com/6498960自动抢全区广播的小电视优点可以抢到所有的小电视缺点只能抢到全区广播的道具注意事项:浏览器不能最小化,保持直播间的显示不要被其他网页盖住,可能导致抢不到功能二进入直播间时会弹出一个百度网页 请允许弹出窗口 请允许弹出窗口 请允许弹出窗口百度页面只是用来方便设置允许弹窗的 可以关闭功能一和二可以一起用 以上

As of 2019-04-16. See the latest version.

// ==UserScript==
// @name         自动抢辣条二代by十六夜
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  功能一:随便打开个直播间自动刷小时榜直播间优点可以抢到舰长等不全区广播的道具缺点占用资源多抢不到小时榜以外的礼物功能二:打开指定直播间https://live.bilibili.com/6498960自动抢全区广播的小电视优点可以抢到所有的小电视缺点只能抢到全区广播的道具注意事项:浏览器不能最小化,保持直播间的显示不要被其他网页盖住,可能导致抢不到功能二进入直播间时会弹出一个百度网页 请允许弹出窗口 请允许弹出窗口 请允许弹出窗口百度页面只是用来方便设置允许弹窗的 可以关闭功能一和二可以一起用 以上
// @author       逆回十六夜
// @match        https://live.bilibili.com/*
// @grant        none
// ==/UserScript==
var time_get = 800;// 点击抽奖的时间间隔单位毫秒
var time_flash = 8000;// 跳转到下个直播间的时间单位毫秒


(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
})(jQuery);

(function() {
    '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
        }
        window.open('https://www.baidu.com' ,'_blank');// 弹窗测试
        setInterval(function (){
            var link = $(".msg-content .link");
            if (link.length > 0) {
                link.each(function(){
                    var link_href = $(this).attr('href');
                    if(link_href){
                        link_href = link_href.split('?')[0];
                        link_href += '?mode=Izayoi';
                        window.open(link_href,'_blank');
                        var mydate = new Date();
                        link.text('辣条已抢~' + mydate.toLocaleString());
                        link.removeAttr('href');
                        link.removeAttr('class');
                    }
                });
            }
        },1000);
        setInterval(function(){
            window.location.reload();
        },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 ($(".main").length > 0) {
                    $(".popup-content-ctnr button").click();
                    $(".main").click();
                    //$('.small-tv-icon-ctnr').click()
                    setTimeout(function () {
                        $(".popup-content-ctnr button").click()
                        console.log('+1')
                    }, time_get);
                }
            }, 500);
            setInterval(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();
                //$('.small-tv-icon-ctnr').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;
        });
    }
})();