战斗吧歌姬!(天选众版)

Bilibili直播间,小心心、天选时刻、实物抽奖

// ==UserScript==
// @name         战斗吧歌姬!(天选众版)
// @homepage     https://greasyfork.org/zh-CN/scripts/415162
// @version      5.22.30
// @description  Bilibili直播间,小心心、天选时刻、实物抽奖
// @author       风绫丨钰袖
// @iconURL      https://i0.hdslb.com/bfs/article/927cc195124c47474b4a150d8b09e00536d15a0a.gif
// @icon64URL    https://i0.hdslb.com/bfs/article/927cc195124c47474b4a150d8b09e00536d15a0a.gif
// @include      /https?:\/\/live\.bilibili.com/\??.*/
// @include      /https://www.bilibili.com/blackboard/live/\??.*/
// @include      /https://space.bilibili.com/\??.*/
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @connect      passport.bilibili.com
// @connect      api.live.bilibili.com
// @connect      live-trace.bilibili.com
// @connect      sc.ftqq.com
// @require      https://cdn.jsdelivr.net/gh/lzghzr/TampermonkeyJS@55fdb489ce4d3f73c02a4ddec9a6979023b7479c/libBilibiliToken/libBilibiliToken.js
// @require      https://cdn.jsdelivr.net/gh/lzghzr/TampermonkeyJS@fe2340677328762f9d6e9686603e9781d69cd3c9/libWasmHash/libWasmHash.js
// @grant        unsafeWindow
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @grant        GM_openInTab
// @run-at       document-idle
// @license      MIT License
// @namespace http://tampermonkey.net/
// ==/UserScript==

window.onload=(function ZDBGJ_BLRHH_Plus(){
    var guardsListdata=[]//大航海数据
    var guardroom=[]//大航海房间
    var guard_level=[]//大航海等级,3舰长2提督1总督
    var guardroom_activite=[]//生效与否
    var medal_ignore_roomid_list=[];
    var need_medal_roomid=[];
    var readConfig=[];
    var Anchor_ignore_keyword=[];
    var Anchor_ignore_uid=[];
    var Anchor_room_list=[];
    var Anchor_always_room_list=[];//常驻房,收集最近天选房
    var Anchor_award_id_list=[];
    var Anchor_award_name_list=[];
    var Anchor_award_gift_id_list=[];
    var Anchor_award_gift_num_list=[];
    var Anchor_award_nowdate=[];
    var medal_list=[];
    var FollowingList = [];
    var medal_uid_list=[];
    var medal_roomid_list=[];
    var medal_id_list=[];
    var room_exist_check;
    var done_id_list=[];//已抽奖序号id
    var done_room_list=[];//已抽奖序号房号
    var done_room_time_list=[];//已抽奖序号时间标记
    var CZ_delay=0;//抽奖时不刷新
    var webmodle_delay=20;//网页模式延迟
    var updata=[];//上传数据
    var medal_sign=0;//正在签到标记
    let NAME;
    let BAPI;
    let ZBJ;
    let CJ;
    var BPDJ;
    var COUNT;
    var Lcount;//小心心防异常
    let Live_info = {
        room_id: undefined,
        uid: undefined,
        blocked:undefined,
        csrf_token: undefined,
        visit_id: undefined,
        rnd: undefined,
        ruid: undefined,
        uname: undefined,
        user_level:undefined,
        Blever:undefined,
    };
    const month = () =>new Date().getMonth()+1;
    const day = () =>new Date().getDate();
    const hour = () =>new Date().getHours();
    const minute = () =>new Date().getMinutes();
    const tz_offset = () => new Date().getTimezoneOffset() + 480;
    const ts_ms = () => Date.now();
    const ts_s = () => Math.round(ts_ms()/1000);
    const ts_ten_m = () => new Date().getHours()*6+Math.round(new Date().getMinutes()/10)//十分钟误差标记
    const delayCall = (callback, delay = 10e3) => {
        const p = $.Deferred();
        setTimeout(() => {
            const t = callback();
            if (t && t.then) t.then((arg1, arg2, arg3, arg4, arg5, arg6) => p.resolve(arg1, arg2, arg3, arg4, arg5, arg6));
            else p.resolve();
        }, delay);
        return p;
    };
    function Sleep(ms) {
        return new Promise(resolve => setTimeout(() => resolve('sleep'), ms));
    }
    const appToken = new BilibiliToken();
    const baseQuery = `actionKey=appkey&appkey=${BilibiliToken.appKey}&build=5561000&channel=bili&device=android&mobi_app=android&platform=android&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%225.57.0%22%2C%22abtest%22%3A%22%22%7D`;
    let tokenData = JSON.parse(GM_getValue(`${NAME}userToken`, '{}'));
    const setToken = async () => {
        const userToken = await appToken.getToken();
        if (userToken === undefined)
            return console.error(GM_info.script.name, '未获取到token');
        tokenData = userToken;
        GM_setValue(`${NAME}userToken`, JSON.stringify(tokenData));
        return 'OK';
    };
    $(function () {//DOM完毕,等待弹幕加载完成
        document.getElementById("my-dear-haruna-vm").style.display = "none"; //去掉2233 sections-vm
        document.getElementById("sections-vm").style.display = "none"; //去掉直播画面下方内容
        let i=0
        let loadInfo = (delay) => {
            setTimeout(async function () {
                if (BilibiliLive === undefined || parseInt(BilibiliLive.UID) === 0 || isNaN(parseInt(BilibiliLive.UID))) {
                    loadInfo(5000);
                    chatLog('未登录或网络卡顿,请先登录或检查网络!');
                    i +=1
                    if(i>15) {
                        window.location.reload()
                    }
                    //console.log('无配置信息');
                } else {
                    Live_info.room_id = BilibiliLive.ROOMID;
                    Live_info.uid = BilibiliLive.UID;
                    NAME=Live_info.uid;
                    //console.log(Live_info);
                    init();
                    i=0
                }
            }, delay);
        };
        loadInfo(3000);
    });

    Array.prototype.remove = function (val) {
        let index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    function init() {//API初始化
        try {
            BAPI = BilibiliAPI;
        } catch (err) {
            console.error(`[${NAME}]`, err);
            return;
        }
        Live_info.csrf_token = BAPI.getCookie('bili_jct');
        Live_info.visit_id = getvisit_id()
        let getuname=async function() {
            await BAPI.ajax({url:"xlive/web-ucenter/user/get_user_info"}).then(async (data) =>{
                //console.log('getuname',data)
                Live_info.uname = data.data.uname;
                Live_info.user_level= data.data.user_level;
            }, () => {
                return delayCall(() => getuname());
            });
        };
        getuname();
        let getBlever=async function() {
            await BAPI.ajax({url:"//api.bilibili.com/x/web-interface/nav?build=0&mobi_app=web"}).then(async (data) =>{
                //console.log('getBlever',data)
                Live_info.Blever = data.data.level_info.current_level;
            }, () => {
                return delayCall(() => getBlever());
            });
        };
        getBlever()
        console.log('Live_info',Live_info)
        const MY_API = {
            CONFIG_DEFAULT: {
                medal_ignore_roomid_list:[],
                medal_sign_time_hour:16,
                medal_sign_time_min:16,
                GIFT_AUTO:true,
                GIFT_AUTO2:true,
                GIFT_NUM: 1500,
                GIFT_ROOM: 2374828,
                GIFT_NUM2: 24,
                GIFT_ROOM2: 2374828,
                TALK: false,//不显示抽奖反馈
                tu50room:false,
                getroomnum:30,
                TIMEAREADISABLE: true,
                TIMEAREASTART: 2,
                TIMEAREAEND: 6,
                TOProomnum:350,
                gift_price:0,
                Anchor_ignore_keyword:['舰长', '照', '总督', '提督', '一毛', '0.01', '禁言', '0.0','代金','片','通行证','第五人格','抵用'],
                Anchor_ignore_uid:[],
                CZ: 180,
                webmodledelay:1,//检测到参加的天选,打开网页后,暂停检索的延迟
                AnchorFLASH: 50,//天选间隔
                AnchorserverFLASH:8,//获取服务器天选间隔
                AnchorcheckFLASH:150,//检索天选间隔
                Anchor_room_send:0,//手动推送服务器数据房间
                JSMARK:0,//多开标记
                AUTO_BOX: true,//每日硬币
                AUTO_HEART_newmodel: true,
                AUTO_sign_danmu: false,//勋章直播间打卡签到
                AUTO_DailyReward: true,//主站登陆、观看、转发经验获取
                AUTO_lottery_model1: false,//网页模拟方式
                AUTO_lottery_model2: true,//API发送数据模式
                materialobject_ts:0,
                medal_ts:0,
                Anchor_ts:0,
                last_aid:650,
                AUTO_GOLDBOX:false,//金箱子抽奖
                AUTO_Anchor:false,//天选时刻抽奖
                COUNT_GOLDBOX: 0,//天选时刻、金箱子抽奖参与次数
                sever_room:0,//伪服务器直播间
                sever_room1:0,//伪服务器直播间1
                sever_room2:[181601,4017190,11464080,181601,1689584,1643847,3061999,21111267,2216610,8402287,5238625,7657577],//伪服务器直播间2
                switch_sever:false,//伪服务器服务开关
                sever_modle:false,//天选大号小号伪服务器获取模式开关
                switch_sever_room:true,//0伪服务器服务开关
                switch_sever_room1:true,//1伪服务器服务开关
                switch_sever_room2:true,//2伪服务器服务开关
                medal_change:true,
                ServerChan_SCKEY:0,//Server酱微信推送SCKEY
                switch_ServerChan_SCKEY1:false,//运行推送开关
                switch_ServerChan_SCKEY:false,//Server酱微信推送开关
                anchor_danmu:false,//天选中奖发弹幕开关
                anchor_danmu_content:['嘿嘿嘿嘿嘿','hahahahaha'],//中奖弹幕
                sign_danmu_content:['签到','....','看看.','额.','好.','哈哈'],//中奖弹幕
                anchor_msg:false,//天选中奖发私信开关
                anchor_msg_content:['嘿嘿嘿嘿嘿中奖了~~','天选中奖了~~','天选居然中奖了~~'],//中奖私信
                Anchor_Followings_switch:false,
                Anchor_always_room_switch:false,//常驻天选房开关
                Anchor_always_room_num:100,//常驻天选房数量上限
                Anchor_always_room_add:0,//手动加入常驻天选房
                Anchor_room_get:true,//推荐直播间获取、排行榜获取天选房开关
                Anchor_room_get_to_always:true,//推荐直播间获取、排行榜获取天选房开关
            },

            CONFIG: {},
            GIFT_COUNT: {
                COUNT: 0,
                LCOUNT: 0,//小心心数量
                LCOUNT2: 0,//模式2小心心数量
                LOVE_COUNT: 0,
                CLEAR_TS: 0,
                TTCOUNT: 0,
                TTLOVE_COUNT: 0,
                BPJY: 0,
                BPDJ: 1,
                DJLVMK: 100,

            },
            init: async function () {
                try {
                    BAPI.setCommonArgs(BAPI.getCookie('bili_jct'));// 设置token
                } catch (err) {
                    console.error(`[${NAME}]`, err);
                    return;
                }
                let btn4 = $('<button style="position: absolute; top: 0px; left: 0px;z-index:999;background-color:#00B2EE;color:white;border-radius: 4px;border: none;padding: 5px;cursor: pointer;box-shadow: 1px 1px 2px #00000075;">' +
                             '一键购买勋章</button>');
                btn4.click(async function () {
                    await BAPI.live_user.get_anchor_in_room(Live_info.room_id).then(async function (data) {
                        console.log(data)
                        if (data.code === 0) {
                            let ruid = data.data.info.uid
                            let rr=confirm("点击确定,消耗20硬币购买当前房间勋章!");
                            if (rr==true){
                                await BAPI.link_group.buy_medal(ruid).then((dat) => {
                                    console.log(data)
                                    if (dat.code === 0) {
                                        chatLog('【一键购买勋章】成功!');
                                    } else {
                                        chatLog(`【一键购买勋章】${dat.message}!`);
                                    }
                                });
                            }
                        }
                    });
                });
                $('.bottom-actions.p-relative').append(btn4);

                let p = $.Deferred();
                try {
                    MY_API.loadConfig().then(async function () {
                        MY_API.chatLog('正在初始化系统....', 'success');
                        MY_API.chatLog('系统参数配置完成!', 'success');
                        MY_API.chatLog('谁才是天选之子!天选众,来战!', 'success');
                        setTimeout(() => {
                            let l = $("div.checkin-btn.t-center.pointer");
                            if (l.length > 0) {
                                l.click();
                            }
                        }, 1000);
                        setTimeout(() => {
                            let l = $("div.checkin-btn.t-center.pointer");
                            if (l.length > 0) {
                                l.click();
                            }
                        }, 3000);
                        setTimeout(() => {
                            let l = $("div.checkin-btn.t-center.pointer");
                            if (l.length > 0) {
                                l.click();
                            }
                        }, 10000);
                        setTimeout(() => {
                            let l = $("div.checkin-btn.t-center.pointer");
                            if (l.length > 0) {
                                l.click();
                            }
                        }, 100000);
                        let getMedalList=async function(page = 1) {//粉丝勋章数据
                            if (page == 1) medal_list = [];
                            await Sleep(100)
                            return BAPI.Lottery.anchor.medal(page, 25).then((data) => {
                                medal_list = medal_list.concat(data.data.fansMedalList);
                                console.log('勋章房间数据',medal_list);
                                if (data.data.pageinfo.curPage < data.data.pageinfo.totalpages) return getMedalList(page + 1);
                            }, () => {
                                return MY_API.chatLog('获取粉丝勋章数据出错!', 'warning');
                                //delayCall(() => getMedalList());
                            });
                        };
                        let getFollowingList=async function(pn = 1, ps = 50){
                            await Sleep(100)
                            if (pn === 1) FollowingList = [];
                            return BAPI.Lottery.anchor.getFollowings(Live_info.uid, pn, ps).then((response) => {
                                let p = $.Deferred();
                                if (response.code === 0) {
                                    p.resolve();
                                    const total = response.data.total;
                                    for (const up of response.data.list) {
                                        FollowingList.push(up.mid);
                                    }
                                    const remainUp = total - FollowingList.length;
                                    if (remainUp > 0)
                                        return $.when(getFollowingList(pn + 1, ps), p);
                                    else {
                                        return p;
                                    }
                                } else {
                                    return p.reject();
                                }
                            }, () => {
                                return MY_API.chatLog('获取关注数据出错!', 'warning');
                                //delayCall(() => getFollowingList());
                            })
                        }
                        MY_API.chatLog('正在初始化勋章等数据...', 'success');
                        if (MY_API.CONFIG.medal_ts==0 | ts_ms() - MY_API.CONFIG.medal_ts > 6*60e3) {//
                            MY_API.CONFIG.medal_ts = ts_ms()
                            MY_API.GsaveConfig();
                            await getMedalList();
                            console.log('勋章房间数据',medal_list);
                            for (let i=0;i<medal_list.length;i++) {
                                medal_uid_list[i]=medal_list[i].target_id
                            }
                            console.log('勋章uid列表',medal_uid_list);
                            for (let i=0;i<medal_list.length;i++) {
                                medal_id_list[i]=medal_list[i].medal_id
                            }
                            for (let i=0;i<medal_list.length;i++) {
                                await Sleep(20)
                                await BAPI.room.get_info(medal_list[i].roomid).then(async (data) =>{
                                    medal_roomid_list[i]=data.data.room_id
                                    console.log('勋章roomid列表',medal_roomid_list);
                                })
                            }
                            console.log('勋章roomid列表',medal_roomid_list);
                            if(MY_API.CONFIG.Anchor_Followings_switch){
                                await getFollowingList();
                                console.log('关注uid列表',FollowingList);
                            }
                            try {
                                localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                            } catch (e) {
                                localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                            }
                            try {
                                localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                            } catch (e) {
                                localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                            }
                            try {
                                localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                            } catch (e) {
                                localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                            }
                            try {
                                localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                            } catch (e) {
                                localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                            }
                        }
                        if(MY_API.CONFIG.medal_change & medal_id_list.length>0 & medal_roomid_list.indexOf(Live_info.room_id)>-1){
                            let nu= medal_roomid_list.indexOf(Live_info.room_id)
                            BAPI.wear_medal(medal_id_list[nu]).then(async (data) =>{
                                console.log('medal_id_list',data)
                                chatLog(`【自动更换勋章】${data.message}`);
                            })
                        }
                        p.resolve();
                    });
                } catch (e) {
                    //console.log('API初始化出错', e);
                    MY_API.chatLog('系统初始化出错', 'warning');
                    p.reject()
                }
                return p
            },

            loadConfig: function () {
                let p = $.Deferred();
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_CONFIG`));
                    $.extend(true, MY_API.CONFIG, MY_API.CONFIG_DEFAULT);
                    for (let item in MY_API.CONFIG) {
                        if (!MY_API.CONFIG.hasOwnProperty(item)) continue;
                        if (config[item] !== undefined && config[item] !== null) MY_API.CONFIG[item] = config[item];
                    }
                    MY_API.loadGiftCount();//载入礼物统计
                    p.resolve()
                } catch (e) {
                    //console.log('API载入配置失败,加载默认配置', e);
                    MY_API.setDefaults();
                    p.reject()
                };
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_done_list`));
                    done_id_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                };

                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_done_room_list`));
                    done_room_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_done_room_time_list`));
                    done_room_time_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                }//
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_updata`));
                    updata = [].concat(config.id);
                    localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_always_room_list`));
                    Anchor_always_room_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_need_medal_roomid`));
                    need_medal_roomid = [].concat(config.id);
                    localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_medal_uid_list`));
                    medal_uid_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_medal_roomid_list`));
                    medal_roomid_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_medal_id_list`));
                    medal_id_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_medal_id_list`));
                    medal_id_list = [].concat(config.id);
                    localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_guardroom`));
                    guardroom = [].concat(config.id);
                    localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_guard_level`));
                    guard_level = [].concat(config.id);
                    localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                }
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_guardroom_activite`));
                    guardroom_activite = [].concat(config.id);
                    localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                }
                return p
            },
            saveConfig: function () {
                try {
                    localStorage.setItem(`${NAME}_CONFIG`, JSON.stringify(MY_API.CONFIG));
                    MY_API.chatLog('配置已保存');
                    //     //console.log(MY_API.CONFIG);
                    return true
                } catch (e) {
                    console.log('API保存出错', e);
                    return false
                }
            },
            GsaveConfig: function () {
                try {
                    localStorage.setItem(`${NAME}_CONFIG`, JSON.stringify(MY_API.CONFIG));
                    $('#COUNT_GOLDBOX span:eq(0)').text(MY_API.CONFIG.COUNT_GOLDBOX);
                    $('#giftCoun span:eq(0)').text(MY_API.CONFIG.COUNT_GOLDBOX);
                    return true
                } catch (e) {
                    //console.log('API保存出错', e);
                    return false
                }
            },
            setDefaults: function () {
                MY_API.CONFIG = MY_API.CONFIG_DEFAULT;
                MY_API.GsaveConfig();
                MY_API.chatLog(`天选众代号:${NAME}<br/>你好!欢迎来到白嫖怪的修仙世界!`);
                MY_API.chatLog(`未检测到帐号信息,正在创建帐号......`, 'warning');
                MY_API.chatLog(`帐号创建完成,5秒后重新登陆系统!`, 'warning');
                setTimeout(() => {
                    window.location.reload()
                }, 5000);
            },
            loadGiftCount: function () {
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_GIFT_COUNT`));
                    for (let item in MY_API.GIFT_COUNT) {
                        if (!MY_API.GIFT_COUNT.hasOwnProperty(item)) continue;
                        if (config[item] !== undefined && config[item] !== null) MY_API.GIFT_COUNT[item] = config[item];
                    }
                    BPDJ=MY_API.GIFT_COUNT.BPDJ;
                    COUNT=MY_API.GIFT_COUNT.COUNT;
                    MY_API.cjcheck();
                } catch (e) {
                    //console.log('读取统计失败', e);
                }
            },
            saveGiftCount: function () {
                try {
                    localStorage.setItem(`${NAME}_GIFT_COUNT`, JSON.stringify(MY_API.GIFT_COUNT));
                    //console.log('统计保存成功', MY_API.GIFT_COUNT);
                    BPDJ=MY_API.GIFT_COUNT.BPDJ;
                    COUNT=MY_API.GIFT_COUNT.COUNT;
                    return true
                } catch (e) {
                    //console.log('统计保存出错', e);
                    return false
                }
            },

            cjcheck: function () {
                if (MY_API.GIFT_COUNT.BPDJ<100) {
                    CJ='筑基白嫖怪';
                } else if(MY_API.GIFT_COUNT.BPDJ<200){
                    CJ='旋照白嫖怪'
                } else if(MY_API.GIFT_COUNT.BPDJ<300){
                    CJ='辟谷白嫖怪'
                } else if(MY_API.GIFT_COUNT.BPDJ<400){
                    CJ='结丹白嫖怪'
                } else if(MY_API.GIFT_COUNT.BPDJ<500){
                    CJ='元婴白嫖怪'
                } else if(MY_API.GIFT_COUNT.BPDJ<600){
                    CJ='出窍白嫖怪'
                } else if(MY_API.GIFT_COUNT.BPDJ<700){
                    CJ='分神白嫖怪';
                } else if(MY_API.GIFT_COUNT.BPDJ<800){
                    CJ='合体白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<900){
                    CJ='渡劫白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<1000){
                    CJ='大乘白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<2000){
                    CJ='仙人白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<5000){
                    CJ='地仙白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<10000){
                    CJ='天仙白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<20000){
                    CJ='玄仙白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<30000){
                    CJ='神境白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<40000){
                    CJ='神人白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<60000){
                    CJ='准神白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<80000){
                    CJ='主神白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<100000){
                    CJ='神王白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<200000){
                    CJ='天尊白嫖怪'
                }else if(MY_API.GIFT_COUNT.BPDJ<300000){
                    CJ='天尊白嫖怪一重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<400000){
                    CJ='天尊白嫖怪二重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<500000){
                    CJ='天尊白嫖怪三重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<600000){
                    CJ='天尊白嫖怪四重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<700000){
                    CJ='天尊白嫖怪五重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<800000){
                    CJ='天尊白嫖怪六重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<900000){
                    CJ='天尊白嫖怪七重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<1000000){
                    CJ='天尊白嫖怪八重天'
                }else if(MY_API.GIFT_COUNT.BPDJ<2000000){
                    CJ='天尊白嫖怪九重天'
                }else if(MY_API.GIFT_COUNT.BPDJ>=2000000){
                    CJ='天尊白嫖怪大圆满'
                };
            },
            expaddGift: function (count) {
                count=20+Math.ceil(Math.random() * 20)
                MY_API.GIFT_COUNT.COUNT += count;
                MY_API.GIFT_COUNT.TTCOUNT+= count;
                let BPJY=MY_API.GIFT_COUNT.BPJY
                MY_API.GIFT_COUNT.BPJY += count*4;
                if (MY_API.GIFT_COUNT.BPJY >= MY_API.GIFT_COUNT.DJLVMK && BPJY < MY_API.GIFT_COUNT.DJLVMK ) {
                    MY_API.GIFT_COUNT.BPDJ +=1;
                    MY_API.cjcheck();
                    MY_API.GIFT_COUNT.DJLVMK +=1000
                    //MY_API.chatLog('恭喜你升级了ヾ(o◕∀◕)ノヾ');
                }
                $('#TTgiftCount span:eq(0)').text(MY_API.GIFT_COUNT.TTCOUNT);
                $('#giftCount span:eq(2)').text(MY_API.GIFT_COUNT.COUNT);
                $('#CJ span:eq()').text(CJ);
                $('#BPJY span:eq(0)').text(MY_API.GIFT_COUNT.BPJY);
                $('#BPJY span:eq(1)').text(MY_API.GIFT_COUNT.BPDJ);
                $('#clockgift span:eq(0)').text(MY_API.GIFT_COUNT.COUNT);
                MY_API.saveGiftCount();
            },
            expaddLove: function (count) {
                count=10+Math.ceil(Math.random() * 20)
                MY_API.GIFT_COUNT.LOVE_COUNT += count;
                MY_API.GIFT_COUNT.TTLOVE_COUNT += count;
                let BPJY=MY_API.GIFT_COUNT.BPJY
                MY_API.GIFT_COUNT.BPJY += count*6;
                if (MY_API.GIFT_COUNT.BPJY >= MY_API.GIFT_COUNT.DJLVMK && BPJY < MY_API.GIFT_COUNT.DJLVMK ) {
                    MY_API.GIFT_COUNT.BPDJ +=1;
                    MY_API.cjcheck();
                    MY_API.GIFT_COUNT.DJLVMK +=1000
                    //MY_API.chatLog('恭喜你升级了ヾ(o◕∀◕)ノヾ');
                }
                $('#TTgiftCount span:eq(1)').text(MY_API.GIFT_COUNT.TTLOVE_COUNT);
                $('#giftCount span:eq(3)').text(MY_API.GIFT_COUNT.LOVE_COUNT);
                $('#giftCoun span:eq(1)').text(MY_API.GIFT_COUNT.LOVE_COUNT);
                $('#BPJY span:eq(0)').text(MY_API.GIFT_COUNT.BPJY);
                $('#BPJY span:eq(1)').text(MY_API.GIFT_COUNT.BPDJ);
                MY_API.saveGiftCount();
            },

            creatSetBox: function () {//创建设置框
                let btn1 = $('<button style="position: absolute; top: 132px; left: 0;z-index: 1;background-color: pink;color: #FF34B3;border-radius: 4px;border: none;padding: 5px;cursor: pointer;box-shadow: 1px 1px 2px #00000075;">' +
                             '隐藏插件参数界面</button>');
                btn1.click(function () {
                    div.css({
                        'z-index': '-1',
                    });
                    tj.css({
                        'z-index': '-1',
                    });
                    ohb.css({
                        'z-index': '-1',
                    });
                    tp.css({
                        'z-index': '-1',
                    });
                    goldbox.css({
                        'z-index': '-1',
                    });
                    call.css({
                        'z-index': '-1',
                    });
                    call2.css({
                        'z-index': '-1',
                    });
                    msg.css({
                        'z-index': '10',
                    });

                });
                $('.chat-history-panel').append(btn1);
                let btn2 = $('<button style="position: absolute; top: 156px; left: 0;z-index:1;background-color:yellow;color: #FF34B3;border-radius: 4px;border: none;padding: 5px;cursor: pointer;box-shadow: 1px 1px 2px #00000075;">' +
                             '显示插件参数界面</button>');
                btn2.click(function () {
                    div.css({
                        'z-index': '10',
                    });
                    tj.css({
                        'z-index': '10',
                    });
                    ohb.css({
                        'z-index': '10',
                    });
                    tp.css({
                        'z-index': '12',
                    });
                    goldbox.css({
                        'z-index': '11',
                    });
                    call.css({
                        'z-index': '11',
                    });
                    call2.css({
                        'z-index': '11',
                    });
                    msg.css({
                        'z-index': '-1',
                    });
                });
                $('.chat-history-panel').append(btn2);

                let btn3 = $('<button style="position: absolute; top: 179px; left: 0;z-index:1;background-color:purple;color: #FF34B3;border-radius: 4px;border: none;padding: 5px;cursor: pointer;box-shadow: 1px 1px 2px #00000075;">' +
                             '清空抽奖反馈信息</button>');
                btn3.click(function () {
                    $('.zdbgjMsg').hide();
                });
                $('.chat-history-panel').append(btn3);
                let msg = $("<div>");
                msg.css({
                    'width': '99px',
                    'height': '15px',
                    'position': 'absolute',
                    'top': '202px',
                    'left': '0px',
                    'background': '#00FFFF',
                    'padding': '4px',
                    'z-index': '10',
                    'border-radius': '4px',
                    'transition': 'height .3s',
                    'overflow': 'hidden',
                });
                msg.append(`
<div id="giftCoun" style="font-size: x-small;color:blue;">
天选:<span>${MY_API.CONFIG.COUNT_GOLDBOX}</span>
`);
                var widthmax,heightmax;
                widthmax= $('.bilibili-live-player-video-area').width()-50;
                heightmax= $('.bilibili-live-player-video-area').height()-50;
                let div = $('<div>');
                div.css({
                    'width': '330px',
                    'height': '630px',
                    'max-height':`${heightmax}px`,
                    'position': 'absolute',
                    'top': '10px',
                    'right': '10px',
                    'background': 'rgba(255,255,255,.8)',
                    'padding': '10px',
                    'z-index': '-1',
                    'border-radius': '12px',
                    'transition': 'height .3s',
                    'overflow': 'auto',
                    'line-height': '15px'
                });

                let tj = $('<div>');
                tj.css({
                    'width': '220px',
                    'height': '630px',
                    'max-height':`${heightmax}px`,
                    'position': 'absolute',
                    'top': '10px',
                    'right': '365px',
                    'background': 'rgba(255,255,255,.8)',
                    'padding': '10px',
                    'z-index': '-1',
                    'border-radius': '12px',
                    'transition': 'height .3s',
                    'overflow': 'auto',
                    'line-height': '15px',
                });

                tj.append(`
<fieldset>
<legend  style="font-size: x-small;color:#FF34B3;" title="关注我,升职加薪不秃头!获得女神阿库娅的祝福!幸运值+++!把把SSR+++!">【天选功能主要参数设置】</legend> </div>
<div data-toggle="AUTO_GOLDBOX">
<apend style="font-size: x-small; color: #FF34B3" title="一个关注,即可自动白嫖金宝箱实物抽奖,主要是各种厂商官方活动抽奖">
<input style="vertical-align: text-top;" type="checkbox" >自动实物宝箱抽奖
</div>
<div data-toggle="AUTO_Anchor">
<apend style="font-size: x-small; color: #FF34B3" title="一个关注,即可自动白嫖天选时刻,参加其他请手动点击蓝字直播间链接前往直播间">
<input style="vertical-align: text-top;" type="checkbox" >自动天选时刻抽奖</div>

<div id="COUNT_GOLDBOX" style="font-size: x-small;color:#FF34B3;">
已参加实物/天选:<span>${MY_API.CONFIG.COUNT_GOLDBOX}</span>次</div>
<apend style="font-size: x-small;color:#FF34B3;">点击查看中奖
<a target="_blank" href="https://link.bilibili.com/p/center/index#/user-center/my-info/award"><button title="以实际为准,可点击查看中奖纪录"  style="font-size: x-small;color:#FF34B3;">实物</button></a>
<a target="_blank" href="https://link.bilibili.com/p/center/index#/user-center/my-info/celestial"><button title="以实际为准,可点击查看中奖纪录"  style="font-size: x-small;color:#FF34B3;">天选</button></a></div>

<div data-toggle="medal_change">
<apend style="font-size: x-small; color:  #FF34B3" title="自动更换粉丝勋章">
<input style="vertical-align: text-top;" type="checkbox" >
自动更换粉丝勋章</div>

<div data-toggle="ServerChan_SCKEY1">
<apend style="font-size: x-small; color:  #FF34B3" title="Server酱微信推送运行消息">
<input style="vertical-align: text-top;" type="checkbox" >
运行提醒微信推送</div>


<div data-toggle="ServerChan_SCKEY">
<apend style="font-size: x-small; color:  #FF34B3" title="Server酱微信推送中奖消息">
<input style="vertical-align: text-top;" type="checkbox" >
中奖信息微信推送<br/><input class="num" style="width:91px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button>
<a target="_blank" href="https://www.bilibili.com/video/BV1Et4y1v79Y"><button title="Server酱:http://sc.ftqq.com/3.version,填写SCKEY,保存"  style="font-size: x-small;color:#FF34B3;">教程</button></a></div>

<div data-toggle="anchor_danmu_content">
<apend style="font-size: x-small; color:  #FF34B3" title="中奖自动发送随机弹幕,英文逗号隔开">
<input style="vertical-align: text-top;" type="checkbox" >
中奖后自动发送随机弹幕<br/><input class="num" style="width:124px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="anchor_msg_content">
<apend style="font-size: x-small; color:  #FF34B3" title="中奖自动发送随机私信,英文逗号隔开">
<input style="vertical-align: text-top;" type="checkbox" >
中奖后自动发送随机私信<br/><input class="num" style="width:124px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="sign_danmu_content">
<apend style="font-size: x-small; color:  #FF34B3" title="新一天发送随机签到弹幕,英文逗号隔开">
新一天发送随机签到弹幕<br/><input class="num" style="width:124px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

</fieldset>

<fieldset>
<legend  style="font-size: x-small;color:#FF34B3;">【按分组列表一键取关】</legend>
<apend id="guanzhu" style="font-size: x-small;color: #FF34B3">
<a target="_blank" href="https://space.bilibili.com/${Live_info.uid}/fans/follow"><button style="font-size: x-small;color: #FF34B3" title="点击前往取关">点击前往一键取关界面!</button></a></div><br/>
<apend style="font-size: x-small;color: blue">注:请尽量支持关注主播!</div>
</fieldset>

<fieldset>
<legend  style="font-size: x-small;color:#FF34B3;">【天选时刻过滤规则设置】</legend></div>

<div data-toggle="switch_sever">
<apend style="font-size: x-small; color: #FF34B3" title="开启直播间伪服务器推送需要有直播间,正常天选无影响并且需要开启,非本号本直播间无法开启且不会生效服务器功能,同一IP各号脚本共只可开启一个,否则容易被风控访问拒绝!">
<input style="vertical-align: text-top;" type="checkbox" >开启天选检索并尝试推送</div>

<div data-toggle="Anchor_Followings_switch">
<apend style="font-size: x-small; color: #FF34B3" title=开启后只参与关注的主播的抽奖!">
<input style="vertical-align: text-top;" type="checkbox" >仅参与关注的主播的抽奖</div>

<div data-toggle="sever_modle">
<apend style="font-size: x-small; color: #FF34B3" title="启用蹭服务器天选房模式!">
<input style="vertical-align: text-top;" type="checkbox" >启用蹭服务器天选房模式</div>

<div data-toggle="sever_room">
<apend style="font-size: x-small; color:  #FF34B3" title="0号伪服务器直播间房间号">
<input style="vertical-align: text-top;" type="checkbox" >
0号房:<input class="num" style="width:60px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="sever_room1">
<apend style="font-size: x-small; color:  #FF34B3" title="1号伪服务器直播间房间号">
<input style="vertical-align: text-top;" type="checkbox" >
1号房:<input class="num" style="width:60px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="sever_room2">
<apend style="font-size: x-small; color:  #FF34B3" title="2号伪服务器直播间房间号,30分钟数据更新则更换,英文逗号【,】隔开。">
<input style="vertical-align: text-top;" type="checkbox" >
2号房:自动更换列表
<input class="num" style="width:126px;vertical-align: top;" type="text"><button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>


<div data-toggle="TOProomnum">
<apend style="font-size: x-small; color:  #FF34B3" title="范围:200-1000,房间上限过大,可能会造成巡查周期过长,漏掉天选,房间上限过小也可能漏掉!">
循检房间上限:<input class="num" style="width: 32px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="gift_price">
<apend style="font-size: x-small; color:  #FF34B3" title="理性消费">
金瓜子上限值:<input class="num" style="width: 32px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="Anchor_ignore_keyword">
<apend style="font-size: x-small;color: #FF34B3" title="没兴趣的奖品或者无法达到的限制条件,可以按格式加进去,注意是英文逗号!">
奖品及限制条件关键词<button data-action="save" style="font-size: x-small;color: #FF34B3">保存</button><input class="keyword" style="width: 156px;vertical-align: top;" type="text">
</div>

<div data-toggle="Anchor_ignore_uid">
<apend style="font-size: x-small;color: #FF34B3" title="主播黑名单,可以按格式加进去,注意是英文逗号!">
直播间房间号屏蔽列表<button data-action="save" style="font-size: x-small;color: #FF34B3">保存</button><input class="keyword" style="width: 156px;vertical-align: top;" type="text">
</div>

<div data-toggle="need_medal_roomid">
<apend style="font-size: x-small;color: #FF34B3" title="显示勋章抽奖直播间房号!">
显示勋章抽奖直播间号<button data-action="save" style="font-size: x-small;color: #FF34B3">显示</button>
</div>

<apend style="font-size: x-small;color: blue">注:只参与一次一键参与!</div>

</fieldset>
`);
                let tp = $('<div>');//立牌
                tp.css({
                    'position': 'absolute',
                    'top': '45px',
                    'right': '30px',
                    'z-index': '-1',
                    'overflow': 'hidden',
                });
                tp.append(`
<img id="img1" src="https://i0.hdslb.com/bfs/article/18e41e6720042647581bca0b24b86082e995f5be.png@1320w_2198h.webp" width="128" height="215" title="李清歌" />
`);

                let goldbox = $('<div>');//樱花树
                goldbox.css({
                    'position': 'absolute',
                    'top': '-20px',
                    'right': '-90px',
                    'z-index': '-1',
                    'opacity':'0.6'
                });
                goldbox.append(`
<img id="box" src="https://i0.hdslb.com/bfs/article/e4b3adf0f63abb240da2f9da72b9a3dc86277b6c.gif" width="288" height="288"/>
`);
                let call = $('<div>');//打call
                call.css({
                    'position': 'absolute',
                    'top': '188px',
                    'right': '100px',
                    'z-index': '-1',
                    'transform':'rotateY(180deg)',
                });
                call.append(`
<img id="box" src="https://i0.hdslb.com/bfs/article/927cc195124c47474b4a150d8b09e00536d15a0a.gif" width="56" height="56"/>
`);
                let call2 = $('<div>');//打call
                call2.css({
                    'position': 'absolute',
                    'top': '188px',
                    'right': '20px',
                    'z-index': '-1',
                });
                call2.append(`
<img id="box" src="https://i0.hdslb.com/bfs/article/927cc195124c47474b4a150d8b09e00536d15a0a.gif" width="56" height="56"/>
`);


                let tpp = $("<div class='zdbgjtpp'>");//海报
                tpp.css({
                    'position': 'absolute',
                    'z-index': '-99',
                    'overflow': 'hidden',
                });

                tpp.append(`

<img id="img2" src="https://i0.hdslb.com/bfs/article/2dc43fa70b7ee108787716f3003691fe9fe8876f.png@1320w_742h.webp" />

`);

                let TP_Timer = () => {
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/10aca7fbe5247b1f217763a12afa0012d988d311.png@1320w_2198h.webp";
                        img.title="神宫司玉藻"
                    }, 5000);
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/fe789e3af417418ad8c0a4e03ba40867dba0c55f.png@1320w_2198h.webp";
                        img.title="罗兹·巴蕾特"
                    }, 10000);
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/69468feeb1263f7653adf2bc0e3379d32ad71ac3.png@1320w_2198h.webp";
                        img.title="伊莎贝拉·霍利"
                    }, 15000);
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/1986b954aff538dc8b18ca1cc29e9eccc49df4fc.png@1320w_2198h.webp";
                        img.title="卡缇娅·乌拉诺娃"
                    }, 20000);
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/fce8ebfb187e0f979da10bd32e9e912da9535dd4.png@1320w_2198h.webp";
                        img.title="墨汐"
                    }, 25000);
                    setTimeout(() => {
                        var img = document.getElementById("img1")
                        img.src = "https://i0.hdslb.com/bfs/article/18e41e6720042647581bca0b24b86082e995f5be.png@1320w_2198h.webp";
                        img.title="李清歌"
                    }, 30000);
                };
                TP_Timer();
                setInterval(TP_Timer, 30e3);

                let TPP_Timer = () => {
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/17b1da8162347cd24d8d18a90d3c65962bf63116.png@1320w_742h.webp";
                    }, 5000);
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/0f12ac73dad762c00797c689bccafe42b99219c4.png@1320w_742h.webp";
                    }, 10000);
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/6a7b6b232036ecadc221e7a741c9910273782081.png@1320w_742h.webp";
                    }, 15000);
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/8f79f9c1f1f7a6698a27d423db22e263d09ed179.png@1320w_742h.webp";
                    }, 20000);
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/5fe092b5c2c32c3363dd447ac9b71b97d9606684.png@1320w_742h.webp";
                    }, 25000);
                    setTimeout(() => {
                        var img = document.getElementById("img2")
                        img.src = "https://i0.hdslb.com/bfs/article/1b709eed8bd104d2429cf294be6e7e5448a45e47.png@1320w_742h.webp";
                    }, 30000);
                };
                TPP_Timer();
                setInterval(TPP_Timer, 30e3);

                let tppp = $("<div class='zdbgjtppp'>");  //nice
                tppp.css({
                    'position': 'absolute',
                    'top': '200px',
                    'right': '160px',
                    'z-index': '-1',
                    'overflow': 'hidden',
                });
                let tpppp = $("<div class='zdbgjtpppp'>");///虚拟小电视
                tpppp.css({
                    'position': 'Absolute',
                    'top': '-170px',
                    'right': '10px',
                    'z-index': '-1111',
                });
                tpppp.append(`
<img id="img4" src="https://i0.hdslb.com/bfs/live/746a8db0702740ec63106581825667ae525bb11a.gif"/>
`);
                tppp.append(`
<img id="img3" src="https://i0.hdslb.com/bfs/article/5546414a3be8e3fd8fb79829b438567e99c9e53e.gif" width="90" height="90" />

`);

                let ohb = $("<div class='ohb'>");//欧皇榜
                ohb.css({
                    'width': '300px',
                    'height': '630px',
                    'max-height':`${heightmax}px`,
                    'position': 'absolute',
                    'top': '10px',
                    'right': '610px',
                    'background': 'rgba(255,255,255,.8)',
                    'padding': '10px',
                    'z-index': '-1',
                    'border-radius': '12px',
                    'transition': 'height .3s',
                    'overflow': 'auto',
                    'line-height': '16px'
                });

                ohb.append(`
<fieldset>
<legend append style="font-size: x-small;color: #FF34B3;text-align: left;"><span>天选众欧皇前十榜</legend> </div>
<div  id="ohb" style="font-size: x-small;color:#FF34B3;">
<append title="太平鸟红双喜联名大礼包、人设钥匙扣、PIERRE巧克力、罗技耳机、枪火重生兑换码x2、小电视披风、战斗吧歌姬二周年鼠标垫、天选中奖等等">1、十年轻音:估2818元,小电视披风等!<br/>
<append title="联想平板等">2、枔殇:估1688元,联想平板等!<br/>
<append title="Keeppley大礼包等">3、守护:估1035元,Keeppley大礼包等!<br/>
<append title="PIERRE巧克力*2等">4、自由:估1028元,PIERRE巧克力*2等!<br/>
<append title="比利时零食大礼包、天选66、60、50、50等">5、荒年:估700元,比利时零食大礼包等!<br/>
<append title="安踏羽绒服">6、重生:估699元,安踏羽绒服!<br/>
<append title="安踏羽绒服">7、':估699元,安踏羽绒服!<br/>
<append title="肯德基玩心宇宙超玩大礼包、小黄人陶瓷杯、团兔玩偶等">8、雀啄:估570元,肯德基玩心宇宙超玩大礼包等!<br/>
<append title="PIERRE巧克力">9、烟花:估514元,PIERRE巧克力!<br/>
<append title="PIERRE巧克力">10、天选来客:估514元,PIERRE巧克力!<br/>
注:如果中奖,欢迎加群告知进榜或吸欧气,群内大量欧皇。</div>
</fieldset>
<fieldset>
<legend append style="font-size: x-small;color: #FF34B3;text-align: left;"><span>支付宝、微信打赏作者!感谢您的支持!</legend> </div>
<img id="img3" src="https://greasyfork.org/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbzFhIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--c0650e78c3190c96f9adc16b886616b032080457/%E5%BE%AE%E4%BF%A1.png?locale=zh-CN" width="100" height="100" />
<img id="img4" src="https://greasyfork.org/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbzVhIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--685416a40a02029793767afee0f403d106172cbf/%E6%94%AF%E4%BB%98%E5%AE%9D.jpg?locale=zh-CN" width="100" height="100" />
</fieldset>

<fieldset>
<legend append style="font-size: x-small;color: #FF34B3;text-align: left;"><span>配置参数操作界面</legend> </div>
<button data-action="exportConfig" style="font-size: x-small;color: red" title="导出配置按钮">导出配置参数</button>
<button data-action="importConfig" style="font-size: x-small;color: red" title="导入配置按钮">导入配置参数</button>
<input type="file" id="ZDBGJ_config_file" name="json" accept=".json" >

</fieldset>
`);

                ohb.find('button[data-action="exportConfig"]').click(() => {//导出配置按钮
                    downFile('ZDBGJ_CONFIG.json', MY_API.CONFIG);
                    MY_API.chatLog('配置已导出');
                });
                ohb.find('button[data-action="importConfig"]').click(() => {//导入配置按钮
                    let selectedFile = document.getElementById("ZDBGJ_config_file").files[0];
                    let reader = new FileReader();
                    reader.readAsText(selectedFile);
                    reader.onload = function () {
                        try {
                            readConfig = JSON.parse(this.result);
                            let p = $.Deferred();
                            try {
                                let config = readConfig;
                                $.extend(true, MY_API.CONFIG, readConfig);
                                for (let item in MY_API.CONFIG) {
                                    if (!MY_API.CONFIG.hasOwnProperty(item)) continue;
                                    if (config[item] !== undefined && config[item] !== null) MY_API.CONFIG[item] = config[item];
                                }
                                p.resolve()
                            } catch (e) {
                                p.reject()
                            };

                            console.log('importConfig:', readConfig);
                        } catch (e) {
                            console.log('importConfig error:', e);
                            return alert('文件格式错误')
                        }
                    };
                    alert('配置导入成功,点击确定刷新页面');
                    //setTimeout(() => {
                    window.location.reload()
                    //}, 5000);

                });


                div.append(`
<fieldset>
<legend append style="font-size: x-small;color: #FF34B3;text-align: left;">欢迎来到<span>${ZBJ}</span>的直播间</legend> </div>
<div id="giftCount" style="font-size: x-small;color:  green;">
<span>${month()}</span>月<span>${day()}</span>日&nbsp;&nbsp;&nbsp修仙指数:<span>${MY_API.GIFT_COUNT.COUNT}</div>
</fieldset>

<fieldset>
<legend id="CJ" style="font-size: x-small;color: #FF34B3;text-align: left;">我欲成仙丨快乐无边【<span>${CJ}</span>】</legend></div>
<div id="TTgiftCount" style="font-size: x-small;color:  green;">
<div>攻击:<span>${MY_API.GIFT_COUNT.TTCOUNT}</span>&nbsp;&nbsp;
防御:<span>${MY_API.GIFT_COUNT.TTLOVE_COUNT}</span></div>

<div id="BPJY" style="font-size: x-small;color:  green;">
<div>经验:<span>${MY_API.GIFT_COUNT.BPJY}</span>&nbsp;&nbsp;
等级:Lv<span>${MY_API.GIFT_COUNT.BPDJ}</span></div>
</fieldset>

<fieldset>
<legend append style="font-size: x-small;color: #FF34B3">修仙插件参数设置</legend></div>
<div><a target="_blank" href="${GM_info.script.homepage}"><button style="font-size: x-small;color: red" title="点击安装最新脚本">脚本更新!</button></a>
<a target="_blank" href="https://shang.qq.com/wpa/qunwpa?idkey=6a64d45dd58c63491c2c9a1da8aa3a0b94c09c4eee576ed601b8094b6bf44eb8"><button style="font-size: x-small;color: red" title="点击加入QQ交流群:746790091">加入扣群!</button></a></div>
<apend id="giftCountsent">
<div><button data-action="countsent" style="font-size: x-small;color: red" title="点击发送修仙等级、指数弹幕">低调使用!</button>
<button data-action="countsentt" style="font-size: x-small;color: red" title="NICE!!!">闷声发财!</button></div>

<div data-toggle="TALK">
<input style="vertical-align: text-top;" type="checkbox" ><append style="font-size: x-small;color: Orange">隐藏抽奖等反馈信息</div>

<div data-toggle="AUTO_BOX">
<apend style="font-size: x-small; color: Orange">
<input style="vertical-align: text-top;" type="checkbox">自动银瓜子兑换硬币</div>

<div data-toggle="AUTO_DailyReward">
<apend style="font-size: x-small; color: Orange" title="获取主站登陆、观看、转发(不显示在动态)经验">
<input style="vertical-align: text-top;" type="checkbox" title="获取主站登陆、观看、转发(不显示在动态)经验">主站登陆观看及转发</div>

<div data-toggle="AUTO_HEART_newmodel">
<apend style="font-size: x-small; color: Orange" title="不占网络内存,加速倍率与勋章数有关,手机端可能无效">
<input style="vertical-align: text-top;" type="checkbox" title="新模式,不占网络内存,加速倍率与勋章数有关,手机端可能无效">自动加速领取小心心</div>

<div data-toggle="AUTO_sign_danmu">
<apend style="font-size: x-small; color: #FF34B3" title="自动发送签到弹幕到勋章房">
<input style="vertical-align: text-top;" type="checkbox" title="自动发送签到弹幕">定时勋章签到
<button data-action="save" style="font-size: x-small;color: #FF34B3">立即签到</button></div>

<div data-toggle="AUTO_sign_time">
<apend style="font-size: x-small; color: #FF34B3" title="自动发送签到弹幕到勋章房">
定时:<input class="hour" style="width:19px;vertical-align: top;" type="text">点
<input class="min" style="width:19px;vertical-align: top;" type="text">分
<button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>


<div data-toggle="medal_ignore_roomid_list">
<apend style="font-size: x-small; color:  #FF34B3" title="勋章签到黑名单,英文逗号【,】隔开。">
勋章房间黑名单:
<input class="num" style="width:126px;vertical-align: top;" type="text"><button data-action="save" style="font-size: x-small;color:  #FF34B3">保存</button></div>

<div data-toggle="AUTO_lottery_model1">
<apend style="font-size: x-small; color: Orange" title="参与抽奖模式一::网页模拟点击,降低黑屋风险">
<input style="vertical-align: text-top;" type="radio" name="AUTO_lottery_model"  title="参与抽奖模式一:网页模拟点击,降低黑屋风险">参与抽奖模式一:网页模拟点击</div>
<div data-toggle="AUTO_lottery_model2">
<apend style="font-size: x-small; color: Orange" title="参与抽奖模式二:直接发送数据,可能黑屋风险较大,手机端可使用该方式,建议屏蔽词加入粉丝勋章">
<input style="vertical-align: text-top;" type="radio" name="AUTO_lottery_model"  title="参与抽奖模式二:直接发送数据,可能黑屋风险较大,手机端可使用改方式,建议屏蔽词加入粉丝勋章">参与抽奖模式二:直接发送数据</div>

<div data-toggle="webmodledelay" title="范围:0-100">
<append style="font-size: x-small;color: Orange" ><data-toggle="webmodledelay" title="检测到可参与的天选房间后打开网页,然后暂停检索的时间,范围:0-100" >网页模式防卡延迟
<input class="webmodledelay" style="width: 30px;vertical-align: AUTO;" type="text">秒
<button data-action="save" style="font-size: x-small;color: Orange" title="范围:0-100,">保存</button></div>

<div data-toggle="TOP">
<append style="font-size: x-small;color: blue" ><data-toggle="CZ" title="自动刷新直播间间隔时间" >自动刷新间隔时间
<input class="CZTIME" style="width: 30px;vertical-align: AUTO;" type="text">分钟
<button data-action="save" style="font-size: x-small;color: blue">保存</button></div>

<div data-toggle="AnchorFLASH" title="范围:0-">
<append style="font-size: x-small;color: blue" ><data-toggle="AnchorFLASH" title="获取天选房间数据间隔延迟,不含代码运行时间,范围:0-" >获取天选数据延迟
<input class="AnchorFLASH" style="width: 30px;vertical-align: AUTO;" type="text">毫秒
<button data-action="save" style="font-size: x-small;color: blue" title="范围:0-100,">保存</button></div>

<div data-toggle="AnchorserverFLASH" title="范围:8-50">
<append style="font-size: x-small;color: blue" ><data-toggle="AnchorserverFLASH" title="获取服务器天选房时间间隔,范围:8-50" >获取服务器天选数据间隔
<input class="AnchorserverFLASH" style="width: 30px;vertical-align: AUTO;" type="text">秒
<button data-action="save" style="font-size: x-small;color: blue" title="范围:8-50,">保存</button></div>

<div data-toggle="AnchorcheckFLASH" title="范围:10-5000">
<append style="font-size: x-small;color: blue" ><data-toggle="AnchorcheckFLASH" title="检索天选房时间间隔,范围:10-5000,建议检索耗时+检索间隔≤300秒,即一个5分钟天选的时间" >检索天选房列表时间间隔
<input class="AnchorcheckFLASH" style="width: 30px;vertical-align: AUTO;" type="text">秒
<button data-action="save" style="font-size: x-small;color: blue" title="范围:10-5000">保存</button></div>

<div data-toggle="Anchor_room_send" >
<append style="font-size: x-small;color: blue" title="手动推送服务器房间,如果发现漏掉的天选,可以手动推送到服务器" >手动推送天选房到服务器
<input class="Anchor_room_send" style="width: 43px;vertical-align: AUTO;" type="text">
<button data-action="save" style="font-size: x-small;color: blue">发送</button></div>

<div data-toggle="tu50room">
<input style="vertical-align: text-top;" type="checkbox" ><append style="font-size: x-small;color: blue">分区推荐直播间获取数量30增加到50</div>

<div data-toggle="Anchor_room_get">
<input style="vertical-align: text-top;" type="checkbox" ><append style="font-size: x-small;color: blue">获取分区推荐及实时榜直播间列表开关</div>

<div data-toggle="Anchor_room_get_to_always">
<input style="vertical-align: text-top;" type="checkbox" ><append style="font-size: x-small;color: blue">将最新检索到的天选房加入常驻房列表</div>

<div data-toggle="Anchor_always_room_switch">
<input style="vertical-align: text-top;" type="checkbox" ><append style="font-size: x-small;color: blue" title="默认自动添加有天选的房间到常驻房">启用常驻房(上限:
<input class="Anchor_always_room_num" style="width: 28px;vertical-align: AUTO;" type="text">)加入轮询
<button data-action="save" style="font-size: x-small;color: blue">保存</button></div>

<div data-toggle="Anchor_always_room_add" >
<append style="font-size: x-small;color: blue" title="手动添加房间号到常驻天选房" >手动添加一个房间到常驻天选
<input class="Anchor_always_room_add" style="width: 67px;vertical-align: AUTO;" type="text">
<button data-action="save" style="font-size: x-small;color: blue">添加</button></div>

<div data-toggle="TIMEAREADISABLE">
<apend style="font-size: x-small; color: purple">
<input style="vertical-align: text-top;" type="checkbox">启用
<input class="start" style="width: 15px;vertical-align: top;" type="text">点至
<input class="end" style="width: 15px;vertical-align: top;" type="text">点不抽奖(24小时制)
<button data-action="save" style="font-size: x-small;color: purple">保存</button></div>

<div data-toggle="onedayLT">
<apend style="font-size: x-small; color: purple" title="即将过期辣条,23点50分检查并送出显示为1天的辣条,24点后会自然消失!">
<input style="vertical-align: text-top;" type="checkbox">即将过期辣条:房间
<input class="start" style="width: 50px;vertical-align: top;" type="text">数量
<input class="end" style="width: 30px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color: purple">保存</button></div>

<div data-toggle="onedayLH">
<apend style="font-size: x-small; color: purple" title="即将过期辣条,23点50分检查并送出显示为1天的小心心,24点后会自然消失!">
<input style="vertical-align: text-top;" type="checkbox">即将过期心心:房间
<input class="start" style="width: 50px;vertical-align: top;" type="text">数量
<input class="end" style="width: 30px;vertical-align: top;" type="text">
<button data-action="save" style="font-size: x-small;color: purple">保存</button></div>
</fieldset>

<fieldset>
<legend append style="font-size: x-small;color: #FF34B3">温馨推荐</legend>
<div style="font-size: x-small;color: red">传送门:<a target="_blank" href="https://live.bilibili.com/14578426"><button style="font-size: x-small;color: red">战斗吧歌姬</button></a>(墙裂推荐,人美歌甜)</div>
<div id="hb" style="font-size: x-small;color: #FF34B3">
╰︶﹉⋛⋋⊱⋋<button data-action="tpphide" style="font-size: x-small;color: #FF34B3" title="点击显示/隐藏" >【战斗吧歌姬海报】</button>⋌⊰⋌⋚﹉︶╯
</div>

</fieldset>
`);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(ohb);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').prepend(tpp);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(tj);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(tppp);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(div);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(tp);
                $('.chat-history-panel').append(msg);
                let ctt = $('.control-panel-ctnr.border-box.p-relative');
                ctt.append(tpppp);//向聊天框加入信息
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(goldbox);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(call);
                $('.live-player-ctnr.w-100.h-100.p-absolute.normal').append(call2);
                //对应配置状态
                if(Live_info.room_id === 2374828){
                    let GJTP_Timer = () => {
                        var kd= $('.bilibili-live-player-video-area').width();
                        var gd= $('.bilibili-live-player-video-area').height();
                        $("#img2").width(kd).height(gd);
                    };
                    GJTP_Timer();
                    setInterval(GJTP_Timer, 5e3);
                    div.css({
                        'z-index': '10',
                    });
                    ohb.css({
                        'z-index': '10',
                    });
                    tj.css({
                        'z-index': '10',
                    });
                    tp.css({
                        'z-index': '12',
                    });
                    goldbox.css({
                        'z-index': '11',
                    });
                    call.css({
                        'z-index': '11',
                    });
                    call2.css({
                        'z-index': '11',
                    });
                    tpp.css({
                        'z-index': '10',
                    });
                    msg.css({
                        'z-index': '-1',
                    });
                }else  {
                    tpp.css({
                        'width': '0px',
                        'height': '0px',
                    });
                }
                setInterval(() => document.dispatchEvent(new Event('visibilitychange')), 5 * 60 * 1000);//防挂机判定?

                let Room_exist_check = async function () {//开启伪服务器可行性检查
                    //await $.get(`https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?room_id=${Live_info.room_id}`, function (data) {
                    await BAPI.ajax({url:"xlive/web-room/v1/index/getRoomPlayInfo?room_id="+`${Live_info.room_id}`}).then(async (data) =>{
                        let code= data.code;
                        let uid= data.data.uid;
                        if (code!=0) {
                            room_exist_check=0
                            console.log(`直播间不存在`);
                            //MY_API.chatLog(`直播间不存在,<br/>未能开启伪服务器,<br/>天选功能不受此项判断影响!`)
                        }else{
                            room_exist_check=1
                            console.log(`直播间真实存在`);
                        }
                        if (uid!=Live_info.uid) {
                            room_exist_check=0
                            console.log(`脚本运行房间非当前账号的直播间`);
                            //MY_API.chatLog(`脚本运行房间非当前账号的直播间,<br/>未能开启伪服务器,<br/>天选功能不受此项判断影响!`)
                        }else{
                            room_exist_check=1
                            console.log(`脚本运行房间为当前账号直播间`);
                        }
                    })
                }
                Room_exist_check();

                tj.find('div[data-toggle="TOProomnum"] .num').val((parseInt(MY_API.CONFIG.TOProomnum)).toString());
                tj.find('div[data-toggle="sever_room"] .num').val((parseInt(MY_API.CONFIG.sever_room)).toString());
                tj.find('div[data-toggle="sever_room1"] .num').val((parseInt(MY_API.CONFIG.sever_room1)).toString());
                tj.find('div[data-toggle="sever_room2"] .num').val(MY_API.CONFIG.sever_room2);

                tj.find('div[data-toggle="gift_price"] .num').val((parseInt(MY_API.CONFIG.gift_price)).toString());
                tj.find('div[data-toggle="Anchor_ignore_keyword"] .keyword').val(MY_API.CONFIG.Anchor_ignore_keyword);
                tj.find('div[data-toggle="Anchor_ignore_uid"] .keyword').val(MY_API.CONFIG.Anchor_ignore_uid);

                tj.find('div[data-toggle="sever_room"] [data-action="save"]').click(function () {//sever_room save按钮
                    let val = parseInt(tj.find('div[data-toggle="sever_room"] .num').val());
                    MY_API.CONFIG.sever_room = val;
                    MY_API.GsaveConfig()
                    MY_API.chatLog('0号伪服务器直播间房间号已设置');
                });

                tj.find('div[data-toggle="sever_room1"] [data-action="save"]').click(function () {//sever_room1 save按钮
                    let val = parseInt(tj.find('div[data-toggle="sever_room1"] .num').val());
                    MY_API.CONFIG.sever_room1 = val;
                    MY_API.GsaveConfig()
                    MY_API.chatLog('1号伪服务器直播间房间号已设置');
                });

                tj.find('div[data-toggle="sever_room2"] [data-action="save"]').click(function () {//sever_room2 save按钮
                    let val = tj.find('div[data-toggle="sever_room2"] .num').val();
                    MY_API.CONFIG.sever_room2 = val.split(",");
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`2号伪服务器直播间房间号已设置:</br>${MY_API.CONFIG.sever_room2}`);
                });

                tj.find('div[data-toggle="TOProomnum"] [data-action="save"]').click(function () {//TOProomnum save按钮
                    let val = parseInt(tj.find('div[data-toggle="TOProomnum"] .num').val());
                    if (MY_API.CONFIG.TOProomnum === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<200){
                        MY_API.chatLog('男人不能太小哦ლ(╹◡╹ლ)');
                        val=200

                    }else if(val>1000){
                        MY_API.chatLog('你要上天啊Σ( ° △ °|||)︴');
                        val=1000
                    }
                    MY_API.CONFIG.TOProomnum = val;
                    MY_API.GsaveConfig()
                    MY_API.chatLog('直播间房间号数量上限已设置');
                });
                tj.find('div[data-toggle="gift_price"] [data-action="save"]').click(function () {//gift_price save按钮
                    let val = parseInt(tj.find('div[data-toggle="gift_price"] .num').val());
                    if(val==''){
                        val=0
                    }
                    if (MY_API.CONFIG.gift_price === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    MY_API.CONFIG.gift_price = val;
                    MY_API.GsaveConfig()
                    MY_API.chatLog('【天选时刻】金瓜子投喂上限过滤规则已设置');
                });

                Anchor_ignore_keyword=MY_API.CONFIG.Anchor_ignore_keyword;
                tj.find('div[data-toggle="Anchor_ignore_keyword"] [data-action="save"]').click(function () {//Anchor_ignore_keyword save按钮
                    let val = $(tj).find('div[data-toggle="Anchor_ignore_keyword"] .keyword').val();
                    if(val==''){
                        val='不会吧不会吧居然真有人什么都不过滤'
                    }
                    MY_API.CONFIG.Anchor_ignore_keyword =val.split(",");
                    Anchor_ignore_keyword=MY_API.CONFIG.Anchor_ignore_keyword;
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`【天选时刻】金瓜子投喂上限过滤规则已设置:</br>${MY_API.CONFIG.Anchor_ignore_keyword}`);

                });

                Anchor_ignore_uid=MY_API.CONFIG.Anchor_ignore_uid;
                tj.find('div[data-toggle="Anchor_ignore_uid"] [data-action="save"]').click(function () {//Anchor_ignore_uid save按钮
                    let val = $(tj).find('div[data-toggle="Anchor_ignore_uid"] .keyword').val();
                    if(val==''){
                        val='1234567890'
                    }
                    MY_API.CONFIG.Anchor_ignore_uid =val.split(",");
                    Anchor_ignore_uid=MY_API.CONFIG.Anchor_ignore_uid;
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`【天选时刻】主播黑名单已设置:</br>${MY_API.CONFIG.Anchor_ignore_uid}`);

                });
                tj.find('div[data-toggle="need_medal_roomid"] [data-action="save"]').click(function () {
                    try {
                        let config = JSON.parse(localStorage.getItem(`${NAME}_need_medal_roomid`));
                        need_medal_roomid = [].concat(config.id);
                    } catch (e) {
                    }
                    MY_API.chatLog(`【天选时刻】勋章抽奖房间列表:</br>${need_medal_roomid}`);
                });

                tj.find('div[data-toggle="AUTO_GOLDBOX"] input').change(function () {//
                    MY_API.CONFIG.AUTO_GOLDBOX = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.AUTO_GOLDBOX){
                        setTimeout(() => {
                            MY_API.MaterialObject.run();
                            if (Live_info.uid!=20842051 && FollowingList.indexOf(20842051) == -1) {
                                $.ajax({
                                    url: '//api.bilibili.com/x/relation/modify',
                                    type: "post",
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    data: {
                                        'fid': 20842051,
                                        'act': 1,
                                        're_src': 11,
                                        'jsonp': 'jsonp',
                                        'csrf': Live_info.csrf_token
                                    }
                                })
                            }
                        }, 60e3);
                    }
                });
                tj.find('div[data-toggle="AUTO_Anchor"] input').change(function () {//
                    MY_API.CONFIG.AUTO_Anchor = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.AUTO_Anchor){
                        MY_API.chatLog('5秒后刷新页面,载入天选模块','success');
                        setTimeout(() => {
                            window.location.reload();
                        }, 5e3);
                        if (Live_info.uid!=20842051) {
                            $.ajax({
                                url: '//api.bilibili.com/x/relation/modify',
                                type: "post",
                                xhrFields: {
                                    withCredentials: true
                                },
                                data: {
                                    'fid': 20842051,
                                    'act': 1,
                                    're_src': 11,
                                    'jsonp': 'jsonp',
                                    'csrf': Live_info.csrf_token
                                }
                            })
                        }
                    }
                });

                tj.find('div[data-toggle="switch_sever"] input').change(function () {//
                    MY_API.CONFIG.switch_sever = $(this).prop('checked');
                    if(MY_API.CONFIG.switch_sever) MY_API.CONFIG.AUTO_Anchor=true;
                    MY_API.saveConfig()
                    MY_API.chatLog('【天选时刻】小号蹭天选需要关闭此项,否者容易被风控访问拒绝','warning');
                });

                tj.find('div[data-toggle="Anchor_Followings_switch"] input').change(async function () {//
                    MY_API.CONFIG.Anchor_Followings_switch = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.Anchor_Followings_switch){
                        let getFollowingList=async function(pn = 1, ps = 50){
                            await Sleep(100)
                            if (pn === 1) FollowingList = [];
                            return BAPI.Lottery.anchor.getFollowings(Live_info.uid, pn, ps).then((response) => {
                                let p = $.Deferred();
                                if (response.code === 0) {
                                    p.resolve();
                                    const total = response.data.total;
                                    for (const up of response.data.list) {
                                        FollowingList.push(up.mid);
                                    }
                                    const remainUp = total - FollowingList.length;
                                    if (remainUp > 0)
                                        return $.when(getFollowingList(pn + 1, ps), p);
                                    else {
                                        return p;
                                    }
                                } else {
                                    return p.reject();
                                }
                            }, () => {
                                return MY_API.chatLog('获取关注数据出错!', 'warning');
                                //delayCall(() => getFollowingList());
                            })
                        }
                        MY_API.chatLog('【天选时刻】正在获取关注列表......');
                        await getFollowingList();
                        MY_API.chatLog(`关注列表(${FollowingList.length}):${FollowingList}`);
                        console.log('关注uid列表',FollowingList);
                        try {
                            localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                        }
                    }
                    MY_API.chatLog('【天选时刻】仅参与关注的主播的抽奖设置已保存','success');
                });

                tj.find('div[data-toggle="sever_modle"] input').change(function () {//
                    MY_API.CONFIG.sever_modle = $(this).prop('checked');
                    MY_API.saveConfig()
                });


                if (MY_API.CONFIG.TOP) div.find('div[data-toggle="TOP"] input').attr('checked', '');
                if (MY_API.CONFIG.TALK) div.find('div[data-toggle="TALK"] input').attr('checked', '');
                if (MY_API.CONFIG.tu50room) div.find('div[data-toggle="tu50room"] input').attr('checked', '');//tu50room
                if (MY_API.CONFIG.Anchor_room_get) div.find('div[data-toggle="Anchor_room_get"] input').attr('checked', '');
                if (MY_API.CONFIG.Anchor_room_get_to_always) div.find('div[data-toggle="Anchor_room_get_to_always"] input').attr('checked', '');

                if (MY_API.CONFIG.Anchor_always_room_switch) div.find('div[data-toggle="Anchor_always_room_switch"] input').attr('checked', '');

                if (MY_API.CONFIG.AUTO_BOX) div.find('div[data-toggle="AUTO_BOX"] input').attr('checked', '');
                if (MY_API.CONFIG.AUTO_HEART_newmodel) div.find('div[data-toggle="AUTO_HEART_newmodel"] input').attr('checked', '');
                if (MY_API.CONFIG.AUTO_sign_danmu) div.find('div[data-toggle="AUTO_sign_danmu"] input').attr('checked', '');
                if (MY_API.CONFIG.AUTO_DailyReward) div.find('div[data-toggle="AUTO_DailyReward"] input').attr('checked', '');

                if (MY_API.CONFIG.AUTO_lottery_model1) div.find('div[data-toggle="AUTO_lottery_model1"] input:radio').attr('checked', '');
                if (MY_API.CONFIG.AUTO_lottery_model2) div.find('div[data-toggle="AUTO_lottery_model2"] input:radio').attr('checked', '');

                if (MY_API.CONFIG.AUTO_lottery_model1) webmodle_delay=20;
                if (MY_API.CONFIG.AUTO_lottery_model2) webmodle_delay=0;


                if (MY_API.CONFIG.AUTO_GOLDBOX) tj.find('div[data-toggle="AUTO_GOLDBOX"] input').attr('checked', '');
                if (MY_API.CONFIG.AUTO_Anchor) tj.find('div[data-toggle="AUTO_Anchor"] input').attr('checked', '');
                if (MY_API.CONFIG.switch_sever) tj.find('div[data-toggle="switch_sever"] input').attr('checked', '');
                if (MY_API.CONFIG.Anchor_Followings_switch) tj.find('div[data-toggle="Anchor_Followings_switch"] input').attr('checked', '');
                if (MY_API.CONFIG.sever_modle) tj.find('div[data-toggle="sever_modle"] input').attr('checked', '');

                if (MY_API.CONFIG.switch_sever_room) tj.find('div[data-toggle="sever_room"] input').attr('checked', '');
                if (MY_API.CONFIG.switch_sever_room1) tj.find('div[data-toggle="sever_room1"] input').attr('checked', '');
                if (MY_API.CONFIG.switch_sever_room2) tj.find('div[data-toggle="sever_room2"] input').attr('checked', '');
                tj.find('div[data-toggle="sever_room"] input').change(function () {//
                    MY_API.CONFIG.switch_sever_room = $(this).prop('checked');
                    MY_API.saveConfig()
                });
                tj.find('div[data-toggle="sever_room1"] input').change(function () {//
                    MY_API.CONFIG.switch_sever_room1 = $(this).prop('checked');
                    MY_API.saveConfig()
                });
                tj.find('div[data-toggle="sever_room2"] input').change(function () {//
                    MY_API.CONFIG.switch_sever_room2 = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                if (MY_API.CONFIG.GIFT_AUTO) div.find('div[data-toggle="onedayLT"] input').attr('checked', '');
                if (MY_API.CONFIG.GIFT_AUTO2) div.find('div[data-toggle="onedayLH"] input').attr('checked', '');
                if (MY_API.CONFIG.TIMEAREADISABLE) div.find('div[data-toggle="TIMEAREADISABLE"] input').attr('checked', '');
                div.find('div[data-toggle="TOP"] .CZTIME').val((parseInt(MY_API.CONFIG.CZ)).toString());
                div.find('div[data-toggle="AnchorFLASH"] .AnchorFLASH').val((parseInt(MY_API.CONFIG.AnchorFLASH)).toString());
                div.find('div[data-toggle="webmodledelay"] .webmodledelay').val((parseInt(MY_API.CONFIG.webmodledelay)).toString());
                div.find('div[data-toggle="AnchorserverFLASH"] .AnchorserverFLASH').val((parseInt(MY_API.CONFIG.AnchorserverFLASH)).toString());
                div.find('div[data-toggle="AnchorcheckFLASH"] .AnchorcheckFLASH').val((parseInt(MY_API.CONFIG.AnchorcheckFLASH)).toString());
                div.find('div[data-toggle="Anchor_room_send"] .Anchor_room_send').val((parseInt(MY_API.CONFIG.Anchor_room_send)).toString());
                div.find('div[data-toggle="Anchor_always_room_add"] .Anchor_always_room_add').val((parseInt(MY_API.CONFIG.Anchor_always_room_add)).toString());
                div.find('div[data-toggle="Anchor_always_room_switch"] .Anchor_always_room_num').val((parseInt(MY_API.CONFIG.Anchor_always_room_num)).toString());

                div.find('div[data-toggle="onedayLT"] .start').val(MY_API.CONFIG.GIFT_ROOM.toString());
                div.find('div[data-toggle="onedayLT"] .end').val(MY_API.CONFIG.GIFT_NUM.toString());
                div.find('div[data-toggle="onedayLH"] .start').val(MY_API.CONFIG.GIFT_ROOM2.toString());
                div.find('div[data-toggle="onedayLH"] .end').val(MY_API.CONFIG.GIFT_NUM2.toString());
                div.find('div[data-toggle="TIMEAREADISABLE"] .start').val(MY_API.CONFIG.TIMEAREASTART.toString());
                div.find('div[data-toggle="TIMEAREADISABLE"] .end').val(MY_API.CONFIG.TIMEAREAEND.toString());

                div.find('div[data-toggle="AUTO_sign_time"] .hour').val((parseInt(MY_API.CONFIG.medal_sign_time_hour)).toString());
                div.find('div[data-toggle="AUTO_sign_time"] .min').val((parseInt(MY_API.CONFIG.medal_sign_time_min)).toString());

                div.find('div[data-toggle="AUTO_sign_time"] [data-action="save"]').click(function () {
                    MY_API.CONFIG.medal_sign_time_hour = parseInt(div.find('div[data-toggle="AUTO_sign_time"] .hour').val());
                    if(MY_API.CONFIG.medal_sign_time_hour<0 | MY_API.CONFIG.medal_sign_time_hour>23){
                        MY_API.chatLog('请设置0-23');
                    }
                    MY_API.CONFIG.medal_sign_time_min = parseInt(div.find('div[data-toggle="AUTO_sign_time"] .min').val());
                    if(MY_API.CONFIG.medal_sign_time_min<0 | MY_API.CONFIG.medal_sign_time_min>59){
                        MY_API.chatLog('请设置0-59');
                    }
                    MY_API.saveConfig()
                    MY_API.chatLog('签到时间已设置');
                });

                tj.find('div[data-toggle="ServerChan_SCKEY"] .num').val((MY_API.CONFIG.ServerChan_SCKEY).toString());
                tj.find('div[data-toggle="ServerChan_SCKEY"] [data-action="save"]').click(function () {//save按钮 ServerChan_SCKEY:0,//Server酱微信推送SCKEY      switch_ServerChan_SCKEY:0,//Server酱微信推送开关
                    let val = tj.find('div[data-toggle="ServerChan_SCKEY"] .num').val();
                    MY_API.CONFIG.ServerChan_SCKEY = val;
                    MY_API.GsaveConfig()
                    MY_API.chatLog('ServerChan_SCKEY已设置');
                });
                if (MY_API.CONFIG.switch_ServerChan_SCKEY) tj.find('div[data-toggle="ServerChan_SCKEY"] input').attr('checked', '');
                tj.find('div[data-toggle="ServerChan_SCKEY"] input').change(function () {//
                    MY_API.CONFIG.switch_ServerChan_SCKEY = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                if (MY_API.CONFIG.medal_change) tj.find('div[data-toggle="medal_change"] input').attr('checked', '');
                tj.find('div[data-toggle="medal_change"] input').change(async function () {//
                    MY_API.CONFIG.medal_change = $(this).prop('checked');
                    if(MY_API.CONFIG.medal_change){
                        let getMedalList=async function(page = 1) {//粉丝勋章数据
                            if (page == 1) medal_list = [];
                            await Sleep(100)
                            return BAPI.Lottery.anchor.medal(page, 25).then((data) => {
                                medal_list = medal_list.concat(data.data.fansMedalList);
                                if (data.data.pageinfo.curPage < data.data.pageinfo.totalpages) return getMedalList(page + 1);
                            }, () => {
                                return MY_API.chatLog('获取粉丝勋章数据出错!', 'warning');
                                //delayCall(() => getMedalList());
                            });
                        };
                        await getMedalList();
                        console.log('勋章房间数据',medal_list);
                        for (let i=0;i<medal_list.length;i++) {
                            medal_uid_list[i]=medal_list[i].target_id
                        }
                        console.log('勋章uid列表',medal_uid_list);
                        for (let i=0;i<medal_list.length;i++) {
                            medal_id_list[i]=medal_list[i].medal_id
                        }
                        for (let i=0;i<medal_list.length;i++) {
                            await Sleep(100)
                            await BAPI.room.get_info(medal_list[i].roomid).then(async (data) =>{
                                medal_roomid_list[i]=data.data.room_id
                            })
                        }
                        console.log('勋章roomid列表',medal_roomid_list);
                        try {
                            localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                        }
                        try {
                            localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                        }
                        try {
                            localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                        }
                    }
                    if(MY_API.CONFIG.medal_change & medal_roomid_list.length>0 & medal_roomid_list.indexOf(Live_info.room_id)>-1){
                        let nu= medal_roomid_list.indexOf(Live_info.room_id)
                        BAPI.wear_medal(medal_id_list[nu]).then(async (data) =>{
                            console.log('medal_id_list',data)
                            chatLog(`【自动更换勋章】${data.message}`);
                        })
                    }
                    MY_API.saveConfig()
                });

                if (MY_API.CONFIG.switch_ServerChan_SCKEY1) tj.find('div[data-toggle="ServerChan_SCKEY1"] input').attr('checked', '');
                tj.find('div[data-toggle="ServerChan_SCKEY1"] input').change(function () {//
                    MY_API.CONFIG.switch_ServerChan_SCKEY1 = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                tj.find('div[data-toggle="anchor_danmu_content"] .num').val((MY_API.CONFIG.anchor_danmu_content).toString());
                tj.find('div[data-toggle="anchor_danmu_content"] [data-action="save"]').click(function () {
                    let val = tj.find('div[data-toggle="anchor_danmu_content"] .num').val();
                    if(val==''){
                        val='哈哈哈哈哈哈'
                    }
                    MY_API.CONFIG.anchor_danmu_content = val.split(",");
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`中奖自动弹幕已保存:</br>${MY_API.CONFIG.anchor_danmu_content}`);
                });

                tj.find('div[data-toggle="sign_danmu_content"] .num').val((MY_API.CONFIG.sign_danmu_content).toString());//签到弹幕
                tj.find('div[data-toggle="sign_danmu_content"] [data-action="save"]').click(function () {
                    let val = tj.find('div[data-toggle="sign_danmu_content"] .num').val();
                    if(val==''){
                        val='签到'
                    }
                    MY_API.CONFIG.sign_danmu_content = val.split(",");
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`自动签到弹幕已保存:</br>${MY_API.CONFIG.sign_danmu_content}`);
                });

                if (MY_API.CONFIG.anchor_danmu) tj.find('div[data-toggle="anchor_danmu_content"] input').attr('checked', '');
                tj.find('div[data-toggle="anchor_danmu_content"] input').change(function () {//
                    MY_API.CONFIG.anchor_danmu = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                tj.find('div[data-toggle="anchor_msg_content"] .num').val((MY_API.CONFIG.anchor_msg_content).toString());
                tj.find('div[data-toggle="anchor_msg_content"] [data-action="save"]').click(function () {
                    let val = tj.find('div[data-toggle="anchor_msg_content"] .num').val();
                    if(val==''){
                        val='天选中奖了~~'
                    }
                    MY_API.CONFIG.anchor_msg_content = val.split(",");
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`中奖自动私信已保存:</br>${MY_API.CONFIG.anchor_msg_content}`);
                });
                if (MY_API.CONFIG.anchor_msg) tj.find('div[data-toggle="anchor_msg_content"] input').attr('checked', '');
                tj.find('div[data-toggle="anchor_msg_content"] input').change(function () {//
                    MY_API.CONFIG.anchor_msg = $(this).prop('checked');
                    MY_API.saveConfig()
                });


                div.find('div[data-toggle="TOP"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="TOP"] .CZTIME').val());
                    if (MY_API.CONFIG.CZ === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<30){
                        MY_API.chatLog('男人不能太快哦ლ(╹◡╹ლ)');
                        val=30
                    }else if(val>1500){
                        MY_API.chatLog('你要上天啊Σ( ° △ °|||)︴');
                        val=1500
                    }
                    MY_API.CONFIG.CZ = val;
                    MY_API.saveConfig()
                    MY_API.chatLog('直播间自动刷新时间已设置,并重新开始计时');
                });
                div.find('div[data-toggle="AnchorFLASH"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="AnchorFLASH"] .AnchorFLASH').val());
                    if (MY_API.CONFIG.AnchorFLASH === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<0){
                        MY_API.chatLog('男人不能太快哦ლ(╹◡╹ლ)');
                        val=0
                    }
                    /*else if(val>100){
                        MY_API.chatLog('太慢了Σ( ° △ °|||)︴');
                        val=100
                    }*/
                    MY_API.CONFIG.AnchorFLASH = val;
                    MY_API.saveConfig()
                    MY_API.chatLog('自动巡查时间间隔已设置保存');
                });

                div.find('div[data-toggle="webmodledelay"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="webmodledelay"] .webmodledelay').val());
                    if (MY_API.CONFIG.webmodledelay === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<0){
                        MY_API.chatLog('男人不能太快哦ლ(╹◡╹ლ)');
                        val=0
                    }else if(val>100){
                        MY_API.chatLog('太慢了Σ( ° △ °|||)︴');
                        val=100
                    }
                    MY_API.CONFIG.webmodledelay = val;
                    MY_API.saveConfig()
                    MY_API.chatLog('模拟点击模式打开网页时间间隔已设置保存');
                });


                div.find('div[data-toggle="AnchorserverFLASH"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="AnchorserverFLASH"] .AnchorserverFLASH').val());
                    if (MY_API.CONFIG.AnchorserverFLASH === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<8){
                        MY_API.chatLog('男人不能太快哦ლ(╹◡╹ლ)');
                        val=8
                    }else if(val>50){
                        MY_API.chatLog('太慢了Σ( ° △ °|||)︴');
                        val=50
                    }
                    MY_API.CONFIG.AnchorserverFLASH = val;
                    MY_API.saveConfig()
                    MY_API.chatLog('获取服务器天选数据时间间隔已设置!');
                });
                div.find('div[data-toggle="AnchorcheckFLASH"] [data-action="save"]').click(function () {//AnchorcheckFLASH
                    let val = parseInt(div.find('div[data-toggle="AnchorcheckFLASH"] .AnchorcheckFLASH').val());
                    if (MY_API.CONFIG.AnchorcheckFLASH === val) {
                        MY_API.chatLog('改都没改保存嘛呢');
                        return
                    }
                    if(val<10){
                        MY_API.chatLog('男人不能太快哦ლ(╹◡╹ლ)');
                        val=10
                    }else if(val>5000){
                        MY_API.chatLog('太慢了Σ( ° △ °|||)︴');
                        val=5000
                    }
                    MY_API.CONFIG.AnchorcheckFLASH = val;
                    MY_API.saveConfig()
                    MY_API.chatLog('检索天选数据时间间隔已设置!');
                });
                div.find('div[data-toggle="Anchor_room_send"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="Anchor_room_send"] .Anchor_room_send').val());
                    MY_API.CONFIG.Anchor_room_send = val;
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.switch_sever & room_exist_check){
                        Anchor_room_list.push(MY_API.CONFIG.Anchor_room_send);
                        Anchor_award_id_list.push(ts_s()-1600000000);
                        Anchor_award_nowdate.push(ts_ten_m());
                    }
                    MY_API.chatLog('正在推送手动提交的天选房间到服务器!');
                });

                div.find('div[data-toggle="Anchor_always_room_add"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="Anchor_always_room_add"] .Anchor_always_room_add').val());
                    MY_API.CONFIG.Anchor_always_room_add = val;
                    MY_API.saveConfig()
                    if(Anchor_always_room_list.indexOf(val) == -1){
                        Anchor_always_room_list.push(val);//记录天选房间
                        try {//保存本地
                            localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                            if (Anchor_always_room_list.length >MY_API.CONFIG.Anchor_always_room_num ) {
                                MY_API.chatLog(`常驻房间数达到${MY_API.CONFIG.Anchor_always_room_num},超过设置的上限,移出旧房间${Anchor_always_room_list.length-MY_API.CONFIG.Anchor_always_room_num}个`, 'warning');
                                Anchor_always_room_list.splice(0, Anchor_always_room_list.length-MY_API.CONFIG.Anchor_always_room_num);
                            }
                            localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                            console.log(`${NAME}_Anchor_always_room_list存储失败`);
                        }
                        MY_API.chatLog('手动添加天选房成功!');
                    }else{
                        MY_API.chatLog('该房间已在常驻天选房列表!');
                    }
                    MY_API.chatLog(`当前房间列表(共${Anchor_always_room_list.length}个):</br>${Anchor_always_room_list}`);
                });


                div.find('div[data-toggle="Anchor_always_room_switch"] [data-action="save"]').click(function () {
                    let val = parseInt(div.find('div[data-toggle="Anchor_always_room_switch"] .Anchor_always_room_num').val());
                    MY_API.CONFIG.Anchor_always_room_num = val;
                    try {//保存本地
                        localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                        if (Anchor_always_room_list.length >MY_API.CONFIG.Anchor_always_room_num ) {
                            MY_API.chatLog(`常驻房间数达到${MY_API.CONFIG.Anchor_always_room_num},超过设置的上限,移出旧房间${Anchor_always_room_list.length-MY_API.CONFIG.Anchor_always_room_num}个`, 'warning');
                            MY_API.chatLog(`当前房间列表(共${MY_API.CONFIG.Anchor_always_room_num}个):</br>${Anchor_always_room_list}`);
                            Anchor_always_room_list.splice(0, Anchor_always_room_list.length-MY_API.CONFIG.Anchor_always_room_num);
                        }
                        localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                        console.log(`${NAME}_Anchor_always_room_list存储失败`);
                    }
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="TALK"] input').change(function () {//
                    MY_API.CONFIG.TALK = $(this).prop('checked');
                    if (MY_API.CONFIG.TALK == true) {//自定义提示开关
                        $('.zdbgjMsg').hide(); //隐藏反馈信息
                    }
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="tu50room"] input').change(function () {
                    MY_API.CONFIG.tu50room = $(this).prop('checked');
                    if (MY_API.CONFIG.tu50room == true) {
                        MY_API.CONFIG.getroomnum=50;
                    }else{
                        MY_API.CONFIG.getroomnum=30;
                    }
                    MY_API.saveConfig()
                });
                div.find('div[data-toggle="Anchor_room_get"] input').change(function () {
                    MY_API.CONFIG.Anchor_room_get = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="Anchor_room_get_to_always"] input').change(function () {
                    MY_API.CONFIG.Anchor_room_get_to_always = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="Anchor_always_room_switch"] input').change(function () {
                    MY_API.CONFIG.Anchor_always_room_switch = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="AUTO_BOX"] input').change(function () {//
                    MY_API.CONFIG.AUTO_BOX = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.AUTO_BOX){
                        setTimeout(() => {
                            MY_API.Exchange.run();
                        }, 3e3);
                    }
                });

                div.find('div[data-toggle="AUTO_HEART_newmodel"] input').change(function () {//
                    MY_API.CONFIG.AUTO_HEART_newmodel = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.AUTO_HEART_newmodel){
                        setTimeout(() => {
                            MY_API.SmallHeart_model_two();
                        }, 3e3);
                    }
                });

                div.find('div[data-toggle="AUTO_sign_danmu"] input').change(function () {//
                    MY_API.CONFIG.AUTO_sign_danmu = $(this).prop('checked');
                    MY_API.saveConfig()
                    MY_API.chatLog(`【勋章打卡】设置已保存!`);
                    if(MY_API.CONFIG.AUTO_sign_danmu){
                        setTimeout(async() => {
                            let medal_sign_danmu =async() => {
                                if(!medal_roomid_list.length) await Sleep(60000)
                                for (let i=0;i<medal_roomid_list.length;i++) {
                                    if(medal_ignore_roomid_list.indexOf(String(medal_roomid_list[i]))>-1) {
                                        MY_API.chatLog(`【勋章打卡】黑名单直播间,舍弃签到!`);
                                        continue;
                                    }
                                    await Sleep(5000)
                                    await BAPI.ajax({url:"xlive/web-room/v1/index/getRoomPlayInfo?room_id="+`${medal_roomid_list[i]}`}).then(async (data) =>{
                                        let code= data.code;
                                        if (code!=0) {
                                            console.log(`直播间不存在`);
                                            MY_API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}不存在,打卡失败!`);
                                        }else{
                                            console.log(`直播间真实存在`);
                                            BAPI.room.room_entry_action(medal_roomid_list[i]);//直播间进入记录
                                            //BAPI.sendLiveDanmu(`打卡`,medal_roomid_list[i])
                                            let ii=Math.ceil(Math.random() * (MY_API.CONFIG.sign_danmu_content.length))
                                            BAPI.sendLiveDanmu(MY_API.CONFIG.sign_danmu_content[ii-1],medal_roomid_list[i])
                                            MY_API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}打卡成功!`);
                                        }
                                    })
                                }
                            }
                            if (hour() == MY_API.CONFIG.medal_sign_time_hour && minute() == MY_API.CONFIG.medal_sign_time_min  && medal_sign==0) {
                                medal_sign=1
                                await medal_sign_danmu();
                                setTimeout(async() => {
                                    medal_sign=0
                                },30*60*1000)
                            }
                        }, 5e3);
                    }
                });
                let run_mark=1
                div.find('div[data-toggle="AUTO_sign_danmu"] [data-action="save"]').click(async function () {//
                    if(run_mark && medal_sign==0){
                        run_mark=0
                        let medal_sign_danmu =async() => {
                            if(!medal_roomid_list.length) await Sleep(60000)
                            for (let i=0;i<medal_roomid_list.length;i++) {
                                if(medal_ignore_roomid_list.indexOf(String(medal_roomid_list[i]))>-1) {
                                    MY_API.chatLog(`【勋章打卡】黑名单直播间,舍弃签到!`);
                                    continue;
                                }
                                if(medal_ignore_roomid_list.indexOf(medal_roomid_list[i])>-1) {
                                    MY_API.chatLog(`【勋章打卡】黑名单直播间,舍弃签到!`);
                                    continue;
                                }
                                await Sleep(5000)
                                await BAPI.ajax({url:"xlive/web-room/v1/index/getRoomPlayInfo?room_id="+`${medal_roomid_list[i]}`}).then(async (data) =>{
                                    let code= data.code;
                                    if (code!=0) {
                                        console.log(`直播间不存在`);
                                        MY_API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}不存在,打卡失败!`);
                                    }else{
                                        console.log(`直播间真实存在`);
                                        BAPI.room.room_entry_action(medal_roomid_list[i]);//直播间进入记录
                                        //BAPI.sendLiveDanmu(`打卡`,medal_roomid_list[i])
                                        let ii=Math.ceil(Math.random() * (MY_API.CONFIG.sign_danmu_content.length))
                                        BAPI.sendLiveDanmu(MY_API.CONFIG.sign_danmu_content[ii-1],medal_roomid_list[i])
                                        MY_API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}打卡成功!`);
                                    }
                                })
                            }
                        };
                        medal_sign=1;
                        await medal_sign_danmu();
                        medal_sign=0;
                        setTimeout(async() => {
                            run_mark=1
                        },100*60*1000)
                    }else{
                        MY_API.chatLog(`【勋章打卡】请勿短期重复操作!`);
                    }
                });

                medal_ignore_roomid_list=MY_API.CONFIG.medal_ignore_roomid_list
                div.find('div[data-toggle="medal_ignore_roomid_list"] .num').val(MY_API.CONFIG.medal_ignore_roomid_list);
                div.find('div[data-toggle="medal_ignore_roomid_list"] [data-action="save"]').click(function () {//sever_room2 save按钮
                    let val = div.find('div[data-toggle="medal_ignore_roomid_list"] .num').val();
                    MY_API.CONFIG.medal_ignore_roomid_list = val.split(",");
                    console.log(MY_API.CONFIG.medal_ignore_roomid_list)
                    medal_ignore_roomid_list=MY_API.CONFIG.medal_ignore_roomid_list
                    MY_API.GsaveConfig()
                    MY_API.chatLog(`勋章签到黑名单直播间房间号已设置:</br>${MY_API.CONFIG.medal_ignore_roomid_list}`);
                });

                div.find('div[data-toggle="AUTO_DailyReward"] input').change(function () {//
                    MY_API.CONFIG.AUTO_DailyReward = $(this).prop('checked');
                    MY_API.saveConfig()
                    if(MY_API.CONFIG.AUTO_DailyReward){
                        setTimeout(async() => {
                            MY_API.DailyReward.login();
                            MY_API.DailyReward.dynamic();
                        }, 3e3);
                    }
                });

                div.find('div[data-toggle="AUTO_lottery_model1"] input:radio').change(function () {//
                    MY_API.CONFIG.AUTO_lottery_model1 = $(this).prop('checked');
                    MY_API.CONFIG.AUTO_lottery_model2=!MY_API.CONFIG.AUTO_lottery_model1;
                    if(MY_API.CONFIG.AUTO_lottery_model1) webmodle_delay=20;
                    if(MY_API.CONFIG.AUTO_lottery_model2) webmodle_delay=0;
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="AUTO_lottery_model2"] input:radio').change(function () {//
                    MY_API.CONFIG.AUTO_lottery_model2 = $(this).prop('checked');
                    MY_API.CONFIG.AUTO_lottery_model1=!MY_API.CONFIG.AUTO_lottery_model2;
                    if(MY_API.CONFIG.AUTO_lottery_model2) webmodle_delay=0;
                    if(MY_API.CONFIG.AUTO_lottery_model1) webmodle_delay=20;
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="onedayLT"] input:checkbox').change(function () {//
                    MY_API.CONFIG.GIFT_AUTO = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="onedayLT"] [data-action="save"]').click(function () {//
                    MY_API.CONFIG.GIFT_ROOM = parseInt(div.find('div[data-toggle="onedayLT"] .start').val());
                    MY_API.CONFIG.GIFT_NUM = parseInt(div.find('div[data-toggle="onedayLT"] .end').val());
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="onedayLH"] input:checkbox').change(function () {//
                    MY_API.CONFIG.GIFT_AUTO2 = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="onedayLH"] [data-action="save"]').click(function () {//
                    MY_API.CONFIG.GIFT_ROOM2 = parseInt(div.find('div[data-toggle="onedayLH"] .start').val());
                    MY_API.CONFIG.GIFT_NUM2 = parseInt(div.find('div[data-toggle="onedayLH"] .end').val());
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="TIMEAREADISABLE"] input:checkbox').change(function () {//
                    MY_API.CONFIG.TIMEAREADISABLE = $(this).prop('checked');
                    MY_API.saveConfig()
                });

                div.find('div[data-toggle="TIMEAREADISABLE"] [data-action="save"]').click(function () {//
                    let TIMEAREASTART = parseInt(div.find('div[data-toggle="TIMEAREADISABLE"] .start').val());
                    let TIMEAREAEND = parseInt(div.find('div[data-toggle="TIMEAREADISABLE"] .end').val());
                    if(TIMEAREASTART>=TIMEAREAEND){
                        MY_API.chatLog('起始时间大于结束时间,时间设置错误,请重新输入');
                    }else{
                        MY_API.CONFIG.TIMEAREASTART = parseInt(div.find('div[data-toggle="TIMEAREADISABLE"] .start').val());
                        MY_API.CONFIG.TIMEAREAEND = parseInt(div.find('div[data-toggle="TIMEAREADISABLE"] .end').val());
                        MY_API.saveConfig()
                    }
                });

                div.find('#giftCountsent [data-action="countsent"]').click(function () {//
                    BAPI.room.room_entry_action(2374828);//直播间进入记录
                    BAPI.sendLiveDanmu(`Lv${BPDJ},${COUNT}`,2374828)

                });
                div.find('#giftCountsent [data-action="countsentt"]').click(function () {//
                    setTimeout(() => {
                        tppp.css({
                            'z-index': '9999',
                        });
                    }, 1e3);
                    setTimeout(() => {
                        tppp.css({
                            'z-index': '-9999',
                        });
                    }, 6e3);
                });
                div.find('#hb [data-action="tpphide"]').click(function () {//
                    $('.zdbgjtpp').toggle();
                    setTimeout(() => {
                        tpppp.css({
                            'z-index': '9999',
                        });
                    }, 3e3);
                    MY_API.chatLog('感谢可可爱爱赠送的虚拟小电视');
                    setTimeout(() => {
                        tpppp.css({
                            'z-index': '-9999',
                        });
                    }, 13e3);

                });

            },


            chatLog: function (text, type = 'info') {//自定义提示
                let div = $("<div class='zdbgjMsg'>");
                let msg = $("<div>");
                let ct = $('#chat-items');
                let myDate = new Date();
                msg.html(text);
                //msg.text(text);
                div.text(myDate.toLocaleString());
                div.append(msg);
                div.css({
                    'text-align': 'center',
                    'border-radius': '4px',
                    'min-height': '30px',
                    'width': '256px',
                    'color': '#00B2EE',
                    'line-height': '30px',
                    'padding': '0 10px',
                    'margin': '10px auto',
                });
                msg.css({
                    'word-wrap': 'break-word',
                    'width': '100%',
                    'line-height': '20px',
                    'margin-bottom': '10px',
                });
                switch (type) {
                    case 'warning':
                        div.css({
                            'border': '1px solid rgb(236, 221, 192)',
                            'color': 'rgb(218, 142, 36)',
                            'background': 'rgb(245, 235, 221) none repeat scroll 0% 0%',
                        });
                        break;
                    case 'success':
                        div.css({
                            'border': '1px solid rgba(22, 140, 0, 0.28)',
                            'color': 'rgb(69, 171, 69)',
                            'background': 'none 0% 0% repeat scroll rgba(16, 255, 0, 0.18)',
                        });
                        break;
                    default:
                        div.css({
                            'border': '1px solid rgb(203, 195, 255)',
                            'background': 'rgb(233, 230, 255) none repeat scroll 0% 0%',
                        });
                }
                if (MY_API.CONFIG.TALK == false) {//自定义提示开关
                    ct.append(div);//向聊天框加入信息
                    let ctt = $('#chat-history-list');
                    ctt.animate({scrollTop: ctt.prop("scrollHeight")}, 0);//滚动到底部
                }
            },
            sendonedayLT: function () {//二次检查时会继续送到设定房间,未做总量累计,剩余少量辣条,可忽略
                BAPI.gift.bag_list().then(function (bagResult) {
                    if (bagResult.data.list[0].corner_mark === '1天' && bagResult.data.list[0].gift_name === '辣条') {
                        BAPI.live_user.get_anchor_in_room(MY_API.CONFIG.GIFT_ROOM).then(function (roomResult) {
                            if(bagResult.data.list[0].gift_num<=MY_API.CONFIG.GIFT_NUM){
                                onedayLT(roomResult.data.info.uid,
                                         bagResult.data.list[0].gift_id,
                                         bagResult.data.list[0].bag_id,
                                         bagResult.data.list[0].gift_num)
                            }else{
                                onedayLT(roomResult.data.info.uid,
                                         bagResult.data.list[0].gift_id,
                                         bagResult.data.list[0].bag_id,
                                         MY_API.CONFIG.GIFT_NUM)
                            }
                            setTimeout(() => {
                                if(bagResult.data.list[0].gift_num > MY_API.CONFIG.GIFT_NUM){
                                    onedayLTUP(roomResult.data.info.uid,
                                               bagResult.data.list[0].gift_id,
                                               bagResult.data.list[0].bag_id,
                                               bagResult.data.list[0].gift_num-MY_API.CONFIG.GIFT_NUM)
                                }
                            },5000);
                        });
                    }
                });
                let onedayLT = (rUid, gift_id, bag_id, num) => {
                    let ts = Math.round(new Date() / 1000);//时间戳
                    BAPI.gift.bag_send(Live_info.uid, gift_id, rUid, num, bag_id, MY_API.CONFIG.GIFT_ROOM, ts).then(function (result) {
                        if (result.code === 0 && result.msg === 'success') {
                            MY_API.chatLog('[马上要过期的1天辣条]' + result.data.send_tips, 'success');
                        } else {
                            MY_API.chatLog('[礼物]赠送失败', 'warning');
                        }
                    });
                };
                let onedayLTUP = (rUid, gift_id, bag_id, num) => {
                    let ts = Math.round(new Date() / 1000);//时间戳
                    BAPI.gift.bag_send(Live_info.uid, gift_id, rUid, num, bag_id, 2374828, ts).then(function (result) {
                        if (result.code === 0 && result.msg === 'success') {
                            MY_API.chatLog('[给UP丢1天辣条吧]' + result.data.send_tips, 'success');
                        } else {
                            MY_API.chatLog('[礼物]赠送失败', 'warning');
                        }
                    });
                };
            },
            sendonedayLH: function () {//二次检查时会继续送到设定房间,未做总量累计,剩余少量辣条,可忽略
                BAPI.gift.bag_list().then(function (bagResult) {
                    if (bagResult.data.list[0].corner_mark === '1天' && bagResult.data.list[0].gift_name === '小心心') {
                        BAPI.live_user.get_anchor_in_room(MY_API.CONFIG.GIFT_ROOM2).then(function (roomResult) {
                            if(bagResult.data.list[0].gift_num<=MY_API.CONFIG.GIFT_NUM2){
                                onedayLH(roomResult.data.info.uid,
                                         bagResult.data.list[0].gift_id,
                                         bagResult.data.list[0].bag_id,
                                         bagResult.data.list[0].gift_num)
                            }else{
                                onedayLH(roomResult.data.info.uid,
                                         bagResult.data.list[0].gift_id,
                                         bagResult.data.list[0].bag_id,
                                         MY_API.CONFIG.GIFT_NUM2)
                            }
                            setTimeout(() => {
                                if(bagResult.data.list[0].gift_num > MY_API.CONFIG.GIFT_NUM2){
                                    onedayLHUP(roomResult.data.info.uid,
                                               bagResult.data.list[0].gift_id,
                                               bagResult.data.list[0].bag_id,
                                               bagResult.data.list[0].gift_num-MY_API.CONFIG.GIFT_NUM2)
                                }
                            },5000);
                        });
                    }
                });
                let onedayLH = (rUid, gift_id, bag_id, num) => {
                    let ts = Math.round(new Date() / 1000);//时间戳
                    BAPI.gift.bag_send(Live_info.uid, gift_id, rUid, num, bag_id, MY_API.CONFIG.GIFT_ROOM2, ts).then(function (result) {
                        if (result.code === 0 && result.msg === 'success') {
                            MY_API.chatLog('[马上要过期的1天小心心]' + result.data.send_tips, 'success');
                        } else {
                            MY_API.chatLog('[礼物]赠送失败', 'warning');
                        }
                    });
                };
                let onedayLHUP = (rUid, gift_id, bag_id, num) => {
                    let ts = Math.round(new Date() / 1000);//时间戳
                    BAPI.gift.bag_send(Live_info.uid, gift_id, rUid, num, bag_id, 2374828, ts).then(function (result) {
                        if (result.code === 0 && result.msg === 'success') {
                            MY_API.chatLog('[给UP丢1天小心心吧]' + result.data.send_tips, 'success');
                        } else {
                            MY_API.chatLog('[礼物]赠送失败', 'warning');
                        }
                    });
                };
            },
            SmallHeart_model_two: async () => {// @namespace   https://github.com/lzghzr/TampermonkeyJS// @version     0.1.4// @author      lzghzr// @description B站直播客户端心跳
                if (!MY_API.CONFIG.AUTO_HEART_newmodel) {
                    return;
                }
                if(MY_API.GIFT_COUNT.LCOUNT>=24) {
                    MY_API.chatLog(`小心心已满`);
                    return;
                }
                await Sleep(5000);
                const W = typeof unsafeWindow === 'undefined' ? window : unsafeWindow;
                if (W.BilibiliLive === undefined)
                    return console.error(GM_info.script.name, '未获取到uid');
                const uid = W.BilibiliLive.UID;
                const tid = W.BilibiliLive.ANCHOR_UID;
                if (uid === 0)
                    return console.error(GM_info.script.name, '未获取到uid');
                const getInfo = () => XHR({
                    GM: true,
                    anonymous: true,
                    method: 'GET',
                    url: `https://passport.bilibili.com/x/passport-login/oauth2/info?${appToken.signLoginQuery(`access_key=${tokenData.access_token}`)}`,
                    responseType: 'json',
                    headers: appToken.headers
                });
                const mobileOnline = () => XHR({
                    GM: true,
                    anonymous: true,
                    method: 'POST',
                    url: `https://api.live.bilibili.com/heartbeat/v1/OnLine/mobileOnline?${BilibiliToken.signQuery(`access_key=${tokenData.access_token}&${baseQuery}`)}`,
                    data: `room_id=${W.BilibiliLive.ROOMID}&scale=xxhdpi`,
                    responseType: 'json',
                    headers: appToken.headers
                });
                const RandomHex = (length) => {
                    const words = '0123456789abcdef';
                    let randomID = '';
                    randomID += words[Math.floor(Math.random() * 15) + 1];
                    for (let i = 0; i < length - 1; i++)
                        randomID += words[Math.floor(Math.random() * 16)];
                    return randomID;
                };
                const uuid = () => RandomHex(32).replace(/(\w{8})(\w{4})\w(\w{3})\w(\w{3})(\w{12})/, `$1-$2-4$3-${'89ab'[Math.floor(Math.random() * 4)]}$4-$5`);
                const mobileHeartBeatJSON = {
                    platform: 'android',
                    uuid: uuid(),
                    buvid: appToken.buvid,
                    seq_id: '1',
                    room_id: '{room_id}',
                    parent_id: '6',
                    area_id: '283',
                    timestamp: '{timestamp}',
                    secret_key: 'axoaadsffcazxksectbbb',
                    watch_time: '60',
                    up_id: '{target_id}',
                    up_level: '40',
                    jump_from: '30000',
                    gu_id: RandomHex(43),
                    play_type: '0',
                    play_url: '',
                    s_time: '0',
                    data_behavior_id: '',
                    data_source_id: '',
                    up_session: 'l:one:live:record:{room_id}:{last_wear_time}',
                    visit_id: RandomHex(32),
                    watch_status: '%7B%22pk_id%22%3A0%2C%22screen_status%22%3A1%7D',
                    click_id: uuid(),
                    session_id: '',
                    player_type: '0',
                    client_ts: '{client_ts}'
                };
                const wasm = new WasmHash();
                await wasm.init();
                const clientSign = (data) => wasm.hash('BLAKE2b512', wasm.hash('SHA3-384', wasm.hash('SHA384', wasm.hash('SHA3-512', wasm.hash('SHA512', JSON.stringify(data))))));
                const getFansMedal = async () => {
                    const funsMedals = await XHR({
                        GM: true,
                        anonymous: true,
                        method: 'GET',
                        url: `https://api.live.bilibili.com/fans_medal/v1/FansMedal/get_list_in_room?${BilibiliToken.signQuery(`access_key=${tokenData.access_token}&target_id=${tid}&uid=${uid}&${baseQuery}`)}`,
                        responseType: 'json',
                        headers: appToken.headers
                    });
                    if (funsMedals !== undefined && funsMedals.response.status === 200)
                        if (funsMedals.body.code === 0)
                            if (funsMedals.body.data.length > 0)
                                return funsMedals.body.data;
                };
                const getGiftNum = async () => {
                    let count = 0;
                    const bagInfo = await XHR({
                        GM: true,
                        anonymous: true,
                        method: 'GET',
                        url: `https://api.live.bilibili.com/xlive/app-room/v1/gift/bag_list?${BilibiliToken.signQuery(`access_key=${tokenData.access_token}&room_id=${W.BilibiliLive.ROOMID}&${baseQuery}`)}`,
                        responseType: 'json',
                        headers: appToken.headers
                    });
                    if (bagInfo !== undefined && bagInfo.response.status === 200)
                        if (bagInfo.body.code === 0)
                            if (bagInfo.body.data.list.length > 0)
                                for (const giftData of bagInfo.body.data.list)
                                    if (giftData.gift_id === 30607) {
                                        const expire = (giftData.expire_at - Date.now() / 1000) / 60 / 60 / 24;
                                        if (expire > 6 && expire <= 7)
                                            count += giftData.gift_num;
                                    }
                    return count;
                };
                const mobileHeartBeat = async (postJSON) => {
                    const sign = clientSign(postJSON);
                    let postData = '';
                    for (const i in postJSON)
                        postData += `${i}=${encodeURIComponent(postJSON[i])}&`;
                    postData += `client_sign=${sign}`;
                    const mobileHeartBeat = await XHR({
                        GM: true,
                        anonymous: true,
                        method: 'POST',
                        url: 'https://live-trace.bilibili.com/xlive/data-interface/v1/heartbeat/mobileHeartBeat',
                        data: BilibiliToken.signQuery(`access_key=${tokenData.access_token}&${postData}&${baseQuery}`),
                        responseType: 'json',
                        headers: appToken.headers
                    });
                    if (mobileHeartBeat !== undefined && mobileHeartBeat.response.status === 200)
                        if (mobileHeartBeat.body.code === 0)
                            return true;
                    return false;
                };
                if (await setToken() === undefined)
                    return;
                else {
                    const userInfo = await getInfo();
                    if (userInfo === undefined)
                        return console.error(GM_info.script.name, '获取用户信息错误');
                    if (userInfo.body.code !== 0 && await setToken() === undefined)
                        return;
                    else if (userInfo.body.data.mid !== uid && await setToken() === undefined)
                        return;
                }
                //console.log('tokenData',tokenData)
                //console.log(GM_info.script.name, '开始客户端心跳');
                //MY_API.chatLog(`正在发送客户端心跳获取小心心`);
                mobileOnline();
                const giftNum = await getGiftNum();
                MY_API.GIFT_COUNT.LCOUNT = await getGiftNum();
                MY_API.saveGiftCount();
                if (giftNum < 24) {
                    const fansMedal = await getFansMedal();
                    if (fansMedal !== undefined) {
                        const control = 24 - giftNum;
                        const loopNum = Math.ceil(control / fansMedal.length)*10;
                        let num=0
                        let mobileHeartBeat_postData = async() => {
                            num++
                            console.log('tokenData',tokenData)
                            console.log(GM_info.script.name, '开始客户端心跳');
                            MY_API.chatLog(`正在发送客户端心跳获取小心心`);
                            for (const funsMedalData of fansMedal) {
                                const postData = Object.assign({}, mobileHeartBeatJSON, {
                                    room_id: funsMedalData.room_id.toString(),
                                    timestamp: (BilibiliToken.TS - 30).toString(),
                                    up_id: funsMedalData.target_id.toString(),
                                    up_session: `l:one:live:record:${funsMedalData.room_id}:${funsMedalData.last_wear_time}`,
                                    client_ts: BilibiliToken.TS.toString()
                                });
                                await mobileHeartBeat(postData);
                            }
                            if(num>loopNum){
                                clearInterval(mobileHeartBeat_Timer);
                                await Sleep(10000)
                                MY_API.GIFT_COUNT.LCOUNT = await getGiftNum();
                                MY_API.saveGiftCount();
                                if(MY_API.GIFT_COUNT.LCOUNT>=24){
                                    MY_API.chatLog(`小心心已满`);
                                }else{
                                    return MY_API.SmallHeart_model_two()
                                }
                            }
                        }
                        let mobileHeartBeat_Timer=setInterval(mobileHeartBeat_postData, 30e3);
                    }else{
                        MY_API.chatLog(`未拥有粉丝牌或获取勋章数据失败!`);
                    }
                }else{
                    console.log(GM_info.script.name, '小心心已满');
                    MY_API.chatLog(`小心心已满`);
                }
            },
            MaterialObject: {
                list: [],
                ignore_keyword: ['test', 'encrypt', '测试', '钓鱼', '加密', '炸鱼'],
                run: () => {
                    if(!MY_API.CONFIG.AUTO_GOLDBOX) return;
                    try {
                        if (MY_API.CONFIG.materialobject_ts) {
                            const diff = ts_ms() - MY_API.CONFIG.materialobject_ts;
                            const interval = 30*60e3;
                            if (diff < interval) {
                                setTimeout(MY_API.MaterialObject.run, interval - diff);
                                return $.Deferred().resolve();
                            }
                        }
                        return MY_API.MaterialObject.check().then((aid) => {
                            if (aid) { // aid有效
                                MY_API.CONFIG.last_aid = aid-5;
                                MY_API.CONFIG.materialobject_ts = ts_ms();
                                MY_API.GsaveConfig();
                            }
                            setTimeout(MY_API.MaterialObject.run, 30*60e3);
                        }, () => delayCall(() => MY_API.MaterialObject.run()));
                    } catch (err) {
                        MY_API.chatLog('【实物宝箱抽奖】运行时出现异常', 'warning');
                        console.error(`[${NAME}]`, err);
                        return $.Deferred().reject();
                    }
                },
                check: async (aid, valid = 650, rem = 9) => { // TODO
                    aid = parseInt( aid ||(MY_API.CONFIG.last_aid), 10);
                    if (isNaN(aid)) aid = valid;
                    await Sleep(1000)
                    return BAPI.Lottery.MaterialObject.getStatus(aid).then((response) => {
                        if (response.code === 0 && response.data) {
                            if (MY_API.MaterialObject.ignore_keyword.some(v => response.data.title.toLowerCase().indexOf(v) > -1)) {
                                MY_API.chatLog(`【实物宝箱抽奖】忽略可疑抽奖(aid=${aid})!`, 'warning');
                                return MY_API.MaterialObject.check(aid + 1, aid);
                            } else {
                                return MY_API.MaterialObject.join(aid, response.data.title,response.data.typeB).then(() => MY_API.MaterialObject.check(
                                    aid + 1, aid));
                            }
                        } else if (response.code === -400 || response.data == null) { // 活动不存在
                            if (rem) return MY_API.MaterialObject.check(aid + 1, valid, rem - 1);
                            return $.Deferred().resolve(valid);
                        } else {
                            MY_API.chatLog(`【实物宝箱抽奖】${response.msg}`, 'info');
                        }
                    }, () => {
                        MY_API.chatLog(`【实物宝箱抽奖】检查抽奖(aid=${aid})失败,请检查网络`, 'warning');
                        return delayCall(() => MY_API.MaterialObject.check(aid, valid));
                    });
                },
                join: (aid, title, typeB,i = 0) => {
                    if (i >= typeB.length) return $.Deferred().resolve();
                    MY_API.chatLog(`【${title}】${i+1}/${typeB.length}:${typeB[i].list[0].jp_name},${typeB[i].startTime}`);
                    if (MY_API.MaterialObject.list.some(v => v.aid === aid && v.number === i + 1)) return MY_API.MaterialObject.join(aid, title, typeB, i + 1);
                    const number = i + 1;
                    const obj = {
                        title: title,
                        aid: aid,
                        number: number,
                        status: typeB[i].status,
                        join_start_time: typeB[i].join_start_time,
                        join_end_time: typeB[i].join_end_time,
                        startTime: typeB[i].startTime,
                        jp_name:typeB[i].list[0].jp_name
                    };
                    switch (obj.status) {
                        case -1: // 未开始
                            {
                                MY_API.MaterialObject.list.push(obj);
                                const p = $.Deferred();
                                p.then(() => {
                                    return MY_API.MaterialObject.draw(obj);
                                });
                                setTimeout(() => {
                                    p.resolve();
                                }, (obj.join_start_time - ts_s() + 1) * 1e3);
                            }
                            break;
                        case 0: // 可参加
                            {
                                return MY_API.MaterialObject.draw(obj).then(() => {
                                    return MY_API.MaterialObject.join(aid, title, typeB, i + 1);
                                });
                            }

                        case 1: // 已参加
                            {
                                MY_API.MaterialObject.list.push(obj);
                            }
                            break;
                    }
                    return MY_API.MaterialObject.join(aid, title, typeB, i + 1);
                },
                draw: (obj) => {//obj.aid
                    if(MY_API.CONFIG.AUTO_lottery_model2){
                        return BAPI.Lottery.MaterialObject.draw(obj.aid, obj.number).then((response) => {
                            if (response.code === 0) {
                                $.each(MY_API.MaterialObject.list, (i, v) => {
                                    if (v.aid === obj.aid && v.number === obj.number) {
                                        v.status = 1;
                                        MY_API.MaterialObject.list[i] = v;
                                        MY_API.CONFIG.COUNT_GOLDBOX++;
                                        MY_API.GsaveConfig();
                                        MY_API.chatLog(`【实物宝箱抽奖】正在参加抽奖:【${obj.title}】(aid=${obj.aid},number=${obj.number})!`,'success');
                                        return false;
                                    }
                                });
                                const p = $.Deferred();
                                p.then(() => {
                                    return MY_API.MaterialObject.notice(obj);
                                });
                                setTimeout(() => {
                                    p.resolve();
                                }, (obj.join_end_time - ts_s() + 1) * 1e3);     //
                            } else {
                                MY_API.chatLog(`【实物宝箱抽奖】【${obj.title}】(aid=${obj.aid},number=${obj.number})${response.msg}`,'warning');
                            }
                        }, () => {
                            MY_API.chatLog(`【实物宝箱抽奖】参加【${obj.title}】(aid=${obj.aid},number=${obj.number})失败,请检查网络`,'warning');
                            return delayCall(() => MY_API.MaterialObject.draw(obj));
                        });
                    }
                    if(MY_API.CONFIG.AUTO_lottery_model1){
                        MY_API.chatLog(`【实物宝箱抽奖】正在参加抽奖:【${obj.title}】(aid=${obj.aid},number=${obj.number})!`,'success');
                        GM_openInTab(`https://live.bilibili.com/p/html/live-room-treasurebox/index.html?aid=${obj.aid}#/?MaterialObjectcut`)
                        MY_API.MaterialObject.list.push(obj)
                        const p = $.Deferred();
                        p.then(() => {
                            return MY_API.MaterialObject.notice(obj);
                        });
                        setTimeout(() => {
                            p.resolve();
                        }, (obj.join_end_time - ts_s() + 1) * 1e3);
                        MY_API.CONFIG.COUNT_GOLDBOX++;
                        MY_API.GsaveConfig();
                        CZ_delay=1;
                        setTimeout(() => {
                            CZ_delay=0
                        }, 60e3);
                    }
                },
                notice: (obj) => {
                    return BAPI.Lottery.MaterialObject.getWinnerGroupInfo(obj.aid, obj.number).then((response) => {
                        if (response.code === 0) {
                            $.each(MY_API.MaterialObject.list, (i, v) => {
                                if (v.aid === obj.aid && v.number === obj.number) {
                                    v.status = 3;
                                    MY_API.MaterialObject.list[i] = v;
                                    return false;
                                }
                            });
                            $.each(response.data.winnerList, (i, v) => {
                                if (v.uid === Live_info.uid) {
                                    MY_API.chatLog(`【实物宝箱抽奖】抽奖【${obj.title}】(aid=${obj.aid},number=${obj.number})获得奖励【${v.giftTitle}】`,'success');
                                    BAPI.postdiscuss(`${Live_info.uname}:${v.giftTitle}`)
                                    if(MY_API.CONFIG.switch_ServerChan_SCKEY){
                                        //$.post(`https://sc.ftqq.com/${API.CONFIG.ServerChan_SCKEY}.send?text=[天选众]恭喜你获得奖品${v.giftTitle}!`)
                                        ServerChan2(MY_API.CONFIG.ServerChan_SCKEY,`[天选众]${Live_info.uname}:恭喜你获得奖品${v.giftTitle}!`);
                                    }
                                    return false;
                                }
                            });
                        } else {
                            MY_API.chatLog(`【实物宝箱抽奖】抽奖【${obj.title}】(aid=${obj.aid},number=${obj.number})${response.msg}`,'warning');
                        }
                    }, () => {
                        MY_API.chatLog(`【实物宝箱抽奖】获取抽奖【${obj.title}】(aid=${obj.aid},number=${obj.number})中奖名单失败,请检查网络`,
                                       'error');
                        return delayCall(() => MY_API.MaterialObject.notice(obj));
                    });
                }
            },
            DailyReward: {//每日任务:主站登陆、观看、转发
                login: () => {
                    if (!MY_API.CONFIG.AUTO_DailyReward) return;
                    return BAPI.DailyReward.login().then(() => {
                        MY_API.chatLog('[自动每日奖励][每日登录]完成', 'success');
                    }, () => {
                        MY_API.chatLog('[自动每日奖励][每日登录]完成失败,请检查网络', 'error');
                        return delayCall(() => MY_API.DailyReward.login());
                    });
                },
                share: (aid) => {
                    return BAPI.DailyReward.share(aid).then((response) => {
                        if (response.code === 0) {
                            MY_API.chatLog(`[自动每日奖励][每日分享]分享成功(av=${aid})`, 'success');
                        } else if (response.code === 71000) {
                            // 重复分享
                            MY_API.chatLog('[自动每日奖励][每日分享]今日分享已完成', 'info');
                        } else {
                            MY_API.chatLog(`[自动每日奖励][每日分享]'${response.msg}`, 'caution');
                        }
                    }, () => {
                        MY_API.chatLog('[自动每日奖励][每日分享]分享失败,请检查网络', 'error');
                        return delayCall(() => MY_API.DailyReward.share(aid));
                    });
                },
                watch: (aid, cid) => {
                    return BAPI.DailyReward.watch(aid, cid, Live_info.uid, ts_s()).then((response) => {
                        if (response.code === 0) {
                            MY_API.chatLog(`[自动每日奖励][每日观看]完成(av=${aid})`, 'success');
                        } else {
                            MY_API.chatLog(`[自动每日奖励][每日观看]'${response.msg}`, 'caution');
                        }
                    }, () => {
                        MY_API.chatLog('[自动每日奖励][每日观看]完成失败,请检查网络', 'error');
                        return delayCall(() => MY_API.DailyReward.watch(aid, cid));
                    });
                },
                dynamic: async () => {
                    if (!MY_API.CONFIG.AUTO_DailyReward) return;
                    return BAPI.dynamic_svr.dynamic_new(Live_info.uid, 8).then((response) => {
                        if (response.code === 0) {
                            if (!!response.data.cards) {
                                const obj = JSON.parse(response.data.cards[0].card);
                                const p1 = MY_API.DailyReward.watch(obj.aid, obj.cid);
                                const p3 = MY_API.DailyReward.share(obj.aid);
                                return $.when(p1,p3);
                            } else {
                                MY_API.chatLog('[自动每日奖励]"动态-投稿视频"中暂无动态', 'info');
                            }
                        } else {
                            MY_API.chatLog(`[自动每日奖励]获取"动态-投稿视频"'${response.msg}`, 'caution');
                        }
                    }, () => {
                        MY_API.chatLog('[自动每日奖励]获取"动态-投稿视频"失败,请检查网络', 'error');
                        return delayCall(() => MY_API.DailyReward.dynamic());
                    });
                },
            }, // Once Run every day "api.live.bilibili.com"

            Exchange: {
                silver2coin: () => {
                    if (!MY_API.CONFIG.AUTO_BOX) return;
                    return BAPI.Exchange.silver2coin().then((response) => {
                        //console.log('Exchange.silver2coin: API.SilverCoinExchange.silver2coin', response);
                        if (response.code === 0) {
                            MY_API.chatLog(`【银瓜子换硬币】${response.msg}`, 'success');// 兑换成功
                        } else if (response.code === 403) {
                            MY_API.chatLog(`【银瓜子换硬币】${response.msg}`, 'warning');// 每天最多能兑换 1 个or银瓜子余额不足
                        } else {
                            MY_API.chatLog(`【银瓜子换硬币】${response.msg}`, 'warning');
                        }
                    }, () => {
                        MY_API.chatLog('【银瓜子换硬币】兑换失败,请检查网络', 'warning');
                        return delayCall(() => MY_API.Exchange.silver2coin());
                    });
                },
                run: () => {
                    if (!MY_API.CONFIG.AUTO_BOX) return;
                    try {
                        return MY_API.Exchange.silver2coin().then(() => {
                        }, () => delayCall(() => MY_API.Exchange.run()));
                    } catch (err) {
                        MY_API.chatLog('【银瓜子换硬币】运行时出现异常,已停止', 'error');
                        console.error(`[${NAME}]`, err);
                        return $.Deferred().reject();
                    }
                }
            }, // 硬币
        };
        MY_API.init().then(function () {
            if (parseInt(Live_info.uid) === 0 ||isNaN(parseInt(Live_info.uid))) {
                MY_API.chatLog('未登录,请先登录再使用本系统', 'warning');
                return
            }
            if (true) {
                try {
                    const promiseInit = $.Deferred();
                    const uniqueCheck = () => {
                        const t = Date.now();
                        if (t - MY_API.CONFIG.JSMARK >= 0 && t - MY_API.CONFIG.JSMARK <= 15e3) {
                            // 其他脚本正在运行
                            setTimeout(() => {
                                MY_API.chatLog('检测到系统已经运行!', 'warning');
                            }, 5e3);
                            return promiseInit.reject();
                        }
                        // 没有其他脚本正在运行
                        return promiseInit.resolve();
                    };
                    uniqueCheck().then(() => {
                        let timer_unique;
                        const uniqueMark = () => {
                            timer_unique = setTimeout(uniqueMark, 10e3);
                            MY_API.CONFIG.JSMARK = Date.now();
                            try {
                                localStorage.setItem(`${NAME}_CONFIG`, JSON.stringify(MY_API.CONFIG));
                                return true
                            } catch (e) {
                                //console.log('API保存出错', e);
                                return false
                            };
                        };
                        window.addEventListener('unload', () => {
                            if (timer_unique) {
                                clearTimeout(timer_unique);
                                MY_API.CONFIG.JSMARK = 0;
                                try {
                                    localStorage.setItem(`${NAME}_CONFIG`, JSON.stringify(MY_API.CONFIG));
                                    return true
                                } catch (e) {
                                    //console.log('API保存出错', e);
                                    return false
                                };
                            }
                        });
                        uniqueMark();
                        //console.log(MY_API.CONFIG);
                        StartPlunder(MY_API);
                    })
                }
                catch (e) {
                    console.error('重复运行检测错误', e);
                }
            }
        });
    }


    async function StartPlunder(API) {
        'use strict';
        let index, nowIndex,fengling;
        //let LIVE_PLAYER_STATUS = window.localStorage["LIVE_PLAYER_STATUS"];
        let cut = window.location.href.indexOf('cut') > -1;
        if (cut) {
            try {
                const originFetch = unsafeWindow.fetch;
                unsafeWindow.fetch = (...arg) => {
                    console.log('fetch arg', ...arg);
                    if (arg[0].indexOf('bilivideo.com') > -1) {
                        console.log('拦截直播流');
                        return new Promise(() => {
                            throw new Error();
                        });
                    } else {
                        console.log('通过');
                        return originFetch(...arg);
                    }
                }
            } catch (err) {
                console.error(`[${NAME}]`, err);
            }

        }else
            if (!cut) {
                if (Live_info.room_id === 14578426) {
                    ZBJ='中国虚拟偶像天团【战斗吧歌姬!】';
                }else if(Live_info.room_id === 2374828){
                    ZBJ='【风绫丨钰袖】';
                }else ZBJ='【可可爱爱】';
                let LT_Timer = async() => {//判断是否第二天重置数据
                    if (hour() == 23 && minute() > 50 && API.CONFIG.GIFT_AUTO && minute() < 59) {
                        API.sendonedayLT();
                    }
                    if (hour() == 23 && minute() > 50 && API.CONFIG.GIFT_AUTO2 && minute() < 59) {
                        API.sendonedayLH();
                    }
                    if (hour() == API.CONFIG.medal_sign_time_hour && minute() == API.CONFIG.medal_sign_time_min  && medal_sign==0 ) {
                        let medal_sign_danmu =async() => {
                            if(!medal_roomid_list.length) await Sleep(60000)
                            for (let i=0;i<medal_roomid_list.length;i++) {
                                if(medal_ignore_roomid_list.indexOf(String(medal_roomid_list[i]))>-1) {
                                    API.chatLog(`【勋章打卡】黑名单直播间,舍弃签到!`);
                                    continue;
                                }
                                await Sleep(5000)
                                await BAPI.ajax({url:"xlive/web-room/v1/index/getRoomPlayInfo?room_id="+`${medal_roomid_list[i]}`}).then(async (data) =>{
                                    let code= data.code;
                                    if (code!=0) {
                                        console.log(`直播间不存在`);
                                        API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}不存在,打卡失败!`);
                                    }else{
                                        console.log(`直播间真实存在`);
                                        BAPI.room.room_entry_action(medal_roomid_list[i]);//直播间进入记录
                                        //BAPI.sendLiveDanmu(`打卡`,medal_roomid_list[i])
                                        let ii=Math.ceil(Math.random() * (API.CONFIG.sign_danmu_content.length))
                                        BAPI.sendLiveDanmu(API.CONFIG.sign_danmu_content[ii-1],medal_roomid_list[i])
                                        API.chatLog(`【勋章打卡】直播间房间号:${medal_roomid_list[i]}打卡成功!`);
                                    }
                                })
                            }
                        }
                        if(API.CONFIG.AUTO_sign_danmu){
                            medal_sign=1
                            await medal_sign_danmu();
                            setTimeout(async() => {
                                medal_sign=0
                            },30*60*1000)
                        }
                    }
                    if (checkNewDay(API.GIFT_COUNT.CLEAR_TS) && Anchor_room_list.length==0 && medal_sign==0) {
                        Lcount=0;
                        API.GIFT_COUNT.LCOUNT = 0;
                        API.GIFT_COUNT.LCOUNT2 = 0;
                        API.GIFT_COUNT.COUNT = 0;
                        API.GIFT_COUNT.LOVE_COUNT = 0;
                        API.GIFT_COUNT.CLEAR_TS = dateNow();
                        API.saveGiftCount();
                        if (API.CONFIG.AUTO_GOLDBOX | API.CONFIG.AUTO_Anchor){
                            if (Live_info.uid!=20842051&& FollowingList.indexOf(20842051) == -1) {
                                $.ajax({
                                    url: '//api.bilibili.com/x/relation/modify',
                                    type: "post",
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    data: {
                                        'fid': 20842051,
                                        'act': 1,
                                        're_src': 11,
                                        'jsonp': 'jsonp',
                                        'csrf': Live_info.csrf_token
                                    }
                                })
                            }
                        };
                        API.chatLog('系统正在重启,5秒后重新登入!', 'warning');
                        setTimeout(() => {
                            window.location.reload()
                        }, 5000);
                        //console.log('清空辣条数量')
                    } else {
                        //console.log('无需清空辣条数量')
                    }
                };
                LT_Timer();
                setTimeout(() => {
                    API.DailyReward.login();
                    API.DailyReward.dynamic();
                    API.Exchange.run();
                    API.SmallHeart_model_two();
                    API.MaterialObject.run();//领金宝箱
                    if(API.CONFIG.switch_ServerChan_SCKEY1){
                        ServerChan2(API.CONFIG.ServerChan_SCKEY,`[天选众]提醒:${Live_info.uname}脚本运行中!${minute()}`);
                    }
                }, 10e3);//脚本加载后10秒执行每日任务
                setInterval(LT_Timer, 20e3);
                setInterval(API.expaddGift, 33e3);
                setInterval(API.expaddLove, 37e3);
                API.cjcheck();
                API.creatSetBox();//创建设置框
                let LCOUNT_timer = setInterval(() => {//每隔600s检查心心数量,防止意外情况心心数量异常
                    if (API.GIFT_COUNT.LCOUNT >=24) {
                        clearInterval(LCOUNT_timer);
                    }
                    if (API.GIFT_COUNT.LCOUNT == Lcount && Lcount<24 &&Lcount!=0 && API.GIFT_COUNT.LCOUNT<24 && API.CONFIG.AUTO_HEART_newmodel) {
                        API.chatLog(`小心心数长时间未变化可能已满,停止发送客户端心跳!`);
                        clearInterval(LCOUNT_timer);
                        API.GIFT_COUNT.LCOUNT=66;
                        API.saveGiftCount();
                        return
                    }else {
                        Lcount=API.GIFT_COUNT.LCOUNT;
                    }
                }, 600e3);

                let getMedalList=async function(page = 1) {//粉丝勋章数据
                    if (page == 1) medal_list = [];
                    await Sleep(100)
                    return BAPI.Lottery.anchor.medal(page, 25).then((data) => {
                        medal_list = medal_list.concat(data.data.fansMedalList);
                        if (data.data.pageinfo.curPage < data.data.pageinfo.totalpages) return getMedalList(page + 1);
                    }, () => {
                        return delayCall(() => getMedalList());
                    });
                };

                let getFollowingList=async function(pn = 1, ps = 50){
                    if (pn === 1) FollowingList = [];
                    return BAPI.Lottery.anchor.getFollowings(Live_info.uid, pn, ps).then((response) => {
                        let p = $.Deferred();
                        if (response.code === 0) {
                            p.resolve();
                            const total = response.data.total;
                            for (const up of response.data.list) {
                                FollowingList.push(up.mid);
                            }
                            const remainUp = total - FollowingList.length;
                            if (remainUp > 0)
                                return $.when(getFollowingList(pn + 1, ps), p);
                            else {
                                return p;
                            }
                        } else {
                            return p.reject();
                        }
                    }, () => {
                        return delayCall(() => getFollowingList());
                    })
                }
                let getguardsList=async function(page = 1) {//舰长数据
                    if (page == 1) guardsListdata = [];
                    await Sleep(100)
                    return BAPI.Lottery.anchor.guards(page, 10).then((data) => {
                        guardsListdata = guardsListdata.concat(data.data.list);
                        if (data.data.pageinfo.curPage < data.data.pageinfo.totalPage) return getguardsList(page + 1);
                    }, () => {
                        return delayCall(() => getguardsList());
                    });
                };
                await getguardsList()
                console.log('大航海数据',guardsListdata);
                for (let i=0;i<guardsListdata.length;i++) {
                    guardroom[i]=guardsListdata[i].room_id
                    guard_level[i]=guardsListdata[i].guard_level
                    guardroom_activite[i]=guardsListdata[i].activite
                }
                console.log('大航海房间',guardroom);
                console.log('大航海等级',guard_level);
                console.log('大航海失效判断',guardroom_activite);
                try {
                    localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                }
                try {
                    localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                }
                try {
                    localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                }
                setInterval(async() => {
                    API.CONFIG.medal_ts = ts_ms()
                    API.GsaveConfig();
                    await getguardsList()
                    console.log('大航海数据',guardsListdata);
                    for (let i=0;i<guardsListdata.length;i++) {
                        guardroom[i]=guardsListdata[i].room_id
                        guard_level[i]=guardsListdata[i].guard_level
                        guardroom_activite[i]=guardsListdata[i].activite
                    }
                    console.log('大航海房间',guardroom);
                    console.log('大航海等级',guard_level);
                    console.log('大航海失效判断',guardroom_activite);
                    if(API.CONFIG.Anchor_Followings_switch){
                        await getFollowingList();
                        console.log('关注uid列表',FollowingList);
                    }
                    await getMedalList();
                    console.log('勋章房间数据',medal_list);
                    for (let i=0;i<medal_list.length;i++) {
                        medal_uid_list[i]=medal_list[i].target_id
                    }
                    for (let i=0;i<medal_list.length;i++) {
                        medal_id_list[i]=medal_list[i].medal_id
                    }
                    console.log('勋章uid列表',medal_uid_list);
                    for (let i=0;i<medal_list.length;i++) {
                        await Sleep(100)
                        await BAPI.room.get_info(medal_list[i].roomid).then(async (data) =>{
                            medal_roomid_list[i]=data.data.room_id
                        })
                    }
                    console.log('勋章roomid列表',medal_roomid_list);
                    try {
                        localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_medal_roomid_list`, JSON.stringify({id: medal_roomid_list}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_medal_uid_list`, JSON.stringify({id: medal_uid_list}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_medal_id_list`, JSON.stringify({id: medal_id_list}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_FollowingList`, JSON.stringify({id: FollowingList}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_guardroom`, JSON.stringify({id: guardroom}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_guard_level`, JSON.stringify({id: guard_level}));
                    }
                    try {
                        localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                    } catch (e) {
                        localStorage.setItem(`${NAME}_guardroom_activite`, JSON.stringify({id: guardroom_activite}));
                    }
                },300*1000);

                var id_list = [];
                var XH=0;
                try {
                    let config = JSON.parse(localStorage.getItem(`${NAME}_Anchor_list`));
                    id_list = [].concat(config.list);
                    localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                } catch (e) {
                    localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                    console.log(`${NAME}_Anchor_list读取失败`);
                }
                let get_Anchor_room =async () => { //天选获取房间号
                    if (!API.CONFIG.AUTO_Anchor) return;
                    if (!API.CONFIG.switch_sever) return;
                    if (!API.CONFIG.Anchor_room_get) return;
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) return;
                    API.chatLog(`【天选时刻】正在更新实时榜房间列表......`);
                    let nn=1
                    let Anchor = async function(){
                        if (!API.CONFIG.switch_sever) return;
                        if (API.CONFIG.AUTO_Anchor) {
                            await $.get("https://api.live.bilibili.com/rankdb/v1/Rank2018/getTop?type=master_realtime_hour&type_id=areaid_realtime_hour&area_id="+`${nn}`
                                        , function (data) {
                                let list = data.data.list;// [{id: ,link:}]
                                console.log('获取实时榜房间列表',list);
                                for (let i=0;i<list.length;i++) {
                                    let room=list[i].roomid;
                                    if (id_list.indexOf(room) > -1){
                                        // console.log(`${room}房间号列表已有`);
                                    }else{
                                        id_list.push(room);
                                        // console.log(`${room}房间号列表添加`);
                                        try {
                                            if (id_list.length > API.CONFIG.TOProomnum) {//直播间房间号数量上限
                                                id_list.splice(0, 50);
                                                if(XH>=50){
                                                    XH=XH-50;
                                                }else{
                                                    XH=0
                                                }
                                                API.chatLog(`房间数达到${id_list.length+50},超过设置的上限,移出旧房间-50`, 'warning');
                                            }
                                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                                        } catch (e) {
                                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                                            console.log(`${NAME}_Anchor_list添加数据失败`);
                                        }
                                        //API.chatLog(`【天选时刻】列表新增房间号:${room}`);
                                    }
                                };
                            });
                        }
                    }
                    let Anchor_timer = setInterval(function () {
                        if (nn <= 6) {
                            Anchor();
                            nn++;
                        } else {
                            clearInterval(Anchor_timer);
                        }
                    }, 9*1000);
                };
                setTimeout(get_Anchor_room, 5e3);
                setInterval(get_Anchor_room, 120*1000);


                let get_Anchor_room2 =async () => { //天选获取房间号 方式二
                    if (!API.CONFIG.AUTO_Anchor) return;
                    if (!API.CONFIG.switch_sever) return;
                    if (!API.CONFIG.Anchor_room_get) return;
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) return;
                    API.chatLog(`【天选时刻】正在更新分区推荐房间列表......`);
                    let nn=1
                    let Anchor = async function(){
                        if (!API.CONFIG.switch_sever) return;
                        if (API.CONFIG.AUTO_Anchor) {
                            await $.get(`https://api.live.bilibili.com/room/v3/area/getRoomList?platform=web&parent_area_id=${nn}&page=1&page_size=${API.CONFIG.getroomnum}&tag_version=1`
                                        , function (data) {
                                let list = data.data.list;// [{id: ,link:}]
                                if(list.length==0) return;
                                console.log('获取分区推荐房间列表',list);
                                for (let i=0;i<list.length;i++) {
                                    let room=list[i].roomid;
                                    if (id_list.indexOf(room) > -1){
                                        // console.log(`${room}房间号列表已有`);
                                    }else{
                                        id_list.push(room);
                                        // console.log(`${room}房间号列表添加`);
                                        try {
                                            if (id_list.length > API.CONFIG.TOProomnum) {//直播间房间号数量上限
                                                id_list.splice(0, 50);
                                                if(XH>=50){
                                                    XH=XH-50;
                                                }else{
                                                    XH=0
                                                }
                                                API.chatLog(`房间数达到${id_list.length+50},超过设置的上限,移出旧房间-50`, 'warning');
                                            }
                                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                                        } catch (e) {
                                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                                            console.log(`${NAME}_Anchor_list添加数据失败`);
                                        }
                                        //API.chatLog(`【天选时刻】列表新增房间号:${room}`);
                                    }
                                };
                            });
                        }
                    }
                    let Anchor_timer = setInterval(function () {
                        if (nn <= 11) {
                            Anchor();
                            nn++;
                        } else {
                            clearInterval(Anchor_timer);
                        }
                    }, 7*1000);
                };
                setTimeout(get_Anchor_room2, 5e3);
                setInterval(get_Anchor_room2, 120*1000);

                let check_Anchor_room = async () => { //检查天选
                    if (!API.CONFIG.switch_sever) return;
                    if (API.CONFIG.AUTO_Anchor) {
                        if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) {//判断时间段
                            API.chatLog('当前时间段不检查天选', 'warning');
                            setTimeout(async() => {
                                check_Anchor_room();
                            }, API.CONFIG.AnchorcheckFLASH*1000);
                            return;
                        };
                        API.chatLog('开始轮查直播间天选时刻信息 ', 'success');
                    }else{
                        //API.chatLog('未开启天选时刻抽奖 ', 'warning');
                        return;
                    };
                    if(API.CONFIG.Anchor_always_room_switch){//加入常驻房间列表,开关
                        for (let i=0;i<Anchor_always_room_list.length;i++) {
                            if (id_list.indexOf(Anchor_always_room_list[i]) == -1){
                                id_list.push(Anchor_always_room_list[i]);
                            }
                        }
                        try {
                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_Anchor_list`, JSON.stringify({list: id_list}));
                        }
                    }
                    if(!id_list.length) return;
                    let div = $("<div class='zdbgjMsg'>");
                    let msg = $("<div>");
                    let aa = $("<div>");
                    let bb = $("<div>");
                    let ct = $('#chat-items');
                    let myDate = new Date();
                    div.text(myDate.toLocaleString());
                    div.append(msg);
                    msg.append(aa);
                    msg.append(bb);
                    div.css({
                        'text-align': 'center',
                        'border-radius': '4px',
                        'min-height': '30px',
                        'width': '256px',
                        'color': '#9585FF',
                        'line-height': '30px',
                        'padding': '0 10px',
                        'margin': '10px auto',
                    });
                    msg.css({
                        'word-wrap': 'break-word',
                        'width': '100%',
                        'line-height': '1em',
                        'margin-bottom': '10px',
                    });
                    div.css({
                        'border': '1px solid rgb(203, 195, 255)',
                        'background': 'rgb(233, 230, 255) none repeat scroll 0% 0%',
                    });
                    aa.css({
                        'color': 'blue',
                        'line-height': '20px',
                    });
                    bb.css({
                        'color': 'blue',
                        'line-height': '20px',
                    });
                    if (API.CONFIG.TALK == false) {//自定义提示开关
                        ct.append(div);
                        aa.text(`【天选时刻】循环检查,已耗时秒:`);///共${id_list.length}
                        bb.text(`序号/共,直播房间号:`);
                        let ctt = $('#chat-history-list');
                        ctt.animate({scrollTop: ctt.prop("scrollHeight")}, 0);//滚动到底部
                    }
                    XH=0;
                    let time1= ts_ms();
                    let Anchor = async function(){
                        if (!API.CONFIG.switch_sever) return;
                        await Sleep(API.CONFIG.AnchorFLASH);
                        API.CONFIG.Anchor_ts=ts_ms();
                        API.GsaveConfig();
                        if (XH>=id_list.length) {
                            API.chatLog(`【天选时刻】天选巡检结束,${API.CONFIG.AnchorcheckFLASH}秒后重新开始天选巡检!`, 'success')
                            setTimeout(async() => {
                                check_Anchor_room();
                            }, API.CONFIG.AnchorcheckFLASH*1000);
                            return;
                        }
                        let time2= ts_ms();
                        if(parseInt((time2-time1)/1000)==300-API.CONFIG.AnchorcheckFLASH |parseInt((time2-time1)/1000)== 310-API.CONFIG.AnchorcheckFLASH|parseInt((time2-time1)/1000)==320-API.CONFIG.AnchorcheckFLASH){
                            //API.chatLog(`【天选时刻】请注意【检索耗时+检索间隔≥300秒】,避免漏掉【5分钟的天选】,请开启蹭服务器天选!`, 'warning')
                        }
                        let checkuid=0;
                        if (API.CONFIG.AUTO_Anchor ) {
                            if (API.CONFIG.TALK == false) {//自定义提示开关
                                ct.append(div);//向聊天框加入信息
                            }
                            aa.text(`【天选时刻】循环检查,已耗时${parseInt((time2-time1)/1000)}秒:`);///共${id_list.length}
                            bb.text(`序号${XH+1}/共${id_list.length},直播房间号:${id_list[XH]}`);
                            if (Anchor_ignore_uid.indexOf(String(id_list[XH])) > -1){
                                console.log(`${id_list[XH]}屏蔽的直播间房间号`);
                                API.chatLog(`【天选时刻】${id_list[XH]}屏蔽的直播间房间号,舍弃!`, 'warning')
                                XH++;
                                Anchor();
                                return;
                            }
                            let check_verif=0
                            await BAPI.ajax({url:"//api.live.bilibili.com/room/v1/Room/verify_room_pwd?room_id="+`${id_list[XH]}`}).then(async (data) =>{
                                if(data.code!=0)check_verif=1;
                            })
                            await Sleep(50)
                            if(check_verif){
                                API.chatLog(`【天选时刻】${id_list[XH]}加密的直播间房间号,舍弃!`, 'warning')
                                XH++;
                                Anchor();
                                return;
                            }
                            await BAPI.ajax({url:"xlive/lottery-interface/v1/Anchor/Check?roomid="+`${id_list[XH]}`}).then(async (data) =>{
                                let roomlist_data=data.data;
                                //console.log(`${id_list[XH]},${XH+1}`);
                                //console.log(roomlist_data);
                                if(roomlist_data==null) {
                                    XH++;
                                    Anchor();
                                    return;
                                }else{
                                    let time = Number(roomlist_data.time);
                                    let id = Number(roomlist_data.id);
                                    let gift_price=Number(roomlist_data.gift_price);
                                    let gift_id=Number(roomlist_data.gift_id);
                                    let gift_num=Number(roomlist_data.gift_num);
                                    let require_type=Number(roomlist_data.require_type)
                                    let require_text=roomlist_data.require_text
                                    let award_name=roomlist_data.award_name;
                                    let require_value=Number(roomlist_data.require_value)

                                    if(time<=webmodle_delay){
                                        XH++;
                                        Anchor();
                                        return;
                                    }
                                    if(time>webmodle_delay) {//抽奖时间限定,原因:考虑网络加载等,延迟20秒点击抽奖Anchor_always_room_list
                                        console.log('检查关注',checkuid)
                                        if (done_id_list.indexOf(id) > -1){
                                            console.log(`${id}已参与抽奖的序号id`);
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        done_id_list.push(id);//记录已检测到的抽奖id
                                        if(API.CONFIG.Anchor_room_get_to_always && Anchor_always_room_list.indexOf(id_list[XH]) == -1){
                                            Anchor_always_room_list.push(id_list[XH]);//记录天选房间
                                            try {//保存本地
                                                localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                                                if (Anchor_always_room_list.length >API.CONFIG.Anchor_always_room_num ) {
                                                    API.chatLog(`常驻房间数达到${API.CONFIG.Anchor_always_room_num},超过设置的上限,移出旧房间${Anchor_always_room_list.length-API.CONFIG.Anchor_always_room_num}个`, 'warning');
                                                    Anchor_always_room_list.splice(0, Anchor_always_room_list.length-API.CONFIG.Anchor_always_room_num);
                                                }
                                                localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                                            } catch (e) {
                                                localStorage.setItem(`${NAME}_Anchor_always_room_list`, JSON.stringify({id: Anchor_always_room_list}));
                                                console.log(`${NAME}_Anchor_always_room_list存储失败`);
                                            }
                                        }
                                        try {
                                            localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                            if (done_id_list.length > 1000) {
                                                done_id_list.splice(0, 500);
                                            }
                                            localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                        } catch (e) {
                                            localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                            console.log(`${NAME}_Anchor_done_list存储失败`);
                                        }
                                        console.log(done_id_list);
                                        if(API.CONFIG.switch_sever & room_exist_check){
                                            Anchor_room_list.push(id_list[XH]);
                                            Anchor_award_id_list.push(id);
                                            Anchor_award_name_list.push(award_name);
                                            Anchor_award_gift_id_list.push(gift_id);
                                            Anchor_award_gift_num_list.push(gift_num);
                                            Anchor_award_nowdate.push(ts_ten_m());
                                        }
                                        API.chatLog(`【天选时刻】【${time}秒后开奖】<a href="https://live.bilibili.com/${id_list[XH]}"target="_blank">直播间:${id_list[XH]}</a>,奖品:${award_name},限制条件:${require_text},金瓜子:${gift_num*gift_price}`, 'success')
                                        if(require_type==3 ){//1关注,2粉丝勋章,3大航海:3舰长2提督1总督| console.log('生效大航海房间',guardroom);console.log('生效大航海等级',guard_level);console.log('生效大航海等级',guardroom_activite);
                                            let num=guardroom.indexOf(Number(id_list[XH]))
                                            if(num==-1){
                                                API.chatLog(`【天选时刻】无大航海身份,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                                XH++;
                                                Anchor();
                                                return;
                                            }
                                            if( num>-1 & guardroom_activite[num]==1 & guard_level[num]<=require_value){
                                                console.log('大航海',guardroom[num],guard_level[num],guardroom_activite[num]);
                                            }else{
                                                console.log('大航海',guardroom[num],guard_level[num],guardroom_activite[num]);
                                                API.chatLog(`【天选时刻】大航海身份不符合要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                                XH++;
                                                Anchor();
                                                return;
                                            }
                                        }
                                        if(require_type==4 && Live_info.user_level<require_value){//直播等级
                                            API.chatLog(`【天选时刻】直播等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if(require_type==5 && Live_info.Blever<require_value){//5主站等级Live_info.Blever
                                            API.chatLog(`【天选时刻】主站等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if(require_type>=6){//未知
                                            API.chatLog(`【天选时刻】含有其他要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        let checkmedal=0;
                                        if(require_type==2){//1关注,2粉丝勋章,3舰长
                                            if (need_medal_roomid.indexOf(id_list[XH]) == -1){
                                                need_medal_roomid.push(id_list[XH]);
                                                try {
                                                    localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                }
                                            }
                                            await BAPI.live_user.get_anchor_in_room(id_list[XH]).then(async (data) =>{
                                                let anchor_uid = data.data.info.uid;
                                                if (medal_uid_list.indexOf(anchor_uid) > -1){
                                                    if (medal_list[medal_uid_list.indexOf(anchor_uid)].level < require_value){
                                                        API.chatLog(`【天选时刻】粉丝勋章等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                                        checkmedal=1;
                                                        return;
                                                    }
                                                }else{
                                                    API.chatLog(`【天选时刻】未拥有粉丝勋章,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                                    checkmedal=1;
                                                    return;
                                                }
                                            })
                                            await Sleep(500)
                                        }
                                        if(checkmedal){//勋章检查
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if(gift_price*gift_num>API.CONFIG.gift_price){//金瓜子判断
                                            API.chatLog(`【天选时刻】投喂金瓜子超过过滤设置,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if (Anchor_ignore_keyword.some(v => award_name.toLowerCase().indexOf(v) > -1) | Anchor_ignore_keyword.some(v => require_text.toLowerCase().indexOf(v) > -1)) {
                                            API.chatLog(`【天选时刻】奖品名称或限制条件含有过滤关键词,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${id_list[XH]}" target="_blank">直播间</a>前往`, 'success')
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if(API.CONFIG.Anchor_Followings_switch){//开启只参与关注的主播抽奖
                                            let check_uid = async function (room) {
                                                await BAPI.live_user.get_anchor_in_room(room).then(async (data) =>{
                                                    let anchor_uid = data.data.info.uid;
                                                    if (FollowingList.indexOf(anchor_uid) == -1){//是否为关注判断
                                                        API.chatLog(`不参与非关注主播${anchor_uid}房间${room}的抽奖!`, 'success');
                                                        checkuid=1;
                                                    }
                                                })
                                            }
                                            await check_uid(id_list[XH]);
                                            await Sleep(500)
                                        }
                                        if(checkuid){//开启值参与关注的主播抽奖
                                            XH++;
                                            Anchor();
                                            return;
                                        }
                                        if (done_room_list.indexOf(id_list[XH]) == -1){
                                            done_room_list.push(id_list[XH]);//记录已参加抽奖的房间
                                            done_room_time_list.push(time+ts_s());//记录已参加抽奖的时间
                                            try {//保存本地
                                                localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                            } catch (e) {
                                                localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                console.log(`${NAME}_Anchor_done_room_time_list存储失败`);
                                            }
                                            try {//保存本地
                                                localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                            } catch (e) {
                                                localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                            }
                                        }
                                        if(API.CONFIG.AUTO_lottery_model1){
                                            GM_openInTab('https://live.bilibili.com/' + `${id_list[XH]}?Anchorcut`)
                                            await Sleep(API.CONFIG.webmodledelay)
                                            CZ_delay=1;
                                            setTimeout(() => {
                                                CZ_delay=0
                                            }, 60e3);
                                        }
                                        if(API.CONFIG.AUTO_lottery_model2) {
                                            BAPI.room.room_entry_action(id_list[XH])
                                            BAPI.Lottery.anchor.join(id,gift_id,gift_num).then(async (data) =>{
                                                if(data.code==400 & gift_num*gift_price!=0){
                                                    API.chatLog(`金瓜子余额不足!`, 'success');
                                                }
                                            });
                                        }
                                        API.chatLog(`【天选时刻】正在参与直播间:${id_list[XH]},奖品:${roomlist_data.award_name}的抽奖!`, 'success')
                                        API.CONFIG.COUNT_GOLDBOX++;
                                        API.GsaveConfig();
                                        XH++;
                                        setTimeout(() => {
                                            Anchor();
                                        },1000);
                                    }
                                };
                            }, () => {
                                API.chatLog(`【天选时刻】天选数据获取失败,请检查网络或可能被访问拒绝,2分钟后重试!`, 'warning');
                                return setTimeout(() => {
                                    API.CONFIG.Anchor_ts=ts_ms();
                                    API.GsaveConfig();
                                    Anchor();
                                },2*60*1000);
                            });
                        }
                    }
                    Anchor();
                };
                if((ts_ms() -API.CONFIG.Anchor_ts)>API.CONFIG.AnchorcheckFLASH*1000){//刷新后的巡检间隔判断
                    setTimeout(check_Anchor_room, 10e3);
                    API.CONFIG.Anchor_ts=ts_ms()
                    API.GsaveConfig();
                }else{
                    setTimeout(check_Anchor_room, API.CONFIG.AnchorcheckFLASH*1000-(ts_ms() -API.CONFIG.Anchor_ts));
                }
                setInterval(async function () {//防止意外检索停止
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) return;
                    console.log(`检索运行检查时间标签`,(ts_ms() -API.CONFIG.Anchor_ts),(API.CONFIG.AnchorcheckFLASH*1000+30*1000));
                    if((ts_ms() -API.CONFIG.Anchor_ts)>(API.CONFIG.AnchorcheckFLASH*1000+120*1000)) check_Anchor_room();
                }, API.CONFIG.AnchorcheckFLASH*1000+600000);
                setInterval(async function () {//我为人人,人人为我!自动共享服务器号
                    if(API.CONFIG.switch_sever & room_exist_check){
                        BAPI.postdiscuss2(`${Live_info.room_id}`)
                    }
                }, 30*60*1000);
                setInterval(async function () {//中奖检查
                    if(!API.CONFIG.AUTO_Anchor) return;
                    console.log(`开奖时间标签`,done_room_time_list);
                    console.log(`当前时间标签`,ts_s());
                    if(done_room_list.length!=done_room_time_list.length){
                        API.chatLog(`【中奖检查】中奖检查数据异常,正在清空数据!`, 'warning');
                        done_room_list=[];
                        done_room_time_list=[];
                        try {//保存本地
                            localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                            console.log(`${NAME}_Anchor_done_room_list存储失败`);
                        }
                        try {//保存本地
                            localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                        }
                        return;
                    }
                    if (done_room_list.length > 0){//done_room_time_list
                        for(let i=0,len=done_room_list.length;i<len;i++,len=done_room_list.length){
                            await Sleep(500);
                            if(ts_s()>done_room_time_list[i]){
                                console.log(`时间标签`,done_room_time_list[i]);
                                let Anchor = async function(){
                                    await Sleep(100);
                                    await BAPI.ajax({url:"xlive/lottery-interface/v1/Anchor/Check?roomid="+`${done_room_list[i]}`}).then(async (data) =>{
                                        let roomlist_data=data.data;
                                        if(roomlist_data==null) {
                                            done_room_list.splice(i, 1);
                                            done_room_time_list.splice(i, 1);
                                            i--;
                                            try {//保存本地
                                                localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                            } catch (e) {
                                                localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                            }
                                            try {//保存本地
                                                localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                            } catch (e) {
                                                localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                            }
                                            return;
                                        }else{
                                            let time = Number(roomlist_data.time);
                                            let id = Number(roomlist_data.id);
                                            let gift_price=Number(roomlist_data.gift_price);
                                            let gift_id=Number(roomlist_data.gift_id);
                                            let gift_num=Number(roomlist_data.gift_num);
                                            let require_type=roomlist_data.require_type
                                            let require_text=roomlist_data.require_text
                                            let award_name=roomlist_data.award_name;
                                            let require_value=roomlist_data.require_value
                                            let award_users=roomlist_data.award_users
                                            if(time==0){
                                                for(let p=0;p<award_users.length;p++){
                                                    console.log(`${award_users[p].uid}中奖uid`);
                                                    if(award_users[p].uid==Live_info.uid){
                                                        API.chatLog(`【天选时刻】${Live_info.uname}:恭喜你在<a href="https://live.bilibili.com/${done_room_list[i]}" target="_blank">直播间</a>获得奖品${award_name}!`)
                                                        BAPI.postdiscuss(`${Live_info.uname}:${award_name}`)
                                                        if(API.CONFIG.switch_ServerChan_SCKEY){
                                                            //$.post(`https://sc.ftqq.com/${API.CONFIG.ServerChan_SCKEY}.send?text=【天选众】恭喜你获得奖品${award_name}!`)
                                                            //ServerChan2(API.CONFIG.ServerChan_SCKEY,`[天选众]${Live_info.uname}:恭喜你获得奖品${award_name}!`);
                                                            ServerChan2(API.CONFIG.ServerChan_SCKEY,`[天选众]${Live_info.uname}:恭喜你获得奖品${award_name}(房间号:${done_room_list[i]})!`);
                                                        }
                                                        if (API.CONFIG.anchor_danmu) {
                                                            let ii=Math.ceil(Math.random() * (API.CONFIG.anchor_danmu_content.length))
                                                            BAPI.sendLiveDanmu(API.CONFIG.anchor_danmu_content[ii-1],done_room_list[i])
                                                        }
                                                        if (API.CONFIG.anchor_msg) {
                                                            let anchor_uid
                                                            await BAPI.live_user.get_anchor_in_room(done_room_list[i]).then(async (data) =>{
                                                                anchor_uid = data.data.info.uid;
                                                            })
                                                            let ii=Math.ceil(Math.random() * (API.CONFIG.anchor_msg_content.length))
                                                            setTimeout(() => {
                                                                let send=async function(){
                                                                    const msg = {
                                                                        sender_uid: Live_info.uid,
                                                                        receiver_id: anchor_uid,
                                                                        receiver_type: 1,
                                                                        msg_type: 1,
                                                                        msg_status: 0,
                                                                        content: `{"content":"`+API.CONFIG.anchor_msg_content[ii-1]+`"}`,
                                                                        dev_id: getMsgDevId()
                                                                    }
                                                                    BAPI.sendMsg(msg).then((data) => {
                                                                        console.log('sendMsg',getMsgDevId())
                                                                        console.log('sendMsg',data)
                                                                        if(data.code== -400) return delayCall(() => send());
                                                                    })
                                                                }
                                                                send()
                                                            }, 9000);
                                                        }

                                                    }
                                                }
                                                done_room_list.splice(i, 1);
                                                done_room_time_list.splice(i, 1);
                                                i--;
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                    console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                                }
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                    console.log(`${NAME}_Anchor_done_room_time_list存储失败`);
                                                }
                                                return;
                                            }
                                        };
                                    });
                                }
                                Anchor();
                            }
                        }
                    }
                }, 10e3);

                let pusherr=0
                setInterval(async function () {//推送天选,改为可推送多个天选
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) {//判断时间段
                        return
                    };
                    if(!API.CONFIG.switch_sever) return;
                    console.log('当前本地推送数据',updata)
                    if(updata.length>90){
                        updata.splice(60, updata.length-60);
                        console.log('减少推送数据',updata)
                        try {
                            localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                        } catch (e) {
                            localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                        }
                    }
                    if (Anchor_room_list.length > 0){
                        let title_update = async function () {
                            let len=Anchor_room_list.length;//防止返回检查上传数据的延迟时,误删新加数据
                            for(let ww=0;ww<len;ww++){//去重复
                                if(updata.indexOf(Anchor_award_id_list[ww])>-1) continue;
                                updata.unshift(Anchor_room_list[ww],Anchor_award_id_list[ww],Anchor_award_nowdate[ww]);
                            }
                            try {
                                localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                            } catch (e) {
                                localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                            }
                            let updata_turn=[]
                            for(let t=0;t<updata.length;t++){
                                let str=updata[t]//寅、卯、辰、巳、午、未、申、酉、戌、亥
                                let hhh=str.toString().replace(/0/g, "寅").replace(/1/g, "卯").replace(/2/g, "辰").replace(/3/g, "巳").replace(/4/g, "午").replace(/5/g, "未").replace(/6/g, "申").replace(/7/g, "酉").replace(/8/g, "戌").replace(/9/g, "亥")
                                updata_turn.push(hhh)
                            }
                            BAPI.Lottery.anchor.description_update(`${updata_turn}`,Live_info.room_id)
                            console.log('转换后推送',updata_turn)
                            API.chatLog(`【天选时刻服务器】正在推送新增的天选直播间${len}个!`)
                            await Sleep(2000)
                            //await BAPI.room.get_info(Live_info.room_id).then(async (data) =>{
                            await BAPI.Lottery.anchor.getRoomBaseInfo(Live_info.room_id).then(async (data) =>{
                                //console.log(data.data.by_room_ids[Live_info.room_id].description)
                                let title= data.data.by_room_ids[Live_info.room_id].description;
                                //let title= data.data.description;
                                let valArray_demo = [];
                                valArray_demo = title.split(",");
                                let valArray = [];
                                for(let t=0;t<valArray_demo.length;t++){
                                    let str=valArray_demo[t]
                                    let hhh=str.toString().replace(/寅/g, "0").replace(/卯/g, "1").replace(/辰/g, "2").replace(/巳/g, "3").replace(/午/g, "4").replace(/未/g, "5").replace(/申/g, "6").replace(/酉/g, "7").replace(/戌/g, "8").replace(/亥/g, "9")
                                    valArray.push(hhh)
                                }
                                console.log('服务器数据转换后',valArray)
                                if(updata.indexOf(Number(valArray[1]))>-1) {
                                    console.log('成功推送',updata)
                                    API.chatLog(`【天选时刻服务器】成功推送新增的天选直播间${len}个!`)
                                    Anchor_room_list.splice(0, len);
                                    Anchor_award_id_list.splice(0, len);
                                    Anchor_award_nowdate.splice(0, len);
                                    pusherr=0;
                                }else{
                                    API.chatLog(`【天选时刻服务器】推送天选直播间失败,稍后重试`, 'warning')
                                    pusherr++;
                                    if(pusherr>2){//清空异常数据
                                        Anchor_room_list.splice(0, Anchor_room_list.length);
                                        Anchor_award_id_list.splice(0, Anchor_award_id_list.length);
                                        Anchor_award_nowdate.splice(0, Anchor_award_nowdate.length);
                                        updata.splice(0, updata.length);
                                        try {
                                            localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                                        } catch (e) {
                                            localStorage.setItem(`${NAME}_Anchor_updata`, JSON.stringify({id: updata}));
                                        }
                                        pusherr=0;
                                        API.chatLog(`【天选时刻服务器】推送天选直播间重试失败,清除异常数据`, 'warning')
                                        console.log('清除本地数据',updata)
                                    }
                                }
                            })
                        }
                        title_update();
                    }
                }, 10e3);

                let se=0;
                setInterval(async function () {
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) {//判断时间段
                        return
                    };
                    if(!API.CONFIG.sever_modle) return;
                    if (!API.CONFIG.AUTO_Anchor) return;
                    if(API.CONFIG.sever_room && API.CONFIG.sever_room != Live_info.uid && API.CONFIG.switch_sever_room) {
                        //await BAPI.room.get_info(API.CONFIG.sever_room).then(async (data) =>{
                        await BAPI.Lottery.anchor.getRoomBaseInfo(API.CONFIG.sever_room).then(async (data) =>{
                            //console.log(data.data.by_room_ids[API.CONFIG.sever_room].description)
                            let title= data.data.by_room_ids[API.CONFIG.sever_room].description;
                            //let title= data.data.description;
                            console.log(`0号直播间:${title}`);
                            let valArray_demo = [];
                            valArray_demo = title.split(",");
                            let valArray = [];
                            for(let t=0;t<valArray_demo.length;t++){
                                let str=valArray_demo[t]
                                let hhh=str.toString().replace(/寅/g, "0").replace(/卯/g, "1").replace(/辰/g, "2").replace(/巳/g, "3").replace(/午/g, "4").replace(/未/g, "5").replace(/申/g, "6").replace(/酉/g, "7").replace(/戌/g, "8").replace(/亥/g, "9")
                                valArray.push(hhh)
                            }

                            //API.chatLog(`【天选时刻】正在获取比对0号服务器数据!`)
                            if(isNaN(Number(valArray[0]))|valArray.length<=2) {
                                API.chatLog(`【天选时刻】0号服务器数据格式不符,服务器可能已经关闭,请更换服务器!`)
                                return;
                            }
                            if(Math.abs(ts_ten_m()-Number(valArray[2]))>3 && Math.abs(ts_ten_m()-Number(valArray[2]))<141) {
                                API.chatLog(`【天选时刻】0号服务器超过半小时无更新数据,服务器可能已经关闭,请更换服务器!`)
                                return;
                            }
                            for(;valArray.length>0;valArray.splice(0,3)){
                                await Sleep(100)
                                if(ts_ten_m()-Number(valArray[2])>1 ) {//最新数据超过10分钟,直接结束循环
                                    return;
                                }
                                if (done_id_list.indexOf(Number(valArray[1])) > -1){
                                    console.log(`${valArray[1]}已参与蹭的抽奖的序号id`);
                                    continue;
                                }
                                done_id_list.push(Number(valArray[1]));
                                try {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    if (done_id_list.length > 1000) {
                                        done_id_list.splice(0, 500);
                                    }
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                } catch (e) {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    console.log(`${NAME}_Anchor_done_list存储失败`);
                                }
                                if (Anchor_ignore_uid.indexOf(valArray[0]) > -1){
                                    console.log(`${valArray[0]}屏蔽的直播间房间号`);
                                    API.chatLog(`【天选时刻】${valArray[0]}屏蔽的直播间房间号,舍弃!`)
                                    continue;
                                }
                                let check_verif=0
                                await BAPI.ajax({url:"//api.live.bilibili.com/room/v1/Room/verify_room_pwd?room_id="+`${valArray[0]}`}).then(async (data) =>{
                                    console.log('data.code11',data.code)
                                    if(data.code!=0)check_verif=1;
                                })
                                await Sleep(50)
                                if(check_verif){
                                    API.chatLog(`【天选时刻】${valArray[0]}加密的直播间房间号,舍弃!`, 'warning')
                                    continue;
                                }
                                console.log('data.code22',check_verif)
                                await BAPI.ajax({url:"xlive/lottery-interface/v1/Anchor/Check?roomid="+`${valArray[0]}`}).then(async (data) =>{
                                    let roomlist_data=data.data;
                                    if(roomlist_data==null) {
                                        return;
                                    }else{
                                        let time = Number(roomlist_data.time);
                                        let id = Number(roomlist_data.id);
                                        let gift_price=Number(roomlist_data.gift_price);
                                        let gift_id=Number(roomlist_data.gift_id);
                                        let gift_num=Number(roomlist_data.gift_num);
                                        let require_type=Number(roomlist_data.require_type)
                                        let require_text=roomlist_data.require_text
                                        let award_name=roomlist_data.award_name;
                                        let require_value=Number(roomlist_data.require_value)
                                        if(time<=webmodle_delay){
                                            return;
                                        }
                                        if(time>webmodle_delay) {//抽奖时间限定,原因:考虑网络加载等,延迟20秒点击抽奖
                                            API.chatLog(`【天选时刻】【${time}秒后开奖】${API.CONFIG.sever_room}服务器推送:<a href="https://live.bilibili.com/${valArray[0]}"target="_blank">直播间:${valArray[0]}</a>,奖品:${award_name},限制条件:${require_text},金瓜子:${gift_num*gift_price}`)
                                            if(require_type==3 ){//1关注,2粉丝勋章,3大航海:3舰长2提督1总督| console.log('生效大航海房间',guardroom);console.log('生效大航海等级',guard_level);console.log('生效大航海等级',guardroom_activite);
                                                let num=guardroom.indexOf(Number(valArray[0]))
                                                if(num==-1){
                                                    API.chatLog(`【天选时刻】无大航海身份,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                                if( num>-1 & guardroom_activite[num]==1 & guard_level[num]<=require_value){
                                                    console.log('大航海',guardroom[num],guard_level[num],guardroom_activite[num]);
                                                }else{
                                                    API.chatLog(`【天选时刻】大航海身份不符合要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                            }
                                            if(require_type==4 && Live_info.user_level<require_value){//直播等级
                                                API.chatLog(`【天选时刻】直播等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type==5 && Live_info.Blever<require_value){//5主站等级Live_info.Blever
                                                API.chatLog(`【天选时刻】主站等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type>=6){//未知
                                                API.chatLog(`【天选时刻】含有其他要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkmedal=0;
                                            if(require_type==2){//1关注,2粉丝勋章,3舰长
                                                if (need_medal_roomid.indexOf(valArray[0]) == -1){
                                                    need_medal_roomid.push(valArray[0]);
                                                    try {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    } catch (e) {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    }
                                                }
                                                await BAPI.live_user.get_anchor_in_room(valArray[0]).then(async (data) =>{
                                                    console.log('get_anchor_in_room',data)
                                                    let anchor_uid = data.data.info.uid;
                                                    if (medal_uid_list.indexOf(anchor_uid) > -1){
                                                        if (medal_list[medal_uid_list.indexOf(anchor_uid)].level < require_value){
                                                            API.chatLog(`【天选时刻】粉丝勋章等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                            checkmedal=1;
                                                            return;
                                                        }
                                                    }else{
                                                        API.chatLog(`【天选时刻】未拥有粉丝勋章,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                        checkmedal=1;
                                                        return;
                                                    }
                                                })
                                                await Sleep(500)
                                            }
                                            if(checkmedal){//勋章检查
                                                return;
                                            }
                                            if(gift_price*gift_num>API.CONFIG.gift_price){
                                                API.chatLog(`【天选时刻】投喂金瓜子超过过滤设置,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if (Anchor_ignore_keyword.some(v => award_name.toLowerCase().indexOf(v) > -1) | Anchor_ignore_keyword.some(v => require_text.toLowerCase().indexOf(v) > -1)) {
                                                API.chatLog(`【天选时刻】奖品名称或限制条件含有过滤关键词,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkuid=0;
                                            if(API.CONFIG.Anchor_Followings_switch){//开启只参与关注的主播抽奖
                                                let check_uid = async function (room) {
                                                    await BAPI.live_user.get_anchor_in_room(room).then(async (data) =>{
                                                        let anchor_uid = data.data.info.uid;
                                                        if (FollowingList.indexOf(anchor_uid) == -1){//是否为关注判断
                                                            API.chatLog(`不参与非关注主播${anchor_uid}房间${room}的抽奖!`, 'success');
                                                            checkuid=1;
                                                        }
                                                    })
                                                }
                                                await check_uid(valArray[0]);
                                                await Sleep(500)
                                            }
                                            if(checkuid){//开启只参与关注的主播抽奖
                                                return;
                                            }
                                            if (done_room_list.indexOf(Number(valArray[0])) == -1){
                                                done_room_list.push(Number(valArray[0]));//记录已参加抽奖的房间
                                                done_room_time_list.push(time+ts_s());//记录已参加抽奖的时间
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                    console.log(`${NAME}_Anchor_done_room_time_list存储失败`);
                                                }
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                    console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                                }
                                            }
                                            if(API.CONFIG.AUTO_lottery_model1){
                                                GM_openInTab('https://live.bilibili.com/' + `${valArray[0]}?Anchorcut`)
                                                await Sleep(API.CONFIG.webmodledelay)
                                                CZ_delay=1;
                                                setTimeout(() => {
                                                    CZ_delay=0
                                                }, 60e3);
                                            }
                                            if(API.CONFIG.AUTO_lottery_model2) {
                                                BAPI.room.room_entry_action(Number(valArray[0]))
                                                await Sleep(100)
                                                BAPI.Lottery.anchor.join(id,gift_id,gift_num).then(async (data) =>{
                                                    if(data.code==400 & gift_num*gift_price!=0){
                                                        API.chatLog(`金瓜子余额不足!`);
                                                    }
                                                });
                                            }
                                            API.chatLog(`【天选时刻】正在参与天选众${API.CONFIG.sever_room}服务器推送的直播间:${valArray[0]},奖品:${award_name}的抽奖!`)
                                            API.CONFIG.COUNT_GOLDBOX++;
                                            API.GsaveConfig();
                                        }
                                    };
                                });
                            }
                        });
                    }
                    await Sleep(1000)
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) {//判断时间段
                        return
                    };
                    if(!API.CONFIG.sever_modle) return;
                    if (!API.CONFIG.AUTO_Anchor) return;
                    if(API.CONFIG.sever_room1 && API.CONFIG.sever_room1 != Live_info.uid && API.CONFIG.switch_sever_room1) {
                        // await BAPI.room.get_info(API.CONFIG.sever_room1).then(async (data) =>{
                        //    let title= data.data.description;
                        await BAPI.Lottery.anchor.getRoomBaseInfo(API.CONFIG.sever_room1).then(async (data) =>{
                            //console.log(data.data.by_room_ids[API.CONFIG.sever_room1].description)
                            let title= data.data.by_room_ids[API.CONFIG.sever_room1].description;
                            //let title= data.data.description;
                            console.log(`1号直播间:${title}`);
                            let valArray_demo = [];
                            valArray_demo = title.split(",");
                            let valArray = [];
                            for(let t=0;t<valArray_demo.length;t++){
                                let str=valArray_demo[t]
                                let hhh=str.toString().replace(/寅/g, "0").replace(/卯/g, "1").replace(/辰/g, "2").replace(/巳/g, "3").replace(/午/g, "4").replace(/未/g, "5").replace(/申/g, "6").replace(/酉/g, "7").replace(/戌/g, "8").replace(/亥/g, "9")
                                valArray.push(hhh)
                            }
                            //API.chatLog(`【天选时刻】正在获取比对1号服务器数据!`)
                            if(isNaN(Number(valArray[0]))|valArray.length<=2) {
                                API.chatLog(`【天选时刻】1号服务器数据格式不符,服务器可能已经关闭,请更换服务器!`)
                                return;
                            }
                            if(Math.abs(ts_ten_m()-Number(valArray[2]))>3 && Math.abs(ts_ten_m()-Number(valArray[2]))<141) {
                                API.chatLog(`【天选时刻】1号服务器超过半小时无更新数据,服务器可能已经关闭,请更换服务器!`)
                                return;
                            }
                            for(;valArray.length>0;valArray.splice(0,3)){
                                await Sleep(100)
                                if(ts_ten_m()-Number(valArray[2])>1 ) {//最新数据超过10分钟,直接结束循环
                                    return;
                                }
                                if (done_id_list.indexOf(Number(valArray[1])) > -1){
                                    console.log(`${valArray[1]}已参与蹭的抽奖的序号id`);
                                    continue;
                                }
                                done_id_list.push(Number(valArray[1]));
                                try {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    if (done_id_list.length > 1000) {
                                        done_id_list.splice(0, 500);
                                    }
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                } catch (e) {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    console.log(`${NAME}_Anchor_done_list存储失败`);
                                }

                                if (Anchor_ignore_uid.indexOf(valArray[0]) > -1){
                                    console.log(`${valArray[0]}屏蔽的直播间房间号`);
                                    API.chatLog(`【天选时刻】${valArray[0]}屏蔽的直播间房间号,舍弃!`)
                                    continue;
                                }
                                let check_verif=0
                                await BAPI.ajax({url:"//api.live.bilibili.com/room/v1/Room/verify_room_pwd?room_id="+`${valArray[0]}`}).then(async (data) =>{
                                    console.log('data.code11',data.code)
                                    if(data.code!=0)check_verif=1;
                                })
                                await Sleep(50)
                                if(check_verif){
                                    API.chatLog(`【天选时刻】${valArray[0]}加密的直播间房间号,舍弃!`, 'warning')
                                    continue;
                                }
                                console.log('data.code22',check_verif)
                                await BAPI.ajax({url:"xlive/lottery-interface/v1/Anchor/Check?roomid="+`${valArray[0]}`}).then(async (data) =>{
                                    let roomlist_data=data.data;
                                    if(roomlist_data==null) {
                                        return;
                                    }else{
                                        let time = Number(roomlist_data.time);
                                        let id = Number(roomlist_data.id);
                                        let gift_price=Number(roomlist_data.gift_price);
                                        let gift_id=Number(roomlist_data.gift_id);
                                        let gift_num=Number(roomlist_data.gift_num);
                                        let require_type=Number(roomlist_data.require_type)
                                        let require_text=roomlist_data.require_text
                                        let award_name=roomlist_data.award_name;
                                        let require_value=Number(roomlist_data.require_value)
                                        if(time<=webmodle_delay){
                                            return;
                                        }
                                        if(time>webmodle_delay) {//抽奖时间限定,原因:考虑网络加载等,延迟20秒点击抽奖
                                            API.chatLog(`【天选时刻】【${time}秒后开奖】${API.CONFIG.sever_room1}服务器推送:<a href="https://live.bilibili.com/${valArray[0]}"target="_blank">直播间:${valArray[0]}</a>,奖品:${award_name},限制条件:${require_text},金瓜子:${gift_num*gift_price}`)
                                            if(require_type==3 ){//1关注,2粉丝勋章,3大航海:3舰长2提督1总督| console.log('生效大航海房间',guardroom);console.log('生效大航海等级',guard_level);console.log('生效大航海等级',guardroom_activite);
                                                let num=guardroom.indexOf(Number(valArray[0]))
                                                if(num==-1){
                                                    API.chatLog(`【天选时刻】无大航海身份,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                                if( num>-1 & guardroom_activite[num]==1 & guard_level[num]<=require_value){
                                                    console.log('大航海',guardroom[num],guard_level[num],guardroom_activite[num]);
                                                }else{
                                                    API.chatLog(`【天选时刻】大航海身份不符合要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                            }
                                            if(require_type==4 && Live_info.user_level<require_value){//直播等级
                                                API.chatLog(`【天选时刻】直播等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type==5 && Live_info.Blever<require_value){//5主站等级Live_info.Blever
                                                API.chatLog(`【天选时刻】主站等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type>=6){//未知
                                                API.chatLog(`【天选时刻】含有其他要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkmedal=0;
                                            if(require_type==2){//1关注,2粉丝勋章,3舰长
                                                if (need_medal_roomid.indexOf(valArray[0]) == -1){
                                                    need_medal_roomid.push(valArray[0]);
                                                    try {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    } catch (e) {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    }
                                                }
                                                await BAPI.live_user.get_anchor_in_room(valArray[0]).then(async (data) =>{
                                                    console.log('get_anchor_in_room',data)
                                                    let anchor_uid = data.data.info.uid;
                                                    if (medal_uid_list.indexOf(anchor_uid) > -1){
                                                        if (medal_list[medal_uid_list.indexOf(anchor_uid)].level < require_value){
                                                            API.chatLog(`【天选时刻】粉丝勋章等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                            checkmedal=1;
                                                            return;
                                                        }
                                                    }else{
                                                        API.chatLog(`【天选时刻】未拥有粉丝勋章,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                        checkmedal=1;
                                                        return;
                                                    }
                                                })
                                                await Sleep(500)
                                            }
                                            if(checkmedal){//勋章检查
                                                return;
                                            }
                                            if(gift_price*gift_num>API.CONFIG.gift_price){
                                                API.chatLog(`【天选时刻】投喂金瓜子超过过滤设置,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if (Anchor_ignore_keyword.some(v => award_name.toLowerCase().indexOf(v) > -1) | Anchor_ignore_keyword.some(v => require_text.toLowerCase().indexOf(v) > -1)) {
                                                API.chatLog(`【天选时刻】奖品名称或限制条件含有过滤关键词,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkuid=0;
                                            if(API.CONFIG.Anchor_Followings_switch){//开启只参与关注的主播抽奖
                                                let check_uid = async function (room) {
                                                    await BAPI.live_user.get_anchor_in_room(room).then(async (data) =>{
                                                        let anchor_uid = data.data.info.uid;
                                                        if (FollowingList.indexOf(anchor_uid) == -1){//是否为关注判断
                                                            API.chatLog(`不参与非关注主播${anchor_uid}房间${room}的抽奖!`, 'success');
                                                            checkuid=1;
                                                        }
                                                    })
                                                }
                                                await check_uid(valArray[0]);
                                                await Sleep(500)
                                            }
                                            if(checkuid){//开启只参与关注的主播抽奖
                                                return;
                                            }
                                            if (done_room_list.indexOf(Number(valArray[0])) == -1){
                                                done_room_list.push(Number(valArray[0]));//记录已参加抽奖的房间
                                                done_room_time_list.push(time+ts_s());//记录已参加抽奖的时间
                                                try {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                }
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                    console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                                }
                                            }
                                            if(API.CONFIG.AUTO_lottery_model1){
                                                GM_openInTab('https://live.bilibili.com/' + `${valArray[0]}?Anchorcut`)
                                                await Sleep(API.CONFIG.webmodledelay)
                                                CZ_delay=1;
                                                setTimeout(() => {
                                                    CZ_delay=0
                                                }, 60e3);
                                            }
                                            if(API.CONFIG.AUTO_lottery_model2) {
                                                BAPI.room.room_entry_action(Number(valArray[0]))
                                                await Sleep(100)
                                                BAPI.Lottery.anchor.join(id,gift_id,gift_num).then(async (data) =>{
                                                    if(data.code==400 & gift_num*gift_price!=0){
                                                        API.chatLog(`金瓜子余额不足!`);
                                                    }
                                                });
                                            }
                                            API.chatLog(`【天选时刻】正在参与天选众${API.CONFIG.sever_room1}服务器推送的直播间:${valArray[0]},奖品:${award_name}的抽奖!`)
                                            API.CONFIG.COUNT_GOLDBOX++;
                                            API.GsaveConfig();
                                        }
                                    };
                                });
                            }
                        });
                    }
                    await Sleep(1000)
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) {//判断时间段
                        return
                    };
                    if(!API.CONFIG.sever_modle) return;
                    if (!API.CONFIG.AUTO_Anchor) return;
                    if(Number(API.CONFIG.sever_room2[se]) && Number(API.CONFIG.sever_room2[se]) != Live_info.uid && API.CONFIG.switch_sever_room2) {
                        //await BAPI.room.get_info(API.CONFIG.sever_room2[se]).then(async (data) =>{
                        //    let title= data.data.description;
                        await BAPI.Lottery.anchor.getRoomBaseInfo(API.CONFIG.sever_room2[se]).then(async (data) =>{
                            //console.log(data.data.by_room_ids[API.CONFIG.sever_room2[se]].description)
                            let title= data.data.by_room_ids[API.CONFIG.sever_room2[se]].description;
                            //let title= data.data.description;
                            console.log(`2号直播间${Number(API.CONFIG.sever_room2[se])}:${title}`);
                            let valArray_demo = [];
                            valArray_demo = title.split(",");
                            let valArray = [];
                            for(let t=0;t<valArray_demo.length;t++){
                                let str=valArray_demo[t]
                                let hhh=str.toString().replace(/寅/g, "0").replace(/卯/g, "1").replace(/辰/g, "2").replace(/巳/g, "3").replace(/午/g, "4").replace(/未/g, "5").replace(/申/g, "6").replace(/酉/g, "7").replace(/戌/g, "8").replace(/亥/g, "9")
                                valArray.push(hhh)
                            }
                            //API.chatLog(`【天选时刻】正在获取比对2号服务器数据!`)
                            if(isNaN(Number(valArray[0]))|valArray.length<=2) {
                                API.chatLog(`【天选时刻】2号服务器${Number(API.CONFIG.sever_room2[se])}数据格式不符,服务器可能已经关闭,正在自动换服务器!`)
                                if(se<API.CONFIG.sever_room2.length-1) {
                                    se=se+1;
                                }else if(se==API.CONFIG.sever_room2.length-1) {
                                    se=0;
                                }
                                return;
                            }
                            //if(Number(valArray[0])==0) return;
                            if(Math.abs(ts_ten_m()-Number(valArray[2]))>3 && Math.abs(ts_ten_m()-Number(valArray[2]))<141) {
                                API.chatLog(`【天选时刻】2号服务器${Number(API.CONFIG.sever_room2[se])}超过半小时无更新数据,服务器可能已经关闭,正在自动换服务器!`)
                                if(se<API.CONFIG.sever_room2.length-1) {
                                    se=se+1;
                                }else if(se==API.CONFIG.sever_room2.length-1) {
                                    se=0;
                                }
                                return;
                            }
                            for(;valArray.length>0;valArray.splice(0,3)){
                                await Sleep(100)
                                if(ts_ten_m()-Number(valArray[2])>1 ) {//最新数据超过10分钟,直接结束循环
                                    return;
                                }
                                if (done_id_list.indexOf(Number(valArray[1])) > -1){
                                    console.log(`${valArray[1]}已参与蹭的抽奖的序号id`);
                                    continue;
                                }
                                done_id_list.push(Number(valArray[1]));
                                try {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    if (done_id_list.length > 1000) {
                                        done_id_list.splice(0, 500);
                                    }
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                } catch (e) {
                                    localStorage.setItem(`${NAME}_Anchor_done_list`, JSON.stringify({id: done_id_list}));
                                    console.log(`${NAME}_Anchor_done_list存储失败`);
                                }
                                if (Anchor_ignore_uid.indexOf(valArray[0]) > -1){
                                    console.log(`${valArray[0]}屏蔽的直播间房间号`);
                                    API.chatLog(`【天选时刻】${valArray[0]}屏蔽的直播间房间号,舍弃!`, 'warning')
                                    continue;
                                }
                                let check_verif=0
                                await BAPI.ajax({url:"//api.live.bilibili.com/room/v1/Room/verify_room_pwd?room_id="+`${valArray[0]}`}).then(async (data) =>{
                                    console.log('data.code11',data.code)
                                    if(data.code!=0)check_verif=1;
                                })
                                await Sleep(50)
                                if(check_verif){
                                    API.chatLog(`【天选时刻】${valArray[0]}加密的直播间房间号,舍弃!`, 'warning')
                                    continue;
                                }
                                console.log('data.code22',check_verif)
                                await BAPI.ajax({url:"xlive/lottery-interface/v1/Anchor/Check?roomid="+`${valArray[0]}`}).then(async (data) =>{
                                    let roomlist_data=data.data;
                                    if(roomlist_data==null) {
                                        return;
                                    }else{
                                        let time = Number(roomlist_data.time);
                                        let id = Number(roomlist_data.id);
                                        let gift_price=Number(roomlist_data.gift_price);
                                        let gift_id=Number(roomlist_data.gift_id);
                                        let gift_num=Number(roomlist_data.gift_num);
                                        let require_type=Number(roomlist_data.require_type)
                                        let require_text=roomlist_data.require_text
                                        let award_name=roomlist_data.award_name;
                                        let require_value=Number(roomlist_data.require_value)
                                        if(time<=webmodle_delay){
                                            return;
                                        }
                                        if(time>webmodle_delay) {//抽奖时间限定,原因:考虑网络加载等,延迟20秒点击抽奖
                                            API.chatLog(`【天选时刻】【${time}秒后开奖】${API.CONFIG.sever_room2[se]}服务器推送:<a href="https://live.bilibili.com/${valArray[0]}"target="_blank">直播间:${valArray[0]}</a>,奖品:${award_name},限制条件:${require_text},金瓜子:${gift_num*gift_price}`)
                                            if(require_type==3 ){//1关注,2粉丝勋章,3大航海:3舰长2提督1总督| console.log('生效大航海房间',guardroom);console.log('生效大航海等级',guard_level);console.log('生效大航海等级',guardroom_activite);
                                                let num=guardroom.indexOf(Number(valArray[0]))
                                                if(num==-1){
                                                    API.chatLog(`【天选时刻】无大航海身份,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                                if( num>-1 & guardroom_activite[num]==1 & guard_level[num]<=require_value){
                                                    console.log('大航海',guardroom[num],guard_level[num],guardroom_activite[num]);
                                                }else{
                                                    API.chatLog(`【天选时刻】大航海身份不符合要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                    return;
                                                }
                                            }
                                            if(require_type==4 && Live_info.user_level<require_value){//直播等级
                                                API.chatLog(`【天选时刻】直播等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type==5 && Live_info.Blever<require_value){//5主站等级Live_info.Blever
                                                API.chatLog(`【天选时刻】主站等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if(require_type>=6){//未知
                                                API.chatLog(`【天选时刻】含有其他要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkmedal=0;
                                            if(require_type==2){//1关注,2粉丝勋章,3舰长
                                                if (need_medal_roomid.indexOf(valArray[0]) == -1){
                                                    need_medal_roomid.push(valArray[0]);
                                                    try {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    } catch (e) {
                                                        localStorage.setItem(`${NAME}_need_medal_roomid`, JSON.stringify({id: need_medal_roomid}));
                                                    }
                                                }
                                                await BAPI.live_user.get_anchor_in_room(valArray[0]).then(async (data) =>{
                                                    console.log('get_anchor_in_room',data)
                                                    let anchor_uid = data.data.info.uid;
                                                    if (medal_uid_list.indexOf(anchor_uid) > -1){
                                                        if (medal_list[medal_uid_list.indexOf(anchor_uid)].level < require_value){
                                                            API.chatLog(`【天选时刻】粉丝勋章等级不符要求,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                            checkmedal=1;
                                                            return;
                                                        }
                                                    }else{
                                                        API.chatLog(`【天选时刻】未拥有粉丝勋章,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                        checkmedal=1;
                                                        return;
                                                    }
                                                })
                                                await Sleep(500)
                                            }
                                            if(checkmedal){//勋章检查
                                                return;
                                            }
                                            if(gift_price*gift_num>API.CONFIG.gift_price){
                                                API.chatLog(`【天选时刻】投喂金瓜子超过过滤设置,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            if (Anchor_ignore_keyword.some(v => award_name.toLowerCase().indexOf(v) > -1) | Anchor_ignore_keyword.some(v => require_text.toLowerCase().indexOf(v) > -1)) {
                                                API.chatLog(`【天选时刻】奖品名称或限制条件含有过滤关键词,舍弃,如需参加,请手动点击<a href="https://live.bilibili.com/${valArray[0]}" target="_blank">直播间</a>前往`)
                                                return;
                                            }
                                            let checkuid=0;
                                            if(API.CONFIG.Anchor_Followings_switch){//开启只参与关注的主播抽奖
                                                let check_uid = async function (room) {
                                                    await BAPI.live_user.get_anchor_in_room(room).then(async (data) =>{
                                                        let anchor_uid = data.data.info.uid;
                                                        if (FollowingList.indexOf(anchor_uid) == -1){//是否为关注判断
                                                            API.chatLog(`不参与非关注主播${anchor_uid}房间${room}的抽奖!`, 'success');
                                                            checkuid=1;
                                                        }
                                                    })
                                                }
                                                await check_uid(valArray[0]);
                                                await Sleep(500)
                                            }
                                            if(checkuid){//开启只参与关注的主播抽奖
                                                return;
                                            }
                                            if (done_room_list.indexOf(Number(valArray[0])) == -1){
                                                done_room_list.push(Number(valArray[0]));//记录已参加抽奖的房间
                                                done_room_time_list.push(time+ts_s());//记录已参加抽奖的时间
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_time_list`, JSON.stringify({id: done_room_time_list}));
                                                    console.log(`${NAME}_Anchor_done_room_time_list存储失败`);
                                                }
                                                try {//保存本地
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                } catch (e) {
                                                    localStorage.setItem(`${NAME}_Anchor_done_room_list`, JSON.stringify({id: done_room_list}));
                                                    console.log(`${NAME}_Anchor_done_room_list存储失败`);
                                                }
                                            }
                                            if(API.CONFIG.AUTO_lottery_model1){
                                                GM_openInTab('https://live.bilibili.com/' + `${valArray[0]}?Anchorcut`)
                                                await Sleep(API.CONFIG.webmodledelay)
                                                CZ_delay=1;
                                                setTimeout(() => {
                                                    CZ_delay=0
                                                }, 60e3);
                                            }
                                            if(API.CONFIG.AUTO_lottery_model2) {
                                                BAPI.room.room_entry_action(Number(valArray[0]))
                                                await Sleep(100)
                                                BAPI.Lottery.anchor.join(id,gift_id,gift_num).then(async (data) =>{
                                                    if(data.code==400 & gift_num*gift_price!=0){
                                                        API.chatLog(`金瓜子余额不足!`);
                                                    }
                                                });
                                            }
                                            API.chatLog(`【天选时刻】正在参与天选众${API.CONFIG.sever_room2[se]}服务器推送的直播间:${valArray[0]},奖品:${award_name}的抽奖!`)
                                            API.CONFIG.COUNT_GOLDBOX++;
                                            API.GsaveConfig();
                                        }
                                    };
                                });
                            }
                        });
                    }
                }, API.CONFIG.AnchorserverFLASH*1000);

                let Refresh_time1=ts_ms();
                let OldCZ=API.CONFIG.CZ;
                setInterval(function () {
                    if (inTimeArea(API.CONFIG.TIMEAREASTART, API.CONFIG.TIMEAREAEND) && API.CONFIG.TIMEAREADISABLE) return;//不抽奖时间段不刷新
                    if (Anchor_room_list.length > 0) return;//有待推送数据不刷新
                    if (CZ_delay==1) return;//有待参与抽奖不刷新
                    if (medal_sign==1) return;//正在打卡不刷新
                    let Refresh_time2=ts_ms();
                    if((Refresh_time2-Refresh_time1)>API.CONFIG.CZ * 60000 ) {
                        API.chatLog('约定之期已到√√√√,5秒后刷新系统','warning')
                        setTimeout(() => {
                            window.location.reload();
                        }, 5e3);
                    }
                    if(OldCZ!=API.CONFIG.CZ) {
                        Refresh_time1=ts_ms();
                        OldCZ=API.CONFIG.CZ
                    }
                }, 30e3);
            }
    }
    let Anchorcut = window.location.href.indexOf('Anchorcut') > -1;//MaterialObject
    let MaterialObject = window.location.href.indexOf('MaterialObject') > -1;
    if (Anchorcut) {
        try {
            const originFetch = unsafeWindow.fetch;
            unsafeWindow.fetch = (...arg) => {
                console.log('fetch arg', ...arg);
                if (arg[0].indexOf('bilivideo.com') > -1) {
                    console.log('拦截直播流');
                    return new Promise(() => {
                        throw new Error();
                    });
                } else {
                    console.log('通过');
                    return originFetch(...arg);
                }
            }
        } catch (err) {
            console.error(`[${NAME}]`, err);
        }
        // Mute a singular HTML5 element
        function muteMe(elem) {
            elem.muted = true;
            // elem.pause();
        }

        // Try to mute all video and audio elements on the page
        function mutePage() {
            var videos = document.querySelectorAll("video"),
                audios = document.querySelectorAll("audio");

            [].forEach.call(videos, function(video) { muteMe(video); });
            [].forEach.call(audios, function(audio) { muteMe(audio); });
        }
        setTimeout(() => {
            $("iframe").contents().find(".btn-name").click();
            $("iframe").contents().find("iframe").contents().find(".btn-name").click();
        }, 20000);
        setTimeout(() => {
            window.close();
        }, 30000);

    }
    if (MaterialObject) {
        setTimeout(() => {
            $(".bl-button.bl-button--primary.bl-button--size").click();
        }, 20000);
        setTimeout(() => {
            window.close();
        }, 30000);

    }

    let fansfollow = window.location.href.indexOf('fans') > -1 && window.location.href.indexOf('follow')> -1;
    if (fansfollow) {
        var left=$(window).width()/2
        let btn = $(`<button style="position: absolute;top:350px;left: ${left}px;z-index:99;background-color:Gainsboro;color:#FF34B3;
border-radius: 4px;border: none;padding: 5px;cursor: pointer;">取关当前分组当前列表</button>`);
        $('body').append(btn);
        btn.click(function () {
            var r=confirm("点击确定,取关当前分组当前列表!");
            if (r==true){
                let uf = $(".be-dropdown-item:contains('取消关注')")
                let l = uf.length;
                for (let i = 0; i < l; i++) {
                    setTimeout(() => uf[i].click(), i * 200)
                }
            }
        });
    }

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

    /**
 * (2,10) 当前是否在两点到十点之间
 * @param a 整数 起始时间
 * @param b 整数 终止时间
 * @returns {boolean}
 */
    function inTimeArea(a, b) {
        if (a > b || a > 23 || b > 24 || a < 0 || b < 1) {
            //console.log('错误时间段');
            return false
        }
        let myDate = new Date();
        let h = myDate.getHours();
        return h >= a && h < b
    }

    /**
 * 概率
 * @param val
 * @returns {boolean}
 */
    function probability(val) {
        if (val <= 0) return false;
        let rad = Math.ceil(Math.random() * 100);
        return val >= rad
    }

    const dateNow = () => Date.now();

    /**
 * 检查是否为新一天
 * @param ts
 * @returns {boolean}
 */
    const checkNewDay = (ts) => {
        if (ts === 0) return true;
        let t = new Date(ts);
        let d = new Date();
        let td = t.getDate();
        let dd = d.getDate();
        return (dd !== td);
    }

    function Do_follow(id,act) {//1关,2取
        $.ajax({
            url: '//api.bilibili.com/x/relation/modify',
            type: "post",
            xhrFields: {
                withCredentials: true
            },
            data: {
                'fid': id,
                'act': act,
                're_src': 11,
                'jsonp': 'jsonp',
                'csrf': Live_info.csrf_token
            }
        })
    }

    function ServerChan2(id,text) {
        return XHR({
            GM: true,
            anonymous: true,
            method: 'POST',
            url: `https://sc.ftqq.com/${id}.send?`,
            responseType: 'json',
            data: encodeURI(`text=${text}`)
        })
    }
    /**
     * 获取msg[dev_id]
     * @param name
     * @returns {String} dev_id
     */
    function getMsgDevId(name = NAME) {
        let deviceid = window.localStorage.getItem("im_deviceid_".concat(name));
        if (!name || !deviceid) {
            let str = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function (name) {
                let randomInt = 16 * Math.random() | 0;
                return ("x" === name ? randomInt : 3 & randomInt | 8).toString(16).toUpperCase()
            }
                                                                              ));
            return function (name, randomInt) {
                Object.keys(localStorage).forEach((function (name) {
                    name.match(/^im_deviceid_/) && window.localStorage.removeItem(name)
                }
                                                  )),
                    window.localStorage.setItem("im_deviceid_".concat(randomInt), name)
            }(str, name),
                str
        }
        return deviceid
    };
    function getvisit_id(name = NAME) {
        let str = "xxxxxxxxxxxx".replace(/[x]/g, (function (name) {
            let randomInt = 16 * Math.random() | 0;
            return ("x" === name ? randomInt : 3 & randomInt | 8).toString(16).toLowerCase()
        }))
        return str
    };
    function XHR(XHROptions) {
        return new Promise(resolve => {
            const onerror = (error) => {
                console.error(GM_info.script.name, error);
                resolve(undefined);
            };
            if (XHROptions.GM) {
                if (XHROptions.method === 'POST') {
                    if (XHROptions.headers === undefined)
                        XHROptions.headers = {};
                    if (XHROptions.headers['Content-Type'] === undefined)
                        XHROptions.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
                }
                XHROptions.timeout = 30 * 1000;
                XHROptions.onload = res => resolve({ response: res, body: res.response });
                XHROptions.onerror = onerror;
                XHROptions.ontimeout = onerror;
                GM_xmlhttpRequest(XHROptions);
            }
            else {
                const xhr = new XMLHttpRequest();
                xhr.open(XHROptions.method, XHROptions.url);
                if (XHROptions.method === 'POST' && xhr.getResponseHeader('Content-Type') === null)
                    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
                if (XHROptions.cookie)
                    xhr.withCredentials = true;
                if (XHROptions.responseType !== undefined)
                    xhr.responseType = XHROptions.responseType;
                xhr.timeout = 30 * 1000;
                xhr.onload = ev => {
                    const res = ev.target;
                    resolve({ response: res, body: res.response });
                };
                xhr.onerror = onerror;
                xhr.ontimeout = onerror;
                xhr.send(XHROptions.data);
            }
        });
    }

    /**
     * 保存文件到本地
     * @param fileName 文件名
     * @param fileContent 文件内容
     */
    function downFile(fileName, fileContent) {
        let elementA = document.createElement("a");
        elementA.setAttribute(
            "href",
            "data:text/plain;charset=utf-8," + JSON.stringify(fileContent)
        );
        elementA.setAttribute("download", fileName);
        elementA.style.display = "none";
        document.body.appendChild(elementA);
        elementA.click();
        document.body.removeChild(elementA);
    }
    /**
     * 导出配置文件
     * @param MY_API MY_API
     * @param nosleepConfig noSleep
     * @param INVISIBLE_ENTER_config invisibleEnter
     */
    function exportConfig(MY_API) {
        return downFile('ZDBGJ_CONFIG.json', MY_API);
    }
    /**
     * 导入配置文件
     */


    function ArrayIsEqual(arr1,arr2){//判断2个数组是否相等
        if(arr1===arr2){//如果2个数组对应的指针相同,那么肯定相等,同时也对比一下类型
            return true;
        }else{
            if(arr1.length!=arr2.length){
                return false;
            }else{//长度相同
                for(let i in arr1){//循环遍历对比每个位置的元素
                    if(arr1[i]!=arr2[i]){//只要出现一次不相等,那么2个数组就不相等
                        return false;
                    }
                }//for循环完成,没有出现不相等的情况,那么2个数组相等
                return true;
            }
        }
    }
    const chatLog=function (text, type = 'info') {//自定义提示
        let div = $("<div class='zdbgjMsg'>");
        let msg = $("<div>");
        let ct = $('#chat-items');
        let myDate = new Date();
        msg.text(text);
        div.text(myDate.toLocaleString());
        div.append(msg);
        div.css({
            'text-align': 'center',
            'border-radius': '4px',
            'min-height': '30px',
            'width': '256px',
            'color': 'rgb(218, 142, 36)',
            'line-height': '30px',
            'padding': '0 10px',
            'margin': '10px auto',
            'border': '1px solid rgb(203, 195, 255)',
            'background': 'rgb(233, 230, 255) none repeat scroll 0% 0%',
        });
        msg.css({
            'word-wrap': 'break-word',
            'width': '100%',
            'line-height': '1em',
            'margin-bottom': '10px',
        });
        ct.append(div);//向聊天框加入信息
        let ctt = $('#chat-history-list');
        ctt.animate({scrollTop: ctt.prop("scrollHeight")}, 0);//滚动到底部
    }
    /**
 * SeaLoong BilibiliAPI https://github.com/SeaLoong/BLRHH
 */
    let csrf_token, visit_id;
    var BilibiliAPI = {
        setCommonArgs: (csrfToken = '', visitId = '') => {
            csrf_token = csrfToken;
            visit_id = getvisit_id();
        },
        // 整合常用API
        wear_medal: (i) => BilibiliAPI.ajaxWithCommonArgs({
            method: "POST",
            url: "xlive/web-room/v1/fansMedal/wear",
            data: {
                medal_id: i,
            }
        }),
        link_group: {
            my_groups: () => BilibiliAPI.ajax({
                url: "link_group/v1/member/my_groups"
            }),
            sign_in: (i, e) => BilibiliAPI.ajax({
                url: "link_setting/v1/link_setting/sign_in",
                data: {
                    group_id: i,
                    owner_id: e
                }
            }),
            buy_medal: (i, e = "metal", a = "android") => BilibiliAPI.ajaxWithCommonArgs({
                method: "POST",
                url: "//api.vc.bilibili.com/link_group/v1/member/buy_medal",
                data: {
                    master_uid: i,
                    coin_type: e,
                    platform: a
                }
            })
        },
        DailyReward: {
            login: () => BilibiliAPI.x.now(),
            share: i => BilibiliAPI.x.share_add(i),
            watch: (i, e, a, t, l, r, o, n, s) => BilibiliAPI.x.heartbeat(i, e, a, t, l, r, o, n, s),

        },
        x: {
            getUserSpace: (i, e, a, t, l, r, o) => BilibiliAPI.ajax({
                url: "//api.bilibili.com/x/space/arc/search",
                data: {
                    mid: i,
                    ps: e,
                    tid: a,
                    pn: t,
                    keyword: l,
                    order: r,
                    jsonp: o
                }
            }),
            heartbeat: (i, e, a, t, l = 0, r = 0, o = 3, n = 1, s = 2) => BilibiliAPI.ajaxWithCommonArgs({
                method: "POST",
                url: "//api.bilibili.com/x/report/web/heartbeat",
                data: {
                    aid: i,
                    cid: e,
                    mid: a,
                    start_ts: t || Date.now() / 1e3,
                    played_time: l,
                    realtime: r,
                    type: o,
                    play_type: n,
                    dt: s
                }
            }),
            share_add: i => BilibiliAPI.ajaxWithCommonArgs({
                method: "POST",
                url: "//api.bilibili.com/x/web-interface/share/add",
                data: {
                    aid: i,
                    jsonp: "jsonp"
                }
            }),
            now: () => BilibiliAPI.ajax({
                url: "//api.bilibili.com/x/report/click/now",
                data: {
                    jsonp: "jsonp"
                }
            })
        },
        dynamic_svr: {
            dynamic_new: (i, e = 8) => BilibiliAPI.ajax({
                url: "dynamic_svr/v1/dynamic_svr/dynamic_new",
                data: {
                    uid: i,
                    type: e
                }
            }),
            space_history: (i, e, a, t) => BilibiliAPI.ajax({
                url: "dynamic_svr/v1/dynamic_svr/space_history",
                data: {
                    visitor_uid: i,
                    host_uid: e,
                    offset_dynamic_id: a,
                    need_top: t
                }
            })
        },
        Exchange: {
            silver2coin: (platform) => BilibiliAPI.pay.silver2coin(platform),
        },
        Lottery: {
            MaterialObject: {
                getRoomActivityByRoomid: (roomid) => BilibiliAPI.lottery.box.getRoomActivityByRoomid(roomid),
                getStatus: (aid, times) => BilibiliAPI.lottery.box.getStatus(aid, times),
                draw: (aid, number) => BilibiliAPI.lottery.box.draw(aid, number),
                getWinnerGroupInfo: (aid, number) => BilibiliAPI.lottery.box.getWinnerGroupInfo(aid, number)
            },
            anchor: {
                join: (id,gift_id, gift_num,t = "pc") => {
                    var data = {
                        id: id,
                        platform: t
                    };
                    if (gift_id !== undefined && gift_num !== undefined && gift_id !== 0) {
                        data.gift_id = gift_id;
                        data.gift_num = gift_num;
                    };
                    return BilibiliAPI.ajaxWithCommonArgs({
                        method: "POST",
                        url: "xlive/lottery-interface/v1/Anchor/Join",
                        data: data
                    })
                },
                title_update: (anchor_list,room_id) => {
                    var data = {
                        room_id:room_id,
                        title:anchor_list,
                        platform:"pc",
                        csrf_token:csrf_token,
                        csrf:csrf_token,
                        visit_id:getvisit_id(),
                    };
                    BilibiliAPI.ajaxWithCommonArgs({
                        method: "POST",
                        url: "/room/v1/Room/update",
                        data: data
                    })
                },
                description_update: (anchor_list,room_id) => {
                    var data = {
                        room_id:room_id,
                        description:anchor_list,
                        csrf_token:csrf_token,
                        csrf:csrf_token,
                    };
                    BilibiliAPI.ajaxWithCommonArgs({
                        method: "POST",
                        url: "/room/v1/Room/update",
                        data: data
                    })
                },
                uid_room:(uid) => {
                    var data = {
                        mid:uid,
                    };
                    BilibiliAPI.ajaxWithCommonArgs({
                        method: "get",
                        url: "/x/space/acc/info",
                        data: data
                    })
                },
                medal: (i = 1, e = 10) => BilibiliAPI.ajax({
                    url: "i/api/medal",
                    data: {
                        page: i,
                        pageSize: e
                    }
                }),
                guards: (i = 1, e = 10) => BilibiliAPI.ajax({
                    url: "xlive/web-ucenter/user/guards",
                    data: {
                        page: i,
                        page_size: e
                    }
                }),
                getFollowings: (i, e = 1, a = 20, t = "desc", l = "jsonp", r = "") => BilibiliAPI.ajax({
                    url: "//api.bilibili.com/x/relation/followings",
                    data: {
                        vmid: i,
                        pn: e,
                        ps: a,
                        order: t,
                        jsonp: l,
                        callback: r
                    }
                }),
                getRoomBaseInfo: (i, e = "link-center") => BilibiliAPI.ajax({
                url: "xlive/web-room/v1/index/getRoomBaseInfo",
                data: {
                room_ids: i,
                req_biz: e
            }
        }),
        getUserInfo: i => BilibiliAPI.ajax({
        url: "User/getUserInfo?ts=" + i
    }),
},
               },
               // ajax调用B站API
               runUntilSucceed: (callback, delay = 0, period = 50) => {
    setTimeout(() => {
        if (!callback()) BilibiliAPI.runUntilSucceed(callback, period, period);
    }, delay);
},
    processing: 0,
        ajax: (settings) => {
            if (settings.xhrFields === undefined) settings.xhrFields = {};
            settings.xhrFields.withCredentials = true;
            jQuery.extend(settings, {
                url: (settings.url.substr(0, 2) === '//' ? '' : '//api.live.bilibili.com/') + settings.url,
                method: settings.method || 'GET',
                crossDomain: true,
                dataType: settings.dataType || 'json'
            });
            const p = jQuery.Deferred();
            BilibiliAPI.runUntilSucceed(() => {
                if (BilibiliAPI.processing > 8) return false;
                ++BilibiliAPI.processing;
                return jQuery.ajax(settings).then((arg1, arg2, arg3) => {
                    --BilibiliAPI.processing;
                    p.resolve(arg1, arg2, arg3);
                    return true;
                }, (arg1, arg2, arg3) => {
                    --BilibiliAPI.processing;
                    p.reject(arg1, arg2, arg3);
                    return true;
                });
            });
            return p;
        },
            ajaxWithCommonArgs: (settings) => {
                if (!settings.data) settings.data = {};
                settings.data.csrf = csrf_token;
                settings.data.csrf_token = csrf_token;
                settings.data.visit_id = getvisit_id();
                return BilibiliAPI.ajax(settings);
            },
                // 以下按照URL分类
                gift: {
                    bag_list: () => {
                        // 获取包裹礼物列表
                        return BilibiliAPI.ajax({
                            url: 'gift/v2/gift/bag_list'
                        });
                    },
                        send: (uid, gift_id, ruid, gift_num, biz_id, rnd, coin_type = 'silver', platform = 'pc', biz_code = 'live', storm_beat_id = 0, price = 0) => {
                            // 消耗瓜子送礼
                            return BilibiliAPI.ajaxWithCommonArgs({
                                method: 'POST',
                                url: 'gift/v2/gift/send',
                                data: {
                                    uid: uid,
                                    gift_id: gift_id,
                                    ruid: ruid,
                                    gift_num: gift_num,
                                    coin_type: coin_type,
                                    bag_id: 0,
                                    platform: platform,
                                    biz_code: biz_code,
                                    biz_id: biz_id, // roomid
                                    rnd: rnd,
                                    storm_beat_id: storm_beat_id,
                                    metadata: '',
                                    price: price
                                }
                            });
                        },
                            bag_send: (uid, gift_id, ruid, gift_num, bag_id, biz_id, rnd, platform = 'pc', biz_code = 'live', storm_beat_id = 0, price = 0) => {
                                // 送出包裹中的礼物
                                return BilibiliAPI.ajaxWithCommonArgs({
                                    method: 'POST',
                                    url: 'gift/v2/live/bag_send',
                                    data: {
                                        uid: uid,
                                        gift_id: gift_id,
                                        ruid: ruid,
                                        gift_num: gift_num,
                                        bag_id: bag_id,
                                        platform: platform,
                                        biz_code: biz_code,
                                        biz_id: biz_id, // roomid
                                        rnd: rnd,
                                        storm_beat_id: storm_beat_id,
                                        metadata: '',
                                        price: price
                                    }
                                });
                            },
                },

                    live_user: {
                        get_anchor_in_room: (roomid) => {
                            return BilibiliAPI.ajax({
                                url: 'live_user/v1/UserInfo/get_anchor_in_room?roomid=' + roomid
                            });
                        },
                            get_info_in_room: i => BilibiliAPI.ajax({
                                url: "live_user/v1/UserInfo/get_info_in_room?roomid=" + i
                            }),
                    },
                        pay: {
                            silver2coin: (platform = 'pc') => {
                                // 银瓜子兑换硬币,700银瓜子=1硬币
                                return BilibiliAPI.ajaxWithCommonArgs({
                                    method: 'POST',
                                    url: 'pay/v1/Exchange/silver2coin',
                                    data: {
                                        platform: platform
                                    }
                                });
                            }
                        },
                            lottery: {
                                box: {
                                    getRoomActivityByRoomid: (roomid) => {
                                        // 获取房间特有的活动 (实物抽奖)
                                        return BilibiliAPI.ajax({
                                            url: 'lottery/v1/box/getRoomActivityByRoomid?roomid=' + roomid
                                        });
                                    },
                                        getStatus: (aid, times = '') => {
                                            // 获取活动信息/状态
                                            return BilibiliAPI.ajax({
                                                url: 'xlive/lottery-interface/v2/Box/getStatus',
                                                data: {
                                                    aid: aid,
                                                    times: times
                                                }
                                            });
                                        },
                                            draw: (aid, number = 1) => {
                                                // 参加实物抽奖
                                                return BilibiliAPI.ajax({
                                                    url: 'xlive/lottery-interface/v2/Box/draw',
                                                    data: {
                                                        aid: aid,
                                                        number: number
                                                    }
                                                });
                                            },
                                                getWinnerGroupInfo: (aid, number = 1) => {
                                                    // 获取中奖名单
                                                    return BilibiliAPI.ajax({
                                                        url: 'xlive/lottery-interface/v2/Box/getWinnerGroupInfo',
                                                        data: {
                                                            aid: aid,
                                                            number: number
                                                        }
                                                    });
                                                }
                                },
                            },

                                room: {
                                    get_info: (room_id, from = 'room') => {
                                        return BilibiliAPI.ajax({
                                            url: 'room/v1/Room/get_info',
                                            data: {
                                                room_id: room_id,
                                                from: from
                                            }
                                        });
                                    },
                                        room_entry_action: (room_id, platform = 'pc') => {
                                            return BilibiliAPI.ajaxWithCommonArgs({
                                                method: 'POST',
                                                url: 'room/v1/Room/room_entry_action',
                                                data: {
                                                    room_id: room_id,
                                                    platform: platform
                                                }
                                            });
                                        },
                                },

                                    /**
* 发送直播弹幕
* @param msg
* @param roomid
*/
                                    sendLiveDanmu: (msg, roomid) => {
                                        let ndate = new Date();
                                        return BilibiliAPI.ajaxWithCommonArgs({
                                            method: 'POST',
                                            url: 'msg/send',
                                            data: {
                                                color: '16777215',
                                                fontsize: '25',
                                                mode: '1',
                                                msg: msg,
                                                rnd: ndate.getTime(),
                                                roomid: roomid,
                                                bubble: '0'

                                            }
                                        });
                                    },
                                        postdiscuss: (discuss) => {//天选中奖公告
                                            return BilibiliAPI.ajax({
                                                method: 'POST',
                                                url: '//api.bilibili.com/x/v2/reply/add',
                                                data: {
                                                    oid: '8685835',
                                                    type: '12',
                                                    message: discuss,
                                                    plat: '1',
                                                    ordering: 'time',
                                                    jsonp: 'jsonp',
                                                    csrf:csrf_token,
                                                }
                                            });
                                        },
                                            postdiscuss2: (discuss) => {//天选服务器共享
                                                return BilibiliAPI.ajax({
                                                    method: 'POST',
                                                    url: '//api.bilibili.com/x/v2/reply/add',
                                                    data: {
                                                        oid: '9203571',
                                                        type: '12',
                                                        message: discuss,
                                                        plat: '1',
                                                        ordering: 'time',
                                                        jsonp: 'jsonp',
                                                        csrf:csrf_token,
                                                    }
                                                });
                                            },
                                                sendMsg: (msg) =>{
                                                    return BilibiliAPI.ajax({
                                                        method: "POST",
                                                        url: "//api.vc.bilibili.com/web_im/v1/web_im/send_msg ",
                                                        data: {
                                                            "msg[sender_uid]": msg.sender_uid,
                                                            "msg[receiver_id]": msg.receiver_id,
                                                            "msg[receiver_type]": msg.receiver_type,
                                                            "msg[msg_type]":msg.msg_type,
                                                            "msg[msg_status]": msg.msg_status,
                                                            "msg[content]": msg.content,
                                                            "msg[timestamp]": ts_s(),
                                                            "msg[dev_id]": msg.dev_id,
                                                            build: 0,
                                                            mobi_app: "web",
                                                            csrf_token:csrf_token,
                                                            csrf:csrf_token,
                                                        }
                                                    })
                                                },

                                                    /**
    * 获取cookie
    * @param name
    * @returns cookie {string|boolean}
    */
                                                    getCookie: (name) => {
                                                        let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
                                                        if (arr != null) return unescape(arr[2]);
                                                        return false;
                                                    }
                    }
})();
/**
https://github.com/turuslan/HackTimer 删减
*/
(function (workerScript) {
    try {
        var blob = new Blob (["\
var fakeIdToId = {};\
onmessage = function (event) {\
var data = event.data,\
name = data.name,\
fakeId = data.fakeId,\
time;\
if(data.hasOwnProperty('time')) {\
time = data.time;\
}\
switch (name) {\
case 'setTimeout':\
fakeIdToId[fakeId] = setTimeout(function () {\
postMessage({fakeId: fakeId});\
if (fakeIdToId.hasOwnProperty (fakeId)) {\
delete fakeIdToId[fakeId];\
}\
}, time);\
break;\
case 'clearTimeout':\
if (fakeIdToId.hasOwnProperty (fakeId)) {\
clearTimeout(fakeIdToId[fakeId]);\
delete fakeIdToId[fakeId];\
}\
break;\
}\
}\
"]);
        // Obtain a blob URL reference to our worker 'file'.
        workerScript = window.URL.createObjectURL(blob);
    } catch (error) {
        /* Blob is not supported, use external script instead */
    }
    var worker,
        fakeIdToCallback = {},
        lastFakeId = 0,
        maxFakeId = 0x7FFFFFFF, // 2 ^ 31 - 1, 31 bit, positive values of signed 32 bit integer
        logPrefix = 'HackTimer.js by turuslan: ';
    if (typeof (Worker) !== 'undefined') {
        function getFakeId () {
            do {
                if (lastFakeId == maxFakeId) {
                    lastFakeId = 0;
                } else {
                    lastFakeId ++;
                }
            } while (fakeIdToCallback.hasOwnProperty (lastFakeId));
            return lastFakeId;
        }
        try {
            worker = new Worker (workerScript);
            window.setTimeout = function (callback, time /* , parameters */) {
                var fakeId = getFakeId ();
                fakeIdToCallback[fakeId] = {
                    callback: callback,
                    parameters: Array.prototype.slice.call(arguments, 2),
                    isTimeout: true
                };
                worker.postMessage ({
                    name: 'setTimeout',
                    fakeId: fakeId,
                    time: time
                });
                return fakeId;
            };
            window.clearTimeout = function (fakeId) {
                if (fakeIdToCallback.hasOwnProperty(fakeId)) {
                    delete fakeIdToCallback[fakeId];
                    worker.postMessage ({
                        name: 'clearTimeout',
                        fakeId: fakeId
                    });
                }
            };
            worker.onmessage = function (event) {
                var data = event.data,
                    fakeId = data.fakeId,
                    request,
                    parameters,
                    callback;
                if (fakeIdToCallback.hasOwnProperty(fakeId)) {
                    request = fakeIdToCallback[fakeId];
                    callback = request.callback;
                    parameters = request.parameters;
                    if (request.hasOwnProperty ('isTimeout') && request.isTimeout) {
                        delete fakeIdToCallback[fakeId];
                    }
                }
                if (typeof (callback) === 'string') {
                    try {
                        callback = new Function (callback);
                    } catch (error) {
                        console.log (logPrefix + 'Error parsing callback code string: ', error);
                    }
                }
                if (typeof (callback) === 'function') {
                    callback.apply (window, parameters);
                }
            };
            worker.onerror = function (event) {
                console.log (event);
            };
            console.log (logPrefix + 'Initialisation succeeded');
        } catch (error) {
            console.log (logPrefix + 'Initialisation failed');
            console.error (error);
        }
    } else {
        console.log (logPrefix + 'Initialisation failed - HTML5 Web Worker is not supported');
    }
}) ('HackTimerWorker.js');