自动抢辣条二代by十六夜

我的我的都是我的

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

// ==UserScript==
// @name         自动抢辣条二代by十六夜
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  我的我的都是我的
// @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
        }

        if(!$.getUrlParam('baidu')){
            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(){
            var href=location.href;
            if(href.indexOf('baidu') == -1){
                if(href.indexOf('?')>0){
                    href+='&baidu=off';
                }else{
                    href+='?baidu=off';
                }
            }
            location.href = href;
        },3600000);
    }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){
                if(href.indexOf('&index')>0){
                    href = href.replace(/&index=\d+/,'&index='+nowIndex);
                }else{
                    href = href.replace(/index=\d+/,'index='+nowIndex);
                }
            }else{
                if(href.indexOf('?')>0){
                    href+='&index='+nowIndex;
                }else{
                    href+='?index='+nowIndex;
                }
            }
            //
            location.href = href;
        });
    }
})();