diff --git a/.eslintrc.js b/.eslintrc.js index fbebe1e..bafd468 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,7 @@ module.exports = { }, "extends": "eslint-config-standard", "parserOptions": { - "ecmaVersion": 2015, + "ecmaVersion": 2016, "sourceType": "module" }, "rules": { diff --git "a/Bilibili\347\233\264\346\222\255\351\227\264\346\214\202\346\234\272\345\212\251\346\211\213.js" "b/Bilibili\347\233\264\346\222\255\351\227\264\346\214\202\346\234\272\345\212\251\346\211\213.js" index 8ec4511..3785d59 100644 --- "a/Bilibili\347\233\264\346\222\255\351\227\264\346\214\202\346\234\272\345\212\251\346\211\213.js" +++ "b/Bilibili\347\233\264\346\222\255\351\227\264\346\214\202\346\234\272\345\212\251\346\211\213.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name Bilibili直播间挂机助手 // @namespace SeaLoong -// @version 2.0.1 +// @version 2.0.2 // @description Bilibili直播间自动签到,领瓜子,参加抽奖,完成任务,送礼等 // @author SeaLoong // @homepageURL https://github.com/SeaLoong/Bilibili-LRHH @@ -90,6 +90,36 @@ // 拒绝所有非API的ajax访问 if (settings.url.indexOf('api.live.bilibili.com') === -1) request.abort(); }); + // 拦截弹幕服务器连接 + let webSocketConstructor = WebSocket.prototype.constructor; + WebSocket.prototype.constructor = (url, protocols) => { + if (url === 'wss://broadcastlv.chat.bilibili.com/sub') return webSocketConstructor(url, protocols); + throw new Error('弹幕服务器连接已拦截 by ' + NAME); + }; + // 拦截直播流 + // let windowFetch = window.fetch; + window.fetch = () => new Promise(() => { + throw new Error('子脚本fetch已拦截 by ' + NAME); + }); + // 清空页面元素和节点 + try { + $('html').remove(); + } catch (err) {}; + // 读取父脚本数据 + window.toast = window.parent.toast; + Info = window.parent[NAME].Info; + CONFIG = window.parent[NAME].CONFIG; + CACHE = window.parent[NAME].CACHE; + window[NAME].promise.sync.then(() => { + Info = window.parent[NAME].Info; + CONFIG = window.parent[NAME].CONFIG; + CACHE = window.parent[NAME].CACHE; + window[NAME].promise.sync = $.Deferred(); + }); + window[NAME].Lottery = { + list: [] + }; + // 正式执行子脚本 const Lottery = { ws: undefined, Gift: { @@ -142,7 +172,6 @@ obj.raffleId = parseInt(obj.raffleId, 10); // 有时候会出现raffleId是string的情况(破站) // raffleId过滤,防止重复参加 if (window[NAME].Lottery.list.some(v => v === obj.raffleId)) return Lottery.Gift.join(roomid, raffleList, i + 1); - const p = $.Deferred(); // 这个Promise在notice之后resolve,如果设置不提示则直接resolve const p1 = $.Deferred(); // 这个Promise在延时时间到的时候resolve p1.then(() => { @@ -259,45 +288,13 @@ } } }; - let empty_innerHTML_cnt = 0; - let timer_clear = setInterval(() => { - try { - if (document.body.innerHTML === '') empty_innerHTML_cnt++; - document.body.innerHTML = ''; - document.getElementsByTagName('head')[0].innerHTML = ''; - if (empty_innerHTML_cnt > 10) { - if (timer_clear) clearInterval(timer_clear); - timer_clear = undefined; - } - } catch (err) {}; - }, 1e3); - try { - document.body.innerHTML = ''; - document.getElementsByTagName('head')[0].innerHTML = ''; - } catch (err) {}; - window.toast = window.parent.toast; - Info = window.parent[NAME].Info; - CONFIG = window.parent[NAME].CONFIG; - CACHE = window.parent[NAME].CACHE; - // 读取父脚本数据 - window[NAME].promise.sync.then(() => { - Info = window.parent[NAME].Info; - CONFIG = window.parent[NAME].CONFIG; - CACHE = window.parent[NAME].CACHE; - window[NAME].promise.sync = $.Deferred(); - }); - window[NAME].Lottery = { - list: [] - }; let timer_next, timer_max_time; let new_raffle = false; let run_finished = false; let raffleList = []; const finish = () => { - Lottery.ws.close(); + if (Lottery.ws.readyState === WebSocket.OPEN) Lottery.ws.close(); Lottery.ws = undefined; - if (timer_clear) clearInterval(timer_clear); - timer_clear = undefined; window[NAME].promise.finish.resolve(); }; Lottery.ws = new API.DanmuWebSocket(Info.uid, window[NAME].roomid); @@ -447,7 +444,7 @@ list.forEach((v) => { v.style.top = (parseInt(v.style.top, 10) - 40) + 'px'; }); - a.parentNode.removeChild(a); + $(a).remove(); }, 200); }, timeout); }; @@ -644,7 +641,11 @@ GIFT_ALLOWED: () => ('设置允许送的礼物类型编号(任何未在此列表的礼物一定不会被送出!),多个请用英文逗号(,)隔开,为空则表示允许送出所有类型的礼物

' + Info.gift_list_str), SEND_TODAY: '送出包裹中今天到期的礼物(会送出"默认礼物类型"之外的礼物,若今日亲密度已满则不送)' }, - SILVER2COIN: '用银瓜子兑换硬币(每天每个接口各能兑换一次)
新接口:700银瓜子兑换1个硬币
旧接口:1400银瓜子兑换1个硬币', + SILVER2COIN: '用银瓜子兑换硬币(每天每个接口各能兑换一次)', + SILVER2COIN_CONFIG: { + USE_NEW: '新接口:700银瓜子兑换1个硬币', + USE_OLD: '旧接口:1400银瓜子兑换1个硬币
该接口已经不能使用' + }, AUTO_DAILYREWARD: '(该功能未实现)', SHOW_TOAST: '选择是否显示浮动提示,但提示信息依旧会在控制台显示' }, @@ -903,7 +904,7 @@ if (Object.prototype.toString.call(CACHE) !== '[object Object]') throw new Error(); } catch (err) { CACHE = { - last_aid: 162 + last_aid: 163 }; localStorage.setItem(NAME + '_CACHE', JSON.stringify(CACHE)); } @@ -1805,14 +1806,14 @@ create: (roomid) => { // roomid过滤,防止创建多个同样roomid的iframe if (window[NAME].Lottery.iframeList.some(v => v.contentWindow[NAME].roomid === roomid)) return; - const iframe = $('')[0]; + const iframe = $('')[0]; iframe.src = '//live.bilibili.com/' + roomid + '?visit_id=' + Info.visit_id; document.body.appendChild(iframe); const p = $.Deferred(); p.then(() => { $.each(window[NAME].Lottery.iframeList, (i, v) => { if (v.contentWindow[NAME].roomid === roomid) { - document.body.removeChild(v); + $(v).remove(); window[NAME].Lottery.iframeList.splice(i, 1); return false; } @@ -1863,23 +1864,27 @@ timer_same_roomid_maxtime = undefined; Lottery.create(last_roomid); } else { - // 连续收到抽奖消息等待9s - timer_last_roomid = setTimeout(() => { - // 过9s没抽奖消息的处理 - if (timer_same_roomid_maxtime) clearTimeout(timer_same_roomid_maxtime); - timer_same_roomid_maxtime = undefined; - timer_last_roomid = undefined; - Lottery.create(obj.real_roomid); - }, 9e3); - // 同一直播间等待150s - timer_same_roomid_maxtime = setTimeout(() => { - // 过150s还是同一个直播间的处理 - if (timer_last_roomid) clearTimeout(timer_last_roomid); - timer_last_roomid = undefined; - timer_same_roomid_maxtime = undefined; - Lottery.create(obj.real_roomid); - }, 150e3); + if (!timer_same_roomid_maxtime) { + // 同一直播间等待150s + timer_same_roomid_maxtime = setTimeout(() => { + // 过150s还是同一个直播间的处理 + if (timer_last_roomid) clearTimeout(timer_last_roomid); + timer_last_roomid = undefined; + timer_same_roomid_maxtime = undefined; + Lottery.create(obj.real_roomid); + last_roomid = undefined; + }, 150e3); + } } + // 连续收到抽奖消息等待9s + timer_last_roomid = setTimeout(() => { + // 过9s没抽奖消息的处理 + if (timer_same_roomid_maxtime) clearTimeout(timer_same_roomid_maxtime); + timer_same_roomid_maxtime = undefined; + timer_last_roomid = undefined; + Lottery.create(obj.real_roomid); + last_roomid = undefined; + }, 9e3); last_roomid = obj.real_roomid; break; case 'GUARD_MSG': diff --git a/README.md b/README.md index f607d69..82e3b85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bilibili直播间挂机助手/Bilibili-LRHH/BLRHH -![ECMAScript2016](https://img.shields.io/badge/ECMAScript-2016-green.svg?longCache=true) ![TamperMonkey](https://img.shields.io/badge/TamperMonkey-pass-green.svg?longCache=true) ![Chromium_67](https://img.shields.io/badge/Chromium_67-pass-green.svg?longCache=true) ![Firefox_61](https://img.shields.io/badge/Firefox_61-pass-green.svg?longCache=true) +![ECMAScript 5](https://img.shields.io/badge/ECMAScript_5-unsupport-red.svg?longCache=true) ![ECMAScript 6](https://img.shields.io/badge/ECMAScript_6-pass-green.svg?longCache=true) ![TamperMonkey 4.6](https://img.shields.io/badge/TamperMonkey_4.6-pass-green.svg?longCache=true) ![Chromium 67](https://img.shields.io/badge/Chromium_67-pass-green.svg?longCache=true) ![Firefox 61](https://img.shields.io/badge/Firefox_61-pass-green.svg?longCache=true) [![Issues](https://img.shields.io/github/issues/SeaLoong/Bilibili-LRHH.svg)](https://github.com/SeaLoong/Bilibili-LRHH/issues) > 该脚本为TamperMonkey脚本,只在该环境下测试通过,使用其它脚本插件来加载此脚本的,不能保证正常运行 @@ -11,7 +11,7 @@ ## 如何使用 1. 见[GreasyFork](https://greasyfork.org/zh-CN) 首页说明 2. 进入[Bilibili直播间挂机助手](https://greasyfork.org/zh-CN/scripts/37095-bilibili%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B)页面,点击"安装此脚本"即可从GreasyFork更新此脚本 -3. 或者点击上方的[Bilibili直播间挂机助手](https://raw.githubusercontent.com/SeaLoong/Bilibili-LRHH/master/Bilibili%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B.js),将代码复制下来。然后从脚本管理器中新建一个脚本,将自动生成的内容删除,粘贴复制的代码即可从Github更新此脚本 +3. 或者点击[Bilibili直播间挂机助手](https://raw.githubusercontent.com/SeaLoong/Bilibili-LRHH/master/Bilibili%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B.js),将代码复制下来。然后从脚本管理器中新建一个脚本,将自动生成的内容删除,粘贴复制的代码即可从Github更新此脚本 ----------------- @@ -30,6 +30,8 @@ ## 注意 自动抽奖功能有封号风险,使用前请做好心理准备 挂在直播间过久极有可能导致页面崩溃(吃内存过多) + 开启自动抽奖->礼物抽奖功能后,很容易在控制台看到许多Error,这些大多是B站的脚本错误,不用理会 + 要检索此脚本的控制台输出只要过滤显示带有"[BLRHH]"字样的输出即可 ----------------- @@ -47,6 +49,9 @@ ----------------- ## 更新日志 +> ### 2018-08-03 (Version 2.0.2) +> 修复了自动抽奖->礼物抽奖在运行时会出现其他直播间声音的问题 +> 优化了自动抽奖->礼物抽奖的参与方式 > ### 2018-08-03 (Version 2.0.1) > 优化了自动抽奖->礼物抽奖的参与方式 > 增加了移动端心跳5分钟后自动进行一次完成任务的功能 @@ -79,7 +84,6 @@ > ### 2018-03-10 > 在Github上创建脚本仓库 > 更新领取银瓜子的功能 -> ----------------- > ### 2018-02-15 > 修正了节奏风暴有关功能的实现逻辑 > 在GreasyFork上删除脚本