Biliplus Evolved

简单的B+增强脚本

目前为 2022-11-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Biliplus Evolved
  3. // @version 0.7.1
  4. // @description 简单的B+增强脚本
  5. // @author DeltaFlyer
  6. // @copyright 2022, DeltaFlyer(https://github.com/DeltaFlyerW)
  7. // @license MIT
  8. // @match https://*.biliplus.com/*
  9. // @match https://www.bilibili.com/blackboard/activity-S1jfy69Jz.html
  10. // @run-at document-end
  11. // @grant none
  12. // @icon https://www.biliplus.com/favicon.ico
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js
  14. // @namespace https://greasyfork.org/users/927887
  15. // ==/UserScript==
  16.  
  17.  
  18. (function () {
  19.  
  20. 'use strict';
  21.  
  22. async function sleep(time) {
  23. await new Promise((resolve) => setTimeout(resolve, time));
  24. }
  25.  
  26. async function xhrGet(url) {
  27. console.log('Get', url)
  28. const xhr = new XMLHttpRequest();
  29. xhr.open("get", url, true);
  30. xhr.withCredentials = true
  31.  
  32. if (xhr.pakku_send) {
  33. xhr.pakku_send()
  34. } else {
  35. xhr.send()
  36. }
  37. return new Promise(
  38. (resolve) => {
  39. xhr.onreadystatechange = async () => {
  40. if (xhr.readyState === 4) {
  41. if (xhr.status === 200) {
  42. resolve(xhr.responseText)
  43. } else {
  44. resolve(null)
  45. }
  46. }
  47. }
  48. }
  49. )
  50. }
  51.  
  52. function downloadFile(fileName, content, type = 'text/plain;charset=utf-8') {
  53. let aLink = document.createElement('a');
  54. let blob
  55. if (typeof (content) == 'string')
  56. blob = new Blob([content], {'type': type})
  57. else blob = content
  58. aLink.download = fileName;
  59. let url = URL.createObjectURL(blob)
  60. aLink.href = url
  61. aLink.click()
  62. URL.revokeObjectURL(url)
  63. }
  64.  
  65. if (window.location.href.indexOf('biliplus') !== -1) {
  66. const broadcastChannel = new BroadcastChannel('exampleUserscript');
  67. let registeredTimestamp = null
  68.  
  69.  
  70. if (window.top === window) {
  71. console.log('biliplus script running')
  72.  
  73.  
  74. function xmlunEscape(content) {
  75. return content.replace(';', ';')
  76. .replace(/&/g, '&')
  77. .replace(/</g, '&')
  78. .replace(/>/g, '&')
  79. .replace(/'/g, '&')
  80. .replace(/"/g, '&')
  81. }
  82.  
  83. let createElement = function (sHtml) {
  84. // 创建一个可复用的包装元素
  85. let recycled = document.createElement('div'),
  86. // 创建标签简易匹配
  87. reg = /^<([a-zA-Z]+)(?=\s|\/>|>)[\s\S]*>$/,
  88. // 某些元素HTML标签必须插入特定的父标签内,才能产生合法元素
  89. // 另规避:ie7-某些元素innerHTML只读
  90. // 创建这些需要包装的父标签hash
  91. hash = {
  92. 'colgroup': 'table',
  93. 'col': 'colgroup',
  94. 'thead': 'table',
  95. 'tfoot': 'table',
  96. 'tbody': 'table',
  97. 'tr': 'tbody',
  98. 'th': 'tr',
  99. 'td': 'tr',
  100. 'optgroup': 'select',
  101. 'option': 'optgroup',
  102. 'legend': 'fieldset'
  103. };
  104. // 闭包重载方法(预定义变量避免重复创建,调用执行更快,成员私有化)
  105. createElement = function (sHtml) {
  106. // 若不包含标签,调用内置方法创建并返回元素
  107. if (!reg.test(sHtml)) {
  108. return document.createElement(sHtml);
  109. }
  110. // hash中是否包含匹配的标签名
  111. let tagName = hash[RegExp.$1.toLowerCase()];
  112. // 若无,向包装元素innerHTML,创建/截取并返回元素
  113. if (!tagName) {
  114. recycled.innerHTML = sHtml;
  115. return recycled.removeChild(recycled.firstChild);
  116. }
  117. // 若匹配hash标签,迭代包装父标签,并保存迭代层次
  118. let deep = 0, element = recycled;
  119. do {
  120. sHtml = '<' + tagName + '>' + sHtml + '</' + tagName + '>';
  121. deep++;
  122. }
  123. while (tagName = hash[tagName]);
  124. element.innerHTML = sHtml;
  125. // 根据迭代层次截取被包装的子元素
  126. do {
  127. element = element.removeChild(element.firstChild);
  128. }
  129. while (--deep > -1);
  130. // 最终返回需要创建的元素
  131. return element;
  132. }
  133. // 执行方法并返回结果
  134. return createElement(sHtml);
  135. }
  136.  
  137. async function parseVideoInfo(aid) {
  138. let videoInfo
  139. try {
  140. let videoPage = await xhrGet('https://www.biliplus.com/video/av' + aid + '/')
  141. videoInfo = JSON.parse(xmlunEscape(/({"id":.*?})\);/.exec(videoPage)[1]))
  142. videoInfo['aid'] = videoInfo['id']
  143. } catch (e) {
  144. console.log(e)
  145. let videoPage = await xhrGet('https://www.biliplus.com/all/video/av' + aid + '/')
  146. let url = /(\/api\/view_all\?.*?)'/.exec(videoPage)[1]
  147. url = 'https://www.biliplus.com' + url
  148. let data = JSON.parse(xmlunEscape(await xhrGet(url)))['data']
  149. videoInfo = data['info']
  150. videoInfo['list'] = data['parts']
  151. }
  152. return videoInfo
  153. }
  154.  
  155.  
  156. (function searchFix() {
  157.  
  158. if (window.location.href.indexOf('api/do.php') === -1) return
  159. window.openOrigin = window.open
  160. window.open = function (link) {
  161. console.log('window.open', link)
  162. if (link) {
  163. window.openOrigin(link)
  164. }
  165. }
  166. let getjson = window.parent.getjsonReal = window.parent.getjson
  167. let aidList = []
  168. let irrelevantArchive = []
  169. let allArchive = []
  170. window.getjson = window.parent.getjson = function (url, callback, n) {
  171. if (url.indexOf("search_api") !== -1 && url.indexOf("source=biliplus") !== -1) {
  172. try {
  173. async function joinCallback(url, callback, n) {
  174. if (url[0] === '/')
  175. url = 'https:' + url
  176. let word = /word=(.*?)(&|$)/.exec(url)[1]
  177. let wordList = []
  178. for (let keyword of decodeURIComponent(word).replace(/([^ ])@/, '$1 @').split(' ')) {
  179. if (keyword[0] !== '@') {
  180. wordList.push(keyword)
  181. }
  182. }
  183. let pn = /p=(\d+)/.exec(url)
  184. pn = pn ? pn[1] : '1'
  185. if (pn === '1') {
  186. aidList = []
  187. irrelevantArchive = []
  188. allArchive = []
  189. }
  190.  
  191. let searchResult = JSON.parse(await xhrGet(url))
  192. let archive = []
  193. searchResult['data']['items']['archive'].forEach(function (item) {
  194. if (item.goto === 'av') {
  195. if (aidList.indexOf(item.param) === -1) {
  196. aidList.push(item.param)
  197. let isRelevant = false
  198. for (let keyword of wordList) {
  199. for (let key of ['title', 'desc']) {
  200. if (item[key].indexOf(keyword) !== -1) {
  201. isRelevant = true
  202. }
  203. }
  204. }
  205. if (isRelevant) {
  206. archive.push(item)
  207. } else {
  208. irrelevantArchive.push(item)
  209. }
  210. allArchive.push(item)
  211. }
  212. } else {
  213. archive.push(item)
  214. }
  215. })
  216.  
  217. try {
  218. let aidSearchUrl = 'https://www.biliplus.com/api/search?word=' + word + '&page=' + pn
  219. let aidSearchResult = JSON.parse((await xhrGet(aidSearchUrl)))['result']
  220. aidSearchResult.forEach(function (video) {
  221. if (aidList.indexOf(video.aid) === -1) {
  222. let item = {
  223. author: video.author,
  224. cover: video.pic,
  225. created: new Date(video.created.replace(/-/g, '/')).getTime() / 1000,
  226. review: video.review,
  227. desc: video.description,
  228. goto: "av",
  229. param: video.aid,
  230. play: video.play,
  231. title: video.title,
  232. }
  233.  
  234. let isRelevant = false
  235. for (let keyword of wordList) {
  236. for (let key of ['title', 'desc']) {
  237. if (item[key].indexOf(keyword) !== -1) {
  238. isRelevant = true
  239. }
  240. }
  241. }
  242. if (isRelevant) {
  243. archive.push(item)
  244. } else {
  245. irrelevantArchive.push(item)
  246. }
  247. allArchive.push(item)
  248. }
  249. })
  250. } catch (e) {
  251. console.log(e)
  252. }
  253.  
  254. if (archive.length === 0) {
  255. archive = irrelevantArchive.slice(0, 40)
  256. irrelevantArchive = irrelevantArchive.slice(40)
  257. }
  258. searchResult['data']['items']['archive'] = archive
  259. callback(searchResult, n)
  260. return
  261. }
  262.  
  263. return joinCallback(url, callback, n)
  264. } catch (e) {
  265. console.log(e)
  266. return getjson(url, callback, n)
  267. }
  268. } else return getjson(url, callback, n)
  269.  
  270. };
  271. window.doSearch()
  272.  
  273.  
  274. broadcastChannel.addEventListener('message', function (event) {
  275. console.log(event.data)
  276. if (event.data.type === 'aidComplete') {
  277. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  278. if (elem) elem.textContent = '下载完成'
  279. }
  280. if (event.data.type === 'aidDownloaded') {
  281. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  282. if (elem) elem.textContent = '已下载'
  283. }
  284. if (event.data.type === 'aidStart') {
  285. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  286. if (elem) elem.textContent = '开始下载'
  287. }
  288. if (event.data.type === 'cidComplete') {
  289. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  290. if (elem) elem.textContent = event.data.progress + "%"
  291. }
  292. })
  293.  
  294. document.addEventListener("DOMNodeInserted", async (msg) => {
  295. if (msg.target.nodeName === '#text') {
  296. let aidElem = msg.target.parentElement.parentElement
  297. .querySelector('div[class="video-card-desc"]')
  298. if (!aidElem) {
  299. return
  300. }
  301. let link = msg.target.parentElement.parentElement.parentElement.getAttribute("data-link")
  302. msg.target.parentElement.parentElement.parentElement.removeAttribute("data-link")
  303. msg.target.parentElement.parentElement.parentElement.addEventListener('click', async function (event) {
  304. console.log(event)
  305. if (event.target.className !== 'download') {
  306. window.open(link)
  307. }
  308. })
  309. let timeago = msg.target.parentElement
  310. let aid = parseInt(aidElem.textContent.slice(2))
  311. if (!aidElem.querySelector('[class="download"]')) {
  312. let downloadButton = createElement(
  313. '<div class="download" style="display:inline-block;float:right;border-radius:5px;border:1px solid #AAA;' +
  314. 'background:#DDD;padding:8px 20px;cursor:pointer" id="av' + aid + '">下载弹幕</div>')
  315. window.moved = true
  316.  
  317. downloadButton.addEventListener('click', async function (event) {
  318. event.preventDefault()
  319. console.log('download', aid)
  320. if (downloadButton.textContent !== '下载弹幕') return
  321. downloadButton.textContent = '等待下载'
  322. await window.registerBili()
  323. let videoInfo = await parseVideoInfo(aid)
  324. broadcastChannel.postMessage({
  325. type: 'biliplusDownloadDanmakuVideo',
  326. videoInfo: videoInfo,
  327. timestamp: registeredTimestamp
  328. })
  329. })
  330. aidElem.appendChild(downloadButton)
  331. }
  332. for (let video of allArchive) {
  333. if (video.param === aid && video.goto === 'av') {
  334. let text = timeago.getAttribute('title') + ' 播放:' + video['play']
  335. if (video['danmaku']) text += ' 弹幕:' + video['danmaku']
  336. if (video['review']) text += ' 评论:' + video['review']
  337. timeago.textContent = text
  338. }
  339. }
  340. }
  341. })
  342.  
  343. })();
  344.  
  345. (function historyFix() {
  346.  
  347. if (window.location.href.indexOf('/video/') === -1) return
  348. window.downloadVideoDanmaku = async function (aid) {
  349. if (!aid) {
  350. aid = /av(\d+)/.exec(window.location.href)[1]
  351. }
  352. let regResult = window.registerBili()
  353. let videoInfo = await parseVideoInfo(aid)
  354. await regResult
  355. broadcastChannel.postMessage({
  356. type: 'biliplusDownloadDanmakuVideo',
  357. videoInfo: videoInfo,
  358. timestamp: registeredTimestamp
  359. })
  360. }
  361.  
  362. window.durationRecover = async function (aid, cid) {
  363. if (!aid) {
  364. aid = /av(\d+)/.exec(window.location.href)[1]
  365. }
  366. let elem = document.querySelector('[id="rec_' + cid + '"]')
  367. let user = document.querySelector("#userbar > p > span:nth-child(2) > b").textContent
  368. if (elem.textContent !== '恢复时长') return
  369. elem.textContent = '提取中'
  370. let regResult = window.registerBili()
  371. await xhrGet(`https://www.biliplus.com/api/history_add?aid=${aid}&cid=${cid}`)
  372. await regResult
  373. broadcastChannel.postMessage({
  374. type: 'biliplusDurationRecover',
  375. aid: aid,
  376. cid: cid,
  377. user: user,
  378. timestamp: registeredTimestamp
  379. })
  380. }
  381. broadcastChannel.addEventListener('message', function (event) {
  382. if (event.data.type === 'recoverComplete') {
  383. let elem = document.querySelector('[id="rec_' + event.data.cid + '"]')
  384. if (elem) elem.textContent = event.data.content
  385. }
  386. })
  387. document.addEventListener("DOMNodeInserted", async (msg) => {
  388. if (msg.target.id) {
  389. console.log(msg.target.className, msg.target)
  390.  
  391. if (msg.target.id === 'danmaku_container') {
  392. let historyButton = msg.target.querySelector('a[href^="/open/moepus.powered"]')
  393. let cid = /#(\d+)/.exec(historyButton.getAttribute('href'))[1]
  394. historyButton.onclick = async function () {
  395.  
  396. console.log('biliplusDownloadDanmaku', {
  397. 'cid': cid,
  398. 'title': document.querySelector('[class="videotitle"]').textContent + ' ' + document.querySelector('[id="cid_' + cid + '"]').innerText,
  399. 'timestamp': registeredTimestamp
  400. })
  401. await window.registerBili()
  402. broadcastChannel.postMessage(
  403. {
  404. type: 'biliplusDownloadDanmaku',
  405. cid: cid,
  406. title: document.querySelector('[class="videotitle"]').textContent + ' '
  407. + document.querySelector('[id="cid_' + cid + '"]').innerText,
  408.  
  409. timestamp: registeredTimestamp
  410. }
  411. )
  412. }
  413. historyButton.removeAttribute('href')
  414.  
  415. let commentButton = msg.target.querySelector('a[href^="https://comment.bilibili.com"]')
  416. commentButton.removeAttribute('href')
  417. commentButton.removeAttribute('onClick')
  418. commentButton.addEventListener('click', async function () {
  419. let commentText = await xhrGet("/danmaku/" + cid + ".xml")
  420. if (!commentText || commentText.indexOf("<state>2</state>") !== -1) {
  421. await window.registerBili()
  422. broadcastChannel.postMessage(
  423. {
  424. type: 'biliplusDownloadDanmaku',
  425. ndanmu: /<maxlimit>(\d+)<\/maxlimit>/.exec(commentText)?.[1],
  426. cid: cid,
  427. title: document.querySelector('[class="videotitle"]').textContent + ' '
  428. + document.querySelector('[id="cid_' + cid + '"]').innerText,
  429. history: false,
  430. timestamp: registeredTimestamp
  431. }
  432. )
  433. } else {
  434. downloadFile(cid + '.xml', commentText)
  435. }
  436. })
  437. } else if (msg.target.id === 'favorite') {
  438. msg.target.parentElement.appendChild(createElement(
  439. '<span id="downloadDanmaku"><a href="javascript:" onclick="window.downloadVideoDanmaku()">' +
  440. '<div class="solidbox pink" id="av' + /av(\d+)/.exec(window.location.href)[1] + '">下载视频弹幕</div></a></span>'))
  441. } else if (msg.target.id === 'part1') {
  442. msg.target.parentElement.insertBefore(createElement('<div class="solidbox pointer" onclick="window.downloadVideoDanmaku()">下载视频弹幕</div>'), msg.target)
  443. let lPartElem = msg.target.parentElement.querySelectorAll('[id^="part"]')
  444. for (let part of lPartElem) {
  445. let cid = part.querySelector('[id^="cid"]').getAttribute('id').slice(4)
  446. part.insertBefore(createElement('<div class="solidbox pointer" onclick="window.durationRecover(null,' + cid + ')" id="rec_' + cid + '">恢复时长</div>'), part.childNodes[4])
  447. }
  448. }
  449.  
  450. }
  451.  
  452. })
  453.  
  454. })();
  455.  
  456. (function corsCrack() {
  457.  
  458. async function registerBili() {
  459. if (registeredTimestamp === null) {
  460. broadcastChannel.addEventListener("message", (event) => {
  461. if (event.data.type === 'response') {
  462. registeredTimestamp = event.data.timestamp
  463. console.log(event.data)
  464. }
  465. })
  466. }
  467. registeredTimestamp = null
  468. broadcastChannel.postMessage({type: 'hello'})
  469. await sleep(500)
  470. if (registeredTimestamp === null) {
  471. window.open('https://www.bilibili.com/blackboard/activity-S1jfy69Jz.html')
  472. await new Promise(resolve => {
  473. function handle(event) {
  474. if (event.data.type !== 'response')
  475. return;
  476. broadcastChannel.removeEventListener('message', handle)
  477. resolve()
  478. }
  479.  
  480. broadcastChannel.addEventListener('message', handle)
  481. })
  482. }
  483. }
  484.  
  485. window.registerBili = registerBili
  486. })()
  487.  
  488. } else {
  489. console.log('iframe')
  490. let timestamp = new Date().getTime()
  491. broadcastChannel.postMessage({
  492. type: 'response',
  493. timestamp: timestamp
  494. })
  495. // We're in an iframe:
  496. window.addEventListener('message', (e) => {
  497. if (e.origin.indexOf('bilibili') !== -1) {
  498. console.log('iframe received message from top window', e.data);
  499. broadcastChannel.postMessage(e.data);
  500. }
  501. });
  502. broadcastChannel.addEventListener('message', (e) => {
  503. console.log('iframe received message from BroadcastChannel');
  504. if (e.data.type === 'hello') {
  505. broadcastChannel.postMessage({
  506. type: 'response',
  507. timestamp: timestamp
  508. })
  509. } else {
  510. if (e.data.timestamp === timestamp) {
  511. window.top.postMessage(e.data, '*');
  512. }
  513. }
  514. });
  515. }
  516.  
  517. } else if (window.location.href.indexOf('bilibili') !== -1) {
  518. let [downloadDanmaku, allProtobufDanmu] = (function () {
  519. !function (z) {
  520. var y = {
  521. 1: [function (p, w) {
  522. w.exports = function (h, m) {
  523. for (var n = Array(arguments.length - 1), e = 0, d = 2, a = !0; d < arguments.length;) n[e++] = arguments[d++];
  524. return new Promise(function (b, c) {
  525. n[e] = function (k) {
  526. if (a) if (a = !1, k) c(k); else {
  527. for (var l = Array(arguments.length - 1), q = 0; q < l.length;) l[q++] = arguments[q];
  528. b.apply(null, l)
  529. }
  530. };
  531. try {
  532. h.apply(m || null, n)
  533. } catch (k) {
  534. a && (a = !1, c(k))
  535. }
  536. })
  537. }
  538. }, {}], 2: [function (p, w, h) {
  539. h.length = function (e) {
  540. var d = e.length;
  541. if (!d) return 0;
  542. for (var a = 0; 1 < --d % 4 && "=" === e.charAt(d);) ++a;
  543. return Math.ceil(3 *
  544. e.length) / 4 - a
  545. };
  546. var m = Array(64), n = Array(123);
  547. for (p = 0; 64 > p;) n[m[p] = 26 > p ? p + 65 : 52 > p ? p + 71 : 62 > p ? p - 4 : p - 59 | 43] = p++;
  548. h.encode = function (e, d, a) {
  549. for (var b, c = null, k = [], l = 0, q = 0; d < a;) {
  550. var f = e[d++];
  551. switch (q) {
  552. case 0:
  553. k[l++] = m[f >> 2];
  554. b = (3 & f) << 4;
  555. q = 1;
  556. break;
  557. case 1:
  558. k[l++] = m[b | f >> 4];
  559. b = (15 & f) << 2;
  560. q = 2;
  561. break;
  562. case 2:
  563. k[l++] = m[b | f >> 6], k[l++] = m[63 & f], q = 0
  564. }
  565. 8191 < l && ((c || (c = [])).push(String.fromCharCode.apply(String, k)), l = 0)
  566. }
  567. return q && (k[l++] = m[b], k[l++] = 61, 1 === q && (k[l++] = 61)), c ? (l && c.push(String.fromCharCode.apply(String, k.slice(0, l))),
  568. c.join("")) : String.fromCharCode.apply(String, k.slice(0, l))
  569. };
  570. h.decode = function (e, d, a) {
  571. for (var b, c = a, k = 0, l = 0; l < e.length;) {
  572. var q = e.charCodeAt(l++);
  573. if (61 === q && 1 < k) break;
  574. if ((q = n[q]) === z) throw Error("invalid encoding");
  575. switch (k) {
  576. case 0:
  577. b = q;
  578. k = 1;
  579. break;
  580. case 1:
  581. d[a++] = b << 2 | (48 & q) >> 4;
  582. b = q;
  583. k = 2;
  584. break;
  585. case 2:
  586. d[a++] = (15 & b) << 4 | (60 & q) >> 2;
  587. b = q;
  588. k = 3;
  589. break;
  590. case 3:
  591. d[a++] = (3 & b) << 6 | q, k = 0
  592. }
  593. }
  594. if (1 === k) throw Error("invalid encoding");
  595. return a - c
  596. };
  597. h.test = function (e) {
  598. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)
  599. }
  600. },
  601. {}], 3: [function (p, w) {
  602. function h() {
  603. this.t = {}
  604. }
  605.  
  606. (w.exports = h).prototype.on = function (m, n, e) {
  607. return (this.t[m] || (this.t[m] = [])).push({fn: n, ctx: e || this}), this
  608. };
  609. h.prototype.off = function (m, n) {
  610. if (m === z) this.t = {}; else if (n === z) this.t[m] = []; else for (var e = this.t[m], d = 0; d < e.length;) e[d].fn === n ? e.splice(d, 1) : ++d;
  611. return this
  612. };
  613. h.prototype.emit = function (m) {
  614. var n = this.t[m];
  615. if (n) {
  616. for (var e = [], d = 1; d < arguments.length;) e.push(arguments[d++]);
  617. for (d = 0; d < n.length;) n[d].fn.apply(n[d++].ctx, e)
  618. }
  619. return this
  620. }
  621. }, {}], 4: [function (p,
  622. w) {
  623. function h(a) {
  624. return "undefined" != typeof Float32Array ? function () {
  625. function b(v, g, t) {
  626. q[0] = v;
  627. g[t] = f[0];
  628. g[t + 1] = f[1];
  629. g[t + 2] = f[2];
  630. g[t + 3] = f[3]
  631. }
  632.  
  633. function c(v, g, t) {
  634. q[0] = v;
  635. g[t] = f[3];
  636. g[t + 1] = f[2];
  637. g[t + 2] = f[1];
  638. g[t + 3] = f[0]
  639. }
  640.  
  641. function k(v, g) {
  642. return f[0] = v[g], f[1] = v[g + 1], f[2] = v[g + 2], f[3] = v[g + 3], q[0]
  643. }
  644.  
  645. function l(v, g) {
  646. return f[3] = v[g], f[2] = v[g + 1], f[1] = v[g + 2], f[0] = v[g + 3], q[0]
  647. }
  648.  
  649. var q = new Float32Array([-0]), f = new Uint8Array(q.buffer), u = 128 === f[3];
  650. a.writeFloatLE = u ? b : c;
  651. a.writeFloatBE = u ? c : b;
  652. a.readFloatLE = u ? k : l;
  653. a.readFloatBE =
  654. u ? l : k
  655. }() : function () {
  656. function b(k, l, q, f) {
  657. var u = 0 > l ? 1 : 0;
  658. if (u && (l = -l), 0 === l) k(0 < 1 / l ? 0 : 2147483648, q, f); else if (isNaN(l)) k(2143289344, q, f); else if (3.4028234663852886E38 < l) k((u << 31 | 2139095040) >>> 0, q, f); else if (1.1754943508222875E-38 > l) k((u << 31 | Math.round(l / 1.401298464324817E-45)) >>> 0, q, f); else {
  659. var v = Math.floor(Math.log(l) / Math.LN2);
  660. k((u << 31 | v + 127 << 23 | 8388607 & Math.round(l * Math.pow(2, -v) * 8388608)) >>> 0, q, f)
  661. }
  662. }
  663.  
  664. function c(k, l, q) {
  665. q = k(l, q);
  666. k = 2 * (q >> 31) + 1;
  667. l = q >>> 23 & 255;
  668. q &= 8388607;
  669. return 255 === l ? q ? NaN : 1 / 0 * k : 0 === l ?
  670. 1.401298464324817E-45 * k * q : k * Math.pow(2, l - 150) * (q + 8388608)
  671. }
  672.  
  673. a.writeFloatLE = b.bind(null, m);
  674. a.writeFloatBE = b.bind(null, n);
  675. a.readFloatLE = c.bind(null, e);
  676. a.readFloatBE = c.bind(null, d)
  677. }(), "undefined" != typeof Float64Array ? function () {
  678. function b(v, g, t) {
  679. q[0] = v;
  680. g[t] = f[0];
  681. g[t + 1] = f[1];
  682. g[t + 2] = f[2];
  683. g[t + 3] = f[3];
  684. g[t + 4] = f[4];
  685. g[t + 5] = f[5];
  686. g[t + 6] = f[6];
  687. g[t + 7] = f[7]
  688. }
  689.  
  690. function c(v, g, t) {
  691. q[0] = v;
  692. g[t] = f[7];
  693. g[t + 1] = f[6];
  694. g[t + 2] = f[5];
  695. g[t + 3] = f[4];
  696. g[t + 4] = f[3];
  697. g[t + 5] = f[2];
  698. g[t + 6] = f[1];
  699. g[t + 7] = f[0]
  700. }
  701.  
  702. function k(v, g) {
  703. return f[0] = v[g], f[1] = v[g +
  704. 1], f[2] = v[g + 2], f[3] = v[g + 3], f[4] = v[g + 4], f[5] = v[g + 5], f[6] = v[g + 6], f[7] = v[g + 7], q[0]
  705. }
  706.  
  707. function l(v, g) {
  708. return f[7] = v[g], f[6] = v[g + 1], f[5] = v[g + 2], f[4] = v[g + 3], f[3] = v[g + 4], f[2] = v[g + 5], f[1] = v[g + 6], f[0] = v[g + 7], q[0]
  709. }
  710.  
  711. var q = new Float64Array([-0]), f = new Uint8Array(q.buffer), u = 128 === f[7];
  712. a.writeDoubleLE = u ? b : c;
  713. a.writeDoubleBE = u ? c : b;
  714. a.readDoubleLE = u ? k : l;
  715. a.readDoubleBE = u ? l : k
  716. }() : function () {
  717. function b(k, l, q, f, u, v) {
  718. var g = 0 > f ? 1 : 0;
  719. if (g && (f = -f), 0 === f) k(0, u, v + l), k(0 < 1 / f ? 0 : 2147483648, u, v + q); else if (isNaN(f)) k(0, u, v + l), k(2146959360,
  720. u, v + q); else if (1.7976931348623157E308 < f) k(0, u, v + l), k((g << 31 | 2146435072) >>> 0, u, v + q); else if (2.2250738585072014E-308 > f) k((f /= 4.9E-324) >>> 0, u, v + l), k((g << 31 | f / 4294967296) >>> 0, u, v + q); else {
  721. var t = Math.floor(Math.log(f) / Math.LN2);
  722. 1024 === t && (t = 1023);
  723. k(4503599627370496 * (f *= Math.pow(2, -t)) >>> 0, u, v + l);
  724. k((g << 31 | t + 1023 << 20 | 1048576 * f & 1048575) >>> 0, u, v + q)
  725. }
  726. }
  727.  
  728. function c(k, l, q, f, u) {
  729. l = k(f, u + l);
  730. f = k(f, u + q);
  731. k = 2 * (f >> 31) + 1;
  732. q = f >>> 20 & 2047;
  733. l = 4294967296 * (1048575 & f) + l;
  734. return 2047 === q ? l ? NaN : 1 / 0 * k : 0 === q ? 4.9E-324 * k * l : k * Math.pow(2,
  735. q - 1075) * (l + 4503599627370496)
  736. }
  737.  
  738. a.writeDoubleLE = b.bind(null, m, 0, 4);
  739. a.writeDoubleBE = b.bind(null, n, 4, 0);
  740. a.readDoubleLE = c.bind(null, e, 0, 4);
  741. a.readDoubleBE = c.bind(null, d, 4, 0)
  742. }(), a
  743. }
  744.  
  745. function m(a, b, c) {
  746. b[c] = 255 & a;
  747. b[c + 1] = a >>> 8 & 255;
  748. b[c + 2] = a >>> 16 & 255;
  749. b[c + 3] = a >>> 24
  750. }
  751.  
  752. function n(a, b, c) {
  753. b[c] = a >>> 24;
  754. b[c + 1] = a >>> 16 & 255;
  755. b[c + 2] = a >>> 8 & 255;
  756. b[c + 3] = 255 & a
  757. }
  758.  
  759. function e(a, b) {
  760. return (a[b] | a[b + 1] << 8 | a[b + 2] << 16 | a[b + 3] << 24) >>> 0
  761. }
  762.  
  763. function d(a, b) {
  764. return (a[b] << 24 | a[b + 1] << 16 | a[b + 2] << 8 | a[b + 3]) >>> 0
  765. }
  766.  
  767. w.exports = h(h)
  768. }, {}], 5: [function (p, w, h) {
  769. w.exports =
  770. function (m) {
  771. try {
  772. var n = eval("require")(m);
  773. if (n && (n.length || Object.keys(n).length)) return n
  774. } catch (e) {
  775. }
  776. return null
  777. }
  778. }, {}], 6: [function (p, w) {
  779. w.exports = function (h, m, n) {
  780. var e = n || 8192, d = e >>> 1, a = null, b = e;
  781. return function (c) {
  782. if (1 > c || d < c) return h(c);
  783. e < b + c && (a = h(e), b = 0);
  784. c = m.call(a, b, b += c);
  785. return 7 & b && (b = 1 + (7 | b)), c
  786. }
  787. }
  788. }, {}], 7: [function (p, w, h) {
  789. h.length = function (m) {
  790. for (var n = 0, e = 0, d = 0; d < m.length; ++d) 128 > (e = m.charCodeAt(d)) ? n += 1 : 2048 > e ? n += 2 : 55296 == (64512 & e) && 56320 == (64512 & m.charCodeAt(d + 1)) ? (++d, n += 4) : n += 3;
  791. return n
  792. };
  793. h.read = function (m, n, e) {
  794. if (1 > e - n) return "";
  795. for (var d, a = null, b = [], c = 0; n < e;) 128 > (d = m[n++]) ? b[c++] = d : 191 < d && 224 > d ? b[c++] = (31 & d) << 6 | 63 & m[n++] : 239 < d && 365 > d ? (d = ((7 & d) << 18 | (63 & m[n++]) << 12 | (63 & m[n++]) << 6 | 63 & m[n++]) - 65536, b[c++] = 55296 + (d >> 10), b[c++] = 56320 + (1023 & d)) : b[c++] = (15 & d) << 12 | (63 & m[n++]) << 6 | 63 & m[n++], 8191 < c && ((a || (a = [])).push(String.fromCharCode.apply(String, b)), c = 0);
  796. return a ? (c && a.push(String.fromCharCode.apply(String, b.slice(0, c))), a.join("")) : String.fromCharCode.apply(String, b.slice(0, c))
  797. };
  798. h.write =
  799. function (m, n, e) {
  800. for (var d, a, b = e, c = 0; c < m.length; ++c) 128 > (d = m.charCodeAt(c)) ? n[e++] = d : (2048 > d ? n[e++] = d >> 6 | 192 : (55296 == (64512 & d) && 56320 == (64512 & (a = m.charCodeAt(c + 1))) ? (d = 65536 + ((1023 & d) << 10) + (1023 & a), ++c, n[e++] = d >> 18 | 240, n[e++] = d >> 12 & 63 | 128) : n[e++] = d >> 12 | 224, n[e++] = d >> 6 & 63 | 128), n[e++] = 63 & d | 128);
  801. return e - b
  802. }
  803. }, {}], 8: [function (p, w, h) {
  804. function m() {
  805. n.Reader.n(n.BufferReader);
  806. n.util.n()
  807. }
  808.  
  809. var n = h;
  810. n.build = "minimal";
  811. n.Writer = p(16);
  812. n.BufferWriter = p(17);
  813. n.Reader = p(9);
  814. n.BufferReader = p(10);
  815. n.util = p(15);
  816. n.rpc = p(12);
  817. n.roots = p(11);
  818. n.configure = m;
  819. n.Writer.n(n.BufferWriter);
  820. m()
  821. }, {10: 10, 11: 11, 12: 12, 15: 15, 16: 16, 17: 17, 9: 9}], 9: [function (p, w) {
  822. function h(f, u) {
  823. return RangeError("index out of range: " + f.pos + " + " + (u || 1) + " > " + f.len)
  824. }
  825.  
  826. function m(f) {
  827. this.buf = f;
  828. this.pos = 0;
  829. this.len = f.length
  830. }
  831.  
  832. function n() {
  833. var f = new c(0, 0), u = 0;
  834. if (!(4 < this.len - this.pos)) {
  835. for (; 3 > u; ++u) {
  836. if (this.pos >= this.len) throw h(this);
  837. if (f.lo = (f.lo | (127 & this.buf[this.pos]) << 7 * u) >>> 0, 128 > this.buf[this.pos++]) return f
  838. }
  839. return f.lo = (f.lo | (127 & this.buf[this.pos++]) <<
  840. 7 * u) >>> 0, f
  841. }
  842. for (; 4 > u; ++u) if (f.lo = (f.lo | (127 & this.buf[this.pos]) << 7 * u) >>> 0, 128 > this.buf[this.pos++]) return f;
  843. if (f.lo = (f.lo | (127 & this.buf[this.pos]) << 28) >>> 0, f.hi = (f.hi | (127 & this.buf[this.pos]) >> 4) >>> 0, 128 > this.buf[this.pos++]) return f;
  844. if (u = 0, 4 < this.len - this.pos) for (; 5 > u; ++u) {
  845. if (f.hi = (f.hi | (127 & this.buf[this.pos]) << 7 * u + 3) >>> 0, 128 > this.buf[this.pos++]) return f
  846. } else for (; 5 > u; ++u) {
  847. if (this.pos >= this.len) throw h(this);
  848. if (f.hi = (f.hi | (127 & this.buf[this.pos]) << 7 * u + 3) >>> 0, 128 > this.buf[this.pos++]) return f
  849. }
  850. throw Error("invalid varint encoding");
  851. }
  852.  
  853. function e(f, u) {
  854. return (f[u - 4] | f[u - 3] << 8 | f[u - 2] << 16 | f[u - 1] << 24) >>> 0
  855. }
  856.  
  857. function d() {
  858. if (this.pos + 8 > this.len) throw h(this, 8);
  859. return new c(e(this.buf, this.pos += 4), e(this.buf, this.pos += 4))
  860. }
  861.  
  862. w.exports = m;
  863. var a, b = p(15), c = b.LongBits, k = b.utf8, l,
  864. q = "undefined" != typeof Uint8Array ? function (f) {
  865. if (f instanceof Uint8Array || Array.isArray(f)) return new m(f);
  866. throw Error("illegal buffer");
  867. } : function (f) {
  868. if (Array.isArray(f)) return new m(f);
  869. throw Error("illegal buffer");
  870. };
  871. m.create = b.Buffer ? function (f) {
  872. return (m.create = function (u) {
  873. return b.Buffer.isBuffer(u) ?
  874. new a(u) : q(u)
  875. })(f)
  876. } : q;
  877. m.prototype.i = b.Array.prototype.subarray || b.Array.prototype.slice;
  878. m.prototype.uint32 = (l = 4294967295, function () {
  879. if ((l = (127 & this.buf[this.pos]) >>> 0, 128 > this.buf[this.pos++]) || (l = (l | (127 & this.buf[this.pos]) << 7) >>> 0, 128 > this.buf[this.pos++]) || (l = (l | (127 & this.buf[this.pos]) << 14) >>> 0, 128 > this.buf[this.pos++]) || (l = (l | (127 & this.buf[this.pos]) << 21) >>> 0, 128 > this.buf[this.pos++]) || (l = (l | (15 & this.buf[this.pos]) << 28) >>> 0, 128 > this.buf[this.pos++])) return l;
  880. if ((this.pos += 5) > this.len) throw this.pos =
  881. this.len, h(this, 10);
  882. return l
  883. });
  884. m.prototype.int32 = function () {
  885. return 0 | this.uint32()
  886. };
  887. m.prototype.sint32 = function () {
  888. var f = this.uint32();
  889. return f >>> 1 ^ -(1 & f) | 0
  890. };
  891. m.prototype.bool = function () {
  892. return 0 !== this.uint32()
  893. };
  894. m.prototype.fixed32 = function () {
  895. if (this.pos + 4 > this.len) throw h(this, 4);
  896. return e(this.buf, this.pos += 4)
  897. };
  898. m.prototype.sfixed32 = function () {
  899. if (this.pos + 4 > this.len) throw h(this, 4);
  900. return 0 | e(this.buf, this.pos += 4)
  901. };
  902. m.prototype["float"] = function () {
  903. if (this.pos + 4 > this.len) throw h(this, 4);
  904. var f = b["float"].readFloatLE(this.buf,
  905. this.pos);
  906. return this.pos += 4, f
  907. };
  908. m.prototype["double"] = function () {
  909. if (this.pos + 8 > this.len) throw h(this, 4);
  910. var f = b["float"].readDoubleLE(this.buf, this.pos);
  911. return this.pos += 8, f
  912. };
  913. m.prototype.bytes = function () {
  914. var f = this.uint32(), u = this.pos, v = this.pos + f;
  915. if (v > this.len) throw h(this, f);
  916. return this.pos += f, Array.isArray(this.buf) ? this.buf.slice(u, v) : u === v ? new this.buf.constructor(0) : this.i.call(this.buf, u, v)
  917. };
  918. m.prototype.string = function () {
  919. var f = this.bytes();
  920. return k.read(f, 0, f.length)
  921. };
  922. m.prototype.skip = function (f) {
  923. if ("number" ==
  924. typeof f) {
  925. if (this.pos + f > this.len) throw h(this, f);
  926. this.pos += f
  927. } else {
  928. do if (this.pos >= this.len) throw h(this); while (128 & this.buf[this.pos++])
  929. }
  930. return this
  931. };
  932. m.prototype.skipType = function (f) {
  933. switch (f) {
  934. case 0:
  935. this.skip();
  936. break;
  937. case 1:
  938. this.skip(8);
  939. break;
  940. case 2:
  941. this.skip(this.uint32());
  942. break;
  943. case 3:
  944. for (; 4 != (f = 7 & this.uint32());) this.skipType(f);
  945. break;
  946. case 5:
  947. this.skip(4);
  948. break;
  949. default:
  950. throw Error("invalid wire type " + f + " at offset " + this.pos);
  951. }
  952. return this
  953. };
  954. m.n = function (f) {
  955. a = f;
  956. var u = b.Long ? "toLong" : "toNumber";
  957. b.merge(m.prototype, {
  958. int64: function () {
  959. return n.call(this)[u](!1)
  960. }, uint64: function () {
  961. return n.call(this)[u](!0)
  962. }, sint64: function () {
  963. return n.call(this).zzDecode()[u](!1)
  964. }, fixed64: function () {
  965. return d.call(this)[u](!0)
  966. }, sfixed64: function () {
  967. return d.call(this)[u](!1)
  968. }
  969. })
  970. }
  971. }, {15: 15}], 10: [function (p, w) {
  972. function h(e) {
  973. m.call(this, e)
  974. }
  975.  
  976. w.exports = h;
  977. var m = p(9);
  978. (h.prototype = Object.create(m.prototype)).constructor = h;
  979. var n = p(15);
  980. n.Buffer && (h.prototype.i = n.Buffer.prototype.slice);
  981. h.prototype.string = function () {
  982. var e =
  983. this.uint32();
  984. return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + e, this.len))
  985. }
  986. }, {15: 15, 9: 9}], 11: [function (p, w) {
  987. w.exports = {}
  988. }, {}], 12: [function (p, w, h) {
  989. h.Service = p(13)
  990. }, {13: 13}], 13: [function (p, w) {
  991. function h(n, e, d) {
  992. if ("function" != typeof n) throw TypeError("rpcImpl must be a function");
  993. m.EventEmitter.call(this);
  994. this.rpcImpl = n;
  995. this.requestDelimited = !!e;
  996. this.responseDelimited = !!d
  997. }
  998.  
  999. w.exports = h;
  1000. var m = p(15);
  1001. ((h.prototype = Object.create(m.EventEmitter.prototype)).constructor = h).prototype.rpcCall = function k(e,
  1002. d, a, b, c) {
  1003. if (!b) throw TypeError("request must be specified");
  1004. var l = this;
  1005. if (!c) return m.asPromise(k, l, e, d, a, b);
  1006. if (!l.rpcImpl) return setTimeout(function () {
  1007. c(Error("already ended"))
  1008. }, 0), z;
  1009. try {
  1010. return l.rpcImpl(e, d[l.requestDelimited ? "encodeDelimited" : "encode"](b).finish(), function (q, f) {
  1011. if (q) return l.emit("error", q, e), c(q);
  1012. if (null === f) return l.end(!0), z;
  1013. if (!(f instanceof a)) try {
  1014. f = a[l.responseDelimited ? "decodeDelimited" : "decode"](f)
  1015. } catch (u) {
  1016. return l.emit("error", u, e), c(u)
  1017. }
  1018. return l.emit("data", f, e), c(null,
  1019. f)
  1020. })
  1021. } catch (q) {
  1022. return l.emit("error", q, e), setTimeout(function () {
  1023. c(q)
  1024. }, 0), z
  1025. }
  1026. };
  1027. h.prototype.end = function (e) {
  1028. return this.rpcImpl && (e || this.rpcImpl(null, null, null), this.rpcImpl = null, this.emit("end").off()), this
  1029. }
  1030. }, {15: 15}], 14: [function (p, w) {
  1031. function h(a, b) {
  1032. this.lo = a >>> 0;
  1033. this.hi = b >>> 0
  1034. }
  1035.  
  1036. w.exports = h;
  1037. var m = p(15), n = h.zero = new h(0, 0);
  1038. n.toNumber = function () {
  1039. return 0
  1040. };
  1041. n.zzEncode = n.zzDecode = function () {
  1042. return this
  1043. };
  1044. n.length = function () {
  1045. return 1
  1046. };
  1047. var e = h.zeroHash = "\x00\x00\x00\x00\x00\x00\x00\x00";
  1048. h.fromNumber = function (a) {
  1049. if (0 ===
  1050. a) return n;
  1051. var b = 0 > a;
  1052. b && (a = -a);
  1053. var c = a >>> 0;
  1054. a = (a - c) / 4294967296 >>> 0;
  1055. return b && (a = ~a >>> 0, c = ~c >>> 0, 4294967295 < ++c && (c = 0, 4294967295 < ++a && (a = 0))), new h(c, a)
  1056. };
  1057. h.from = function (a) {
  1058. if ("number" == typeof a) return h.fromNumber(a);
  1059. if (m.isString(a)) {
  1060. if (!m.Long) return h.fromNumber(parseInt(a, 10));
  1061. a = m.Long.fromString(a)
  1062. }
  1063. return a.low || a.high ? new h(a.low >>> 0, a.high >>> 0) : n
  1064. };
  1065. h.prototype.toNumber = function (a) {
  1066. if (!a && this.hi >>> 31) {
  1067. a = 1 + ~this.lo >>> 0;
  1068. var b = ~this.hi >>> 0;
  1069. return a || (b = b + 1 >>> 0), -(a + 4294967296 * b)
  1070. }
  1071. return this.lo +
  1072. 4294967296 * this.hi
  1073. };
  1074. h.prototype.toLong = function (a) {
  1075. return m.Long ? new m.Long(0 | this.lo, 0 | this.hi, !!a) : {
  1076. low: 0 | this.lo,
  1077. high: 0 | this.hi,
  1078. unsigned: !!a
  1079. }
  1080. };
  1081. var d = String.prototype.charCodeAt;
  1082. h.fromHash = function (a) {
  1083. return a === e ? n : new h((d.call(a, 0) | d.call(a, 1) << 8 | d.call(a, 2) << 16 | d.call(a, 3) << 24) >>> 0, (d.call(a, 4) | d.call(a, 5) << 8 | d.call(a, 6) << 16 | d.call(a, 7) << 24) >>> 0)
  1084. };
  1085. h.prototype.toHash = function () {
  1086. return String.fromCharCode(255 & this.lo, this.lo >>> 8 & 255, this.lo >>> 16 & 255, this.lo >>> 24, 255 & this.hi, this.hi >>> 8 & 255, this.hi >>>
  1087. 16 & 255, this.hi >>> 24)
  1088. };
  1089. h.prototype.zzEncode = function () {
  1090. var a = this.hi >> 31;
  1091. return this.hi = ((this.hi << 1 | this.lo >>> 31) ^ a) >>> 0, this.lo = (this.lo << 1 ^ a) >>> 0, this
  1092. };
  1093. h.prototype.zzDecode = function () {
  1094. var a = -(1 & this.lo);
  1095. return this.lo = ((this.lo >>> 1 | this.hi << 31) ^ a) >>> 0, this.hi = (this.hi >>> 1 ^ a) >>> 0, this
  1096. };
  1097. h.prototype.length = function () {
  1098. var a = this.lo, b = (this.lo >>> 28 | this.hi << 4) >>> 0, c = this.hi >>> 24;
  1099. return 0 === c ? 0 === b ? 16384 > a ? 128 > a ? 1 : 2 : 2097152 > a ? 3 : 4 : 16384 > b ? 128 > b ? 5 : 6 : 2097152 > b ? 7 : 8 : 128 > c ? 9 : 10
  1100. }
  1101. }, {15: 15}], 15: [function (p, w,
  1102. h) {
  1103. function m(e, d, a) {
  1104. for (var b = Object.keys(d), c = 0; c < b.length; ++c) e[b[c]] !== z && a || (e[b[c]] = d[b[c]]);
  1105. return e
  1106. }
  1107.  
  1108. function n(e) {
  1109. function d(a, b) {
  1110. if (!(this instanceof d)) return new d(a, b);
  1111. Object.defineProperty(this, "message", {
  1112. get: function () {
  1113. return a
  1114. }
  1115. });
  1116. Error.captureStackTrace ? Error.captureStackTrace(this, d) : Object.defineProperty(this, "stack", {value: Error().stack || ""});
  1117. b && m(this, b)
  1118. }
  1119.  
  1120. return (d.prototype = Object.create(Error.prototype)).constructor = d, Object.defineProperty(d.prototype, "name", {
  1121. get: function () {
  1122. return e
  1123. }
  1124. }),
  1125. d.prototype.toString = function () {
  1126. return this.name + ": " + this.message
  1127. }, d
  1128. }
  1129.  
  1130. h.asPromise = p(1);
  1131. h.base64 = p(2);
  1132. h.EventEmitter = p(3);
  1133. h["float"] = p(4);
  1134. h.inquire = p(5);
  1135. h.utf8 = p(7);
  1136. h.pool = p(6);
  1137. h.LongBits = p(14);
  1138. h.global = "undefined" != typeof window && window || "undefined" != typeof global && global || "undefined" != typeof self && self || this;
  1139. h.emptyArray = Object.freeze ? Object.freeze([]) : [];
  1140. h.emptyObject = Object.freeze ? Object.freeze({}) : {};
  1141. h.isNode = !!(h.global.process && h.global.process.versions && h.global.process.versions.node);
  1142. h.isInteger =
  1143. Number.isInteger || function (e) {
  1144. return "number" == typeof e && isFinite(e) && Math.floor(e) === e
  1145. };
  1146. h.isString = function (e) {
  1147. return "string" == typeof e || e instanceof String
  1148. };
  1149. h.isObject = function (e) {
  1150. return e && "object" == typeof e
  1151. };
  1152. h.isset = h.isSet = function (e, d) {
  1153. var a = e[d];
  1154. return !(null == a || !e.hasOwnProperty(d)) && ("object" != typeof a || 0 < (Array.isArray(a) ? a.length : Object.keys(a).length))
  1155. };
  1156. h.Buffer = function () {
  1157. try {
  1158. var e = h.inquire("buffer").Buffer;
  1159. return e.prototype.utf8Write ? e : null
  1160. } catch (d) {
  1161. return null
  1162. }
  1163. }();
  1164. h.r = null;
  1165. h.u = null;
  1166. h.newBuffer = function (e) {
  1167. return "number" == typeof e ? h.Buffer ? h.u(e) : new h.Array(e) : h.Buffer ? h.r(e) : "undefined" == typeof Uint8Array ? e : new Uint8Array(e)
  1168. };
  1169. h.Array = "undefined" != typeof Uint8Array ? Uint8Array : Array;
  1170. h.Long = h.global.dcodeIO && h.global.dcodeIO.Long || h.global.Long || h.inquire("long");
  1171. h.key2Re = /^true|false|0|1$/;
  1172. h.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
  1173. h.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
  1174. h.longToHash = function (e) {
  1175. return e ? h.LongBits.from(e).toHash() : h.LongBits.zeroHash
  1176. };
  1177. h.longFromHash = function (e,
  1178. d) {
  1179. var a = h.LongBits.fromHash(e);
  1180. return h.Long ? h.Long.fromBits(a.lo, a.hi, d) : a.toNumber(!!d)
  1181. };
  1182. h.merge = m;
  1183. h.lcFirst = function (e) {
  1184. return e.charAt(0).toLowerCase() + e.substring(1)
  1185. };
  1186. h.newError = n;
  1187. h.ProtocolError = n("ProtocolError");
  1188. h.oneOfGetter = function (e) {
  1189. for (var d = {}, a = 0; a < e.length; ++a) d[e[a]] = 1;
  1190. return function () {
  1191. for (var b = Object.keys(this), c = b.length - 1; -1 < c; --c) if (1 === d[b[c]] && this[b[c]] !== z && null !== this[b[c]]) return b[c]
  1192. }
  1193. };
  1194. h.oneOfSetter = function (e) {
  1195. return function (d) {
  1196. for (var a = 0; a < e.length; ++a) e[a] !== d &&
  1197. delete this[e[a]]
  1198. }
  1199. };
  1200. h.toJSONOptions = {longs: String, enums: String, bytes: String, json: !0};
  1201. h.n = function () {
  1202. var e = h.Buffer;
  1203. e ? (h.r = e.from !== Uint8Array.from && e.from || function (d, a) {
  1204. return new e(d, a)
  1205. }, h.u = e.allocUnsafe || function (d) {
  1206. return new e(d)
  1207. }) : h.r = h.u = null
  1208. }
  1209. }, {1: 1, 14: 14, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7}], 16: [function (p, w) {
  1210. function h(g, t, x) {
  1211. this.fn = g;
  1212. this.len = t;
  1213. this.next = z;
  1214. this.val = x
  1215. }
  1216.  
  1217. function m() {
  1218. }
  1219.  
  1220. function n(g) {
  1221. this.head = g.head;
  1222. this.tail = g.tail;
  1223. this.len = g.len;
  1224. this.next = g.states
  1225. }
  1226.  
  1227. function e() {
  1228. this.len = 0;
  1229. this.tail = this.head =
  1230. new h(m, 0, 0);
  1231. this.states = null
  1232. }
  1233.  
  1234. function d(g, t, x) {
  1235. t[x] = 255 & g
  1236. }
  1237.  
  1238. function a(g, t) {
  1239. this.len = g;
  1240. this.next = z;
  1241. this.val = t
  1242. }
  1243.  
  1244. function b(g, t, x) {
  1245. for (; g.hi;) t[x++] = 127 & g.lo | 128, g.lo = (g.lo >>> 7 | g.hi << 25) >>> 0, g.hi >>>= 7;
  1246. for (; 127 < g.lo;) t[x++] = 127 & g.lo | 128, g.lo >>>= 7;
  1247. t[x++] = g.lo
  1248. }
  1249.  
  1250. function c(g, t, x) {
  1251. t[x] = 255 & g;
  1252. t[x + 1] = g >>> 8 & 255;
  1253. t[x + 2] = g >>> 16 & 255;
  1254. t[x + 3] = g >>> 24
  1255. }
  1256.  
  1257. w.exports = e;
  1258. var k, l = p(15), q = l.LongBits, f = l.base64, u = l.utf8;
  1259. e.create = l.Buffer ? function () {
  1260. return (e.create = function () {
  1261. return new k
  1262. })()
  1263. } : function () {
  1264. return new e
  1265. };
  1266. e.alloc = function (g) {
  1267. return new l.Array(g)
  1268. };
  1269. l.Array !== Array && (e.alloc = l.pool(e.alloc, l.Array.prototype.subarray));
  1270. e.prototype.e = function (g, t, x) {
  1271. return this.tail = this.tail.next = new h(g, t, x), this.len += t, this
  1272. };
  1273. (a.prototype = Object.create(h.prototype)).fn = function (g, t, x) {
  1274. for (; 127 < g;) t[x++] = 127 & g | 128, g >>>= 7;
  1275. t[x] = g
  1276. };
  1277. e.prototype.uint32 = function (g) {
  1278. return this.len += (this.tail = this.tail.next = new a(128 > (g >>>= 0) ? 1 : 16384 > g ? 2 : 2097152 > g ? 3 : 268435456 > g ? 4 : 5, g)).len, this
  1279. };
  1280. e.prototype.int32 = function (g) {
  1281. return 0 > g ? this.e(b, 10, q.fromNumber(g)) : this.uint32(g)
  1282. };
  1283. e.prototype.sint32 =
  1284. function (g) {
  1285. return this.uint32((g << 1 ^ g >> 31) >>> 0)
  1286. };
  1287. e.prototype.int64 = e.prototype.uint64 = function (g) {
  1288. g = q.from(g);
  1289. return this.e(b, g.length(), g)
  1290. };
  1291. e.prototype.sint64 = function (g) {
  1292. g = q.from(g).zzEncode();
  1293. return this.e(b, g.length(), g)
  1294. };
  1295. e.prototype.bool = function (g) {
  1296. return this.e(d, 1, g ? 1 : 0)
  1297. };
  1298. e.prototype.sfixed32 = e.prototype.fixed32 = function (g) {
  1299. return this.e(c, 4, g >>> 0)
  1300. };
  1301. e.prototype.sfixed64 = e.prototype.fixed64 = function (g) {
  1302. g = q.from(g);
  1303. return this.e(c, 4, g.lo).e(c, 4, g.hi)
  1304. };
  1305. e.prototype["float"] = function (g) {
  1306. return this.e(l["float"].writeFloatLE,
  1307. 4, g)
  1308. };
  1309. e.prototype["double"] = function (g) {
  1310. return this.e(l["float"].writeDoubleLE, 8, g)
  1311. };
  1312. var v = l.Array.prototype.set ? function (g, t, x) {
  1313. t.set(g, x)
  1314. } : function (g, t, x) {
  1315. for (var B = 0; B < g.length; ++B) t[x + B] = g[B]
  1316. };
  1317. e.prototype.bytes = function (g) {
  1318. var t = g.length >>> 0;
  1319. if (!t) return this.e(d, 1, 0);
  1320. if (l.isString(g)) {
  1321. var x = e.alloc(t = f.length(g));
  1322. f.decode(g, x, 0);
  1323. g = x
  1324. }
  1325. return this.uint32(t).e(v, t, g)
  1326. };
  1327. e.prototype.string = function (g) {
  1328. var t = u.length(g);
  1329. return t ? this.uint32(t).e(u.write, t, g) : this.e(d, 1, 0)
  1330. };
  1331. e.prototype.fork = function () {
  1332. return this.states =
  1333. new n(this), this.head = this.tail = new h(m, 0, 0), this.len = 0, this
  1334. };
  1335. e.prototype.reset = function () {
  1336. return this.states ? (this.head = this.states.head, this.tail = this.states.tail, this.len = this.states.len, this.states = this.states.next) : (this.head = this.tail = new h(m, 0, 0), this.len = 0), this
  1337. };
  1338. e.prototype.ldelim = function () {
  1339. var g = this.head, t = this.tail, x = this.len;
  1340. return this.reset().uint32(x), x && (this.tail.next = g.next, this.tail = t, this.len += x), this
  1341. };
  1342. e.prototype.finish = function () {
  1343. for (var g = this.head.next, t = this.constructor.alloc(this.len),
  1344. x = 0; g;) g.fn(g.val, t, x), x += g.len, g = g.next;
  1345. return t
  1346. };
  1347. e.n = function (g) {
  1348. k = g
  1349. }
  1350. }, {15: 15}], 17: [function (p, w) {
  1351. function h() {
  1352. n.call(this)
  1353. }
  1354.  
  1355. function m(b, c, k) {
  1356. 40 > b.length ? e.utf8.write(b, c, k) : c.utf8Write(b, k)
  1357. }
  1358.  
  1359. w.exports = h;
  1360. var n = p(16);
  1361. (h.prototype = Object.create(n.prototype)).constructor = h;
  1362. var e = p(15), d = e.Buffer;
  1363. h.alloc = function (b) {
  1364. return (h.alloc = e.u)(b)
  1365. };
  1366. var a = d && d.prototype instanceof Uint8Array && "set" === d.prototype.set.name ? function (b, c, k) {
  1367. c.set(b, k)
  1368. } : function (b, c, k) {
  1369. if (b.copy) b.copy(c, k, 0, b.length); else for (var l =
  1370. 0; l < b.length;) c[k++] = b[l++]
  1371. };
  1372. h.prototype.bytes = function (b) {
  1373. e.isString(b) && (b = e.r(b, "base64"));
  1374. var c = b.length >>> 0;
  1375. return this.uint32(c), c && this.e(a, c, b), this
  1376. };
  1377. h.prototype.string = function (b) {
  1378. var c = d.byteLength(b);
  1379. return this.uint32(c), c && this.e(m, c, b), this
  1380. }
  1381. }, {15: 15, 16: 16}]
  1382. };
  1383. var A = {};
  1384. var r = function h(w) {
  1385. var m = A[w];
  1386. return m || y[w][0].call(m = A[w] = {exports: {}}, h, m, m.exports), m.exports
  1387. }(8);
  1388. r.util.global.protobuf = r;
  1389. "function" == typeof define && define.amd && define(["long"], function (w) {
  1390. return w && w.isLong && (r.util.Long =
  1391. w, r.configure()), r
  1392. });
  1393. "object" == typeof module && module && module.exports && (module.exports = r)
  1394. }();
  1395. (function (z) {
  1396. var y = z.Reader, A = z.Writer, r = z.util, p = z.roots["default"] || (z.roots["default"] = {});
  1397. p.bilibili = function () {
  1398. var w = {};
  1399. w.community = function () {
  1400. var h = {};
  1401. h.service = function () {
  1402. var m = {};
  1403. m.dm = function () {
  1404. var n = {};
  1405. n.v1 = function () {
  1406. var e = {};
  1407. e.DmWebViewReply = function () {
  1408. function d(a) {
  1409. this.specialDms = [];
  1410. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  1411. }
  1412.  
  1413. d.prototype.state = 0;
  1414. d.prototype.text = "";
  1415. d.prototype.textSide = "";
  1416. d.prototype.dmSge = null;
  1417. d.prototype.flag = null;
  1418. d.prototype.specialDms =
  1419. r.emptyArray;
  1420. d.create = function (a) {
  1421. return new d(a)
  1422. };
  1423. d.encode = function (a, b) {
  1424. b || (b = A.create());
  1425. null != a.state && Object.hasOwnProperty.call(a, "state") && b.uint32(8).int32(a.state);
  1426. null != a.text && Object.hasOwnProperty.call(a, "text") && b.uint32(18).string(a.text);
  1427. null != a.textSide && Object.hasOwnProperty.call(a, "textSide") && b.uint32(26).string(a.textSide);
  1428. null != a.dmSge && Object.hasOwnProperty.call(a, "dmSge") && p.bilibili.community.service.dm.v1.DmSegConfig.encode(a.dmSge, b.uint32(34).fork()).ldelim();
  1429. null != a.flag &&
  1430. Object.hasOwnProperty.call(a, "flag") && p.bilibili.community.service.dm.v1.DanmakuFlagConfig.encode(a.flag, b.uint32(42).fork()).ldelim();
  1431. if (null != a.specialDms && a.specialDms.length) for (var c = 0; c < a.specialDms.length; ++c) b.uint32(50).string(a.specialDms[c]);
  1432. return b
  1433. };
  1434. d.encodeDelimited = function (a, b) {
  1435. return this.encode(a, b).ldelim()
  1436. };
  1437. d.decode = function (a, b) {
  1438. a instanceof y || (a = y.create(a));
  1439. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DmWebViewReply; a.pos < c;) {
  1440. var l = a.uint32();
  1441. switch (l >>> 3) {
  1442. case 1:
  1443. k.state = a.int32();
  1444. break;
  1445. case 2:
  1446. k.text = a.string();
  1447. break;
  1448. case 3:
  1449. k.textSide = a.string();
  1450. break;
  1451. case 4:
  1452. k.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.decode(a, a.uint32());
  1453. break;
  1454. case 5:
  1455. k.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.decode(a, a.uint32());
  1456. break;
  1457. case 6:
  1458. k.specialDms && k.specialDms.length || (k.specialDms = []);
  1459. k.specialDms.push(a.string());
  1460. break;
  1461. default:
  1462. a.skipType(l & 7)
  1463. }
  1464. }
  1465. return k
  1466. };
  1467. d.decodeDelimited = function (a) {
  1468. a instanceof y || (a = new y(a));
  1469. return this.decode(a,
  1470. a.uint32())
  1471. };
  1472. d.verify = function (a) {
  1473. if ("object" !== typeof a || null === a) return "object expected";
  1474. if (null != a.state && a.hasOwnProperty("state") && !r.isInteger(a.state)) return "state: integer expected";
  1475. if (null != a.text && a.hasOwnProperty("text") && !r.isString(a.text)) return "text: string expected";
  1476. if (null != a.textSide && a.hasOwnProperty("textSide") && !r.isString(a.textSide)) return "textSide: string expected";
  1477. if (null != a.dmSge && a.hasOwnProperty("dmSge")) {
  1478. var b = p.bilibili.community.service.dm.v1.DmSegConfig.verify(a.dmSge);
  1479. if (b) return "dmSge." + b
  1480. }
  1481. if (null != a.flag && a.hasOwnProperty("flag") && (b = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.verify(a.flag))) return "flag." + b;
  1482. if (null != a.specialDms && a.hasOwnProperty("specialDms")) {
  1483. if (!Array.isArray(a.specialDms)) return "specialDms: array expected";
  1484. for (b = 0; b < a.specialDms.length; ++b) if (!r.isString(a.specialDms[b])) return "specialDms: string[] expected"
  1485. }
  1486. return null
  1487. };
  1488. d.fromObject = function (a) {
  1489. if (a instanceof p.bilibili.community.service.dm.v1.DmWebViewReply) return a;
  1490. var b = new p.bilibili.community.service.dm.v1.DmWebViewReply;
  1491. null != a.state && (b.state = a.state | 0);
  1492. null != a.text && (b.text = String(a.text));
  1493. null != a.textSide && (b.textSide = String(a.textSide));
  1494. if (null != a.dmSge) {
  1495. if ("object" !== typeof a.dmSge) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.dmSge: object expected");
  1496. b.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.fromObject(a.dmSge)
  1497. }
  1498. if (null != a.flag) {
  1499. if ("object" !== typeof a.flag) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.flag: object expected");
  1500. b.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.fromObject(a.flag)
  1501. }
  1502. if (a.specialDms) {
  1503. if (!Array.isArray(a.specialDms)) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.specialDms: array expected");
  1504. b.specialDms = [];
  1505. for (var c = 0; c < a.specialDms.length; ++c) b.specialDms[c] = String(a.specialDms[c])
  1506. }
  1507. return b
  1508. };
  1509. d.toObject = function (a, b) {
  1510. b || (b = {});
  1511. var c = {};
  1512. if (b.arrays || b.defaults) c.specialDms = [];
  1513. b.defaults && (c.state = 0, c.text = "", c.textSide = "", c.dmSge = null, c.flag = null);
  1514. null != a.state && a.hasOwnProperty("state") && (c.state = a.state);
  1515. null != a.text && a.hasOwnProperty("text") && (c.text = a.text);
  1516. null != a.textSide && a.hasOwnProperty("textSide") && (c.textSide = a.textSide);
  1517. null != a.dmSge && a.hasOwnProperty("dmSge") && (c.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.toObject(a.dmSge,
  1518. b));
  1519. null != a.flag && a.hasOwnProperty("flag") && (c.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.toObject(a.flag, b));
  1520. if (a.specialDms && a.specialDms.length) {
  1521. c.specialDms = [];
  1522. for (var k = 0; k < a.specialDms.length; ++k) c.specialDms[k] = a.specialDms[k]
  1523. }
  1524. return c
  1525. };
  1526. d.prototype.toJSON = function () {
  1527. return this.constructor.toObject(this, z.util.toJSONOptions)
  1528. };
  1529. return d
  1530. }();
  1531. e.DmSegConfig = function () {
  1532. function d(a) {
  1533. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  1534. }
  1535.  
  1536. d.prototype.pageSize =
  1537. r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  1538. d.prototype.total = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  1539. d.create = function (a) {
  1540. return new d(a)
  1541. };
  1542. d.encode = function (a, b) {
  1543. b || (b = A.create());
  1544. null != a.pageSize && Object.hasOwnProperty.call(a, "pageSize") && b.uint32(8).int64(a.pageSize);
  1545. null != a.total && Object.hasOwnProperty.call(a, "total") && b.uint32(16).int64(a.total);
  1546. return b
  1547. };
  1548. d.encodeDelimited = function (a, b) {
  1549. return this.encode(a, b).ldelim()
  1550. };
  1551. d.decode = function (a, b) {
  1552. a instanceof y || (a = y.create(a));
  1553. for (var c = void 0 === b ? a.len : a.pos + b,
  1554. k = new p.bilibili.community.service.dm.v1.DmSegConfig; a.pos < c;) {
  1555. var l = a.uint32();
  1556. switch (l >>> 3) {
  1557. case 1:
  1558. k.pageSize = a.int64();
  1559. break;
  1560. case 2:
  1561. k.total = a.int64();
  1562. break;
  1563. default:
  1564. a.skipType(l & 7)
  1565. }
  1566. }
  1567. return k
  1568. };
  1569. d.decodeDelimited = function (a) {
  1570. a instanceof y || (a = new y(a));
  1571. return this.decode(a, a.uint32())
  1572. };
  1573. d.verify = function (a) {
  1574. return "object" !== typeof a || null === a ? "object expected" : null == a.pageSize || !a.hasOwnProperty("pageSize") || r.isInteger(a.pageSize) || a.pageSize && r.isInteger(a.pageSize.low) && r.isInteger(a.pageSize.high) ?
  1575. null == a.total || !a.hasOwnProperty("total") || r.isInteger(a.total) || a.total && r.isInteger(a.total.low) && r.isInteger(a.total.high) ? null : "total: integer|Long expected" : "pageSize: integer|Long expected"
  1576. };
  1577. d.fromObject = function (a) {
  1578. if (a instanceof p.bilibili.community.service.dm.v1.DmSegConfig) return a;
  1579. var b = new p.bilibili.community.service.dm.v1.DmSegConfig;
  1580. null != a.pageSize && (r.Long ? (b.pageSize = r.Long.fromValue(a.pageSize)).unsigned = !1 : "string" === typeof a.pageSize ? b.pageSize = parseInt(a.pageSize, 10) : "number" ===
  1581. typeof a.pageSize ? b.pageSize = a.pageSize : "object" === typeof a.pageSize && (b.pageSize = (new r.LongBits(a.pageSize.low >>> 0, a.pageSize.high >>> 0)).toNumber()));
  1582. null != a.total && (r.Long ? (b.total = r.Long.fromValue(a.total)).unsigned = !1 : "string" === typeof a.total ? b.total = parseInt(a.total, 10) : "number" === typeof a.total ? b.total = a.total : "object" === typeof a.total && (b.total = (new r.LongBits(a.total.low >>> 0, a.total.high >>> 0)).toNumber()));
  1583. return b
  1584. };
  1585. d.toObject = function (a, b) {
  1586. b || (b = {});
  1587. var c = {};
  1588. if (b.defaults) {
  1589. if (r.Long) {
  1590. var k =
  1591. new r.Long(0, 0, !1);
  1592. c.pageSize = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k
  1593. } else c.pageSize = b.longs === String ? "0" : 0;
  1594. r.Long ? (k = new r.Long(0, 0, !1), c.total = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k) : c.total = b.longs === String ? "0" : 0
  1595. }
  1596. null != a.pageSize && a.hasOwnProperty("pageSize") && (c.pageSize = "number" === typeof a.pageSize ? b.longs === String ? String(a.pageSize) : a.pageSize : b.longs === String ? r.Long.prototype.toString.call(a.pageSize) : b.longs === Number ? (new r.LongBits(a.pageSize.low >>>
  1597. 0, a.pageSize.high >>> 0)).toNumber() : a.pageSize);
  1598. null != a.total && a.hasOwnProperty("total") && (c.total = "number" === typeof a.total ? b.longs === String ? String(a.total) : a.total : b.longs === String ? r.Long.prototype.toString.call(a.total) : b.longs === Number ? (new r.LongBits(a.total.low >>> 0, a.total.high >>> 0)).toNumber() : a.total);
  1599. return c
  1600. };
  1601. d.prototype.toJSON = function () {
  1602. return this.constructor.toObject(this, z.util.toJSONOptions)
  1603. };
  1604. return d
  1605. }();
  1606. e.DanmakuFlagConfig = function () {
  1607. function d(a) {
  1608. if (a) for (var b = Object.keys(a), c = 0; c <
  1609. b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  1610. }
  1611.  
  1612. d.prototype.recFlag = 0;
  1613. d.prototype.recText = "";
  1614. d.prototype.recSwitch = 0;
  1615. d.create = function (a) {
  1616. return new d(a)
  1617. };
  1618. d.encode = function (a, b) {
  1619. b || (b = A.create());
  1620. null != a.recFlag && Object.hasOwnProperty.call(a, "recFlag") && b.uint32(8).int32(a.recFlag);
  1621. null != a.recText && Object.hasOwnProperty.call(a, "recText") && b.uint32(18).string(a.recText);
  1622. null != a.recSwitch && Object.hasOwnProperty.call(a, "recSwitch") && b.uint32(24).int32(a.recSwitch);
  1623. return b
  1624. };
  1625. d.encodeDelimited = function (a,
  1626. b) {
  1627. return this.encode(a, b).ldelim()
  1628. };
  1629. d.decode = function (a, b) {
  1630. a instanceof y || (a = y.create(a));
  1631. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DanmakuFlagConfig; a.pos < c;) {
  1632. var l = a.uint32();
  1633. switch (l >>> 3) {
  1634. case 1:
  1635. k.recFlag = a.int32();
  1636. break;
  1637. case 2:
  1638. k.recText = a.string();
  1639. break;
  1640. case 3:
  1641. k.recSwitch = a.int32();
  1642. break;
  1643. default:
  1644. a.skipType(l & 7)
  1645. }
  1646. }
  1647. return k
  1648. };
  1649. d.decodeDelimited = function (a) {
  1650. a instanceof y || (a = new y(a));
  1651. return this.decode(a, a.uint32())
  1652. };
  1653. d.verify = function (a) {
  1654. return "object" !== typeof a ||
  1655. null === a ? "object expected" : null != a.recFlag && a.hasOwnProperty("recFlag") && !r.isInteger(a.recFlag) ? "recFlag: integer expected" : null != a.recText && a.hasOwnProperty("recText") && !r.isString(a.recText) ? "recText: string expected" : null != a.recSwitch && a.hasOwnProperty("recSwitch") && !r.isInteger(a.recSwitch) ? "recSwitch: integer expected" : null
  1656. };
  1657. d.fromObject = function (a) {
  1658. if (a instanceof p.bilibili.community.service.dm.v1.DanmakuFlagConfig) return a;
  1659. var b = new p.bilibili.community.service.dm.v1.DanmakuFlagConfig;
  1660. null !=
  1661. a.recFlag && (b.recFlag = a.recFlag | 0);
  1662. null != a.recText && (b.recText = String(a.recText));
  1663. null != a.recSwitch && (b.recSwitch = a.recSwitch | 0);
  1664. return b
  1665. };
  1666. d.toObject = function (a, b) {
  1667. b || (b = {});
  1668. var c = {};
  1669. b.defaults && (c.recFlag = 0, c.recText = "", c.recSwitch = 0);
  1670. null != a.recFlag && a.hasOwnProperty("recFlag") && (c.recFlag = a.recFlag);
  1671. null != a.recText && a.hasOwnProperty("recText") && (c.recText = a.recText);
  1672. null != a.recSwitch && a.hasOwnProperty("recSwitch") && (c.recSwitch = a.recSwitch);
  1673. return c
  1674. };
  1675. d.prototype.toJSON = function () {
  1676. return this.constructor.toObject(this,
  1677. z.util.toJSONOptions)
  1678. };
  1679. return d
  1680. }();
  1681. e.DmSegMobileReply = function () {
  1682. function d(a) {
  1683. this.elems = [];
  1684. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  1685. }
  1686.  
  1687. d.prototype.elems = r.emptyArray;
  1688. d.create = function (a) {
  1689. return new d(a)
  1690. };
  1691. d.encode = function (a, b) {
  1692. b || (b = A.create());
  1693. if (null != a.elems && a.elems.length) for (var c = 0; c < a.elems.length; ++c) p.bilibili.community.service.dm.v1.DanmakuElem.encode(a.elems[c], b.uint32(10).fork()).ldelim();
  1694. return b
  1695. };
  1696. d.encodeDelimited = function (a, b) {
  1697. return this.encode(a,
  1698. b).ldelim()
  1699. };
  1700. d.decode = function (a, b) {
  1701. a instanceof y || (a = y.create(a));
  1702. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DmSegMobileReply; a.pos < c;) {
  1703. var l = a.uint32();
  1704. switch (l >>> 3) {
  1705. case 1:
  1706. k.elems && k.elems.length || (k.elems = []);
  1707. k.elems.push(p.bilibili.community.service.dm.v1.DanmakuElem.decode(a, a.uint32()));
  1708. break;
  1709. default:
  1710. a.skipType(l & 7)
  1711. }
  1712. }
  1713. return k
  1714. };
  1715. d.decodeDelimited = function (a) {
  1716. a instanceof y || (a = new y(a));
  1717. return this.decode(a, a.uint32())
  1718. };
  1719. d.verify = function (a) {
  1720. if ("object" !== typeof a ||
  1721. null === a) return "object expected";
  1722. if (null != a.elems && a.hasOwnProperty("elems")) {
  1723. if (!Array.isArray(a.elems)) return "elems: array expected";
  1724. for (var b = 0; b < a.elems.length; ++b) {
  1725. var c = p.bilibili.community.service.dm.v1.DanmakuElem.verify(a.elems[b]);
  1726. if (c) return "elems." + c
  1727. }
  1728. }
  1729. return null
  1730. };
  1731. d.fromObject = function (a) {
  1732. if (a instanceof p.bilibili.community.service.dm.v1.DmSegMobileReply) return a;
  1733. var b = new p.bilibili.community.service.dm.v1.DmSegMobileReply;
  1734. if (a.elems) {
  1735. if (!Array.isArray(a.elems)) throw TypeError(".bilibili.community.service.dm.v1.DmSegMobileReply.elems: array expected");
  1736. b.elems = [];
  1737. for (var c = 0; c < a.elems.length; ++c) {
  1738. if ("object" !== typeof a.elems[c]) throw TypeError(".bilibili.community.service.dm.v1.DmSegMobileReply.elems: object expected");
  1739. b.elems[c] = p.bilibili.community.service.dm.v1.DanmakuElem.fromObject(a.elems[c])
  1740. }
  1741. }
  1742. return b
  1743. };
  1744. d.toObject = function (a, b) {
  1745. b || (b = {});
  1746. var c = {};
  1747. if (b.arrays || b.defaults) c.elems = [];
  1748. if (a.elems && a.elems.length) {
  1749. c.elems = [];
  1750. for (var k = 0; k < a.elems.length; ++k) c.elems[k] = p.bilibili.community.service.dm.v1.DanmakuElem.toObject(a.elems[k], b)
  1751. }
  1752. return c
  1753. };
  1754. d.prototype.toJSON = function () {
  1755. return this.constructor.toObject(this, z.util.toJSONOptions)
  1756. };
  1757. return d
  1758. }();
  1759. e.DanmakuElem = function () {
  1760. function d(a) {
  1761. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  1762. }
  1763.  
  1764. d.prototype.id = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  1765. d.prototype.progress = 0;
  1766. d.prototype.mode = 0;
  1767. d.prototype.fontsize = 0;
  1768. d.prototype.color = 0;
  1769. d.prototype.midHash = "";
  1770. d.prototype.content = "";
  1771. d.prototype.ctime = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  1772. d.prototype.weight = 0;
  1773. d.prototype.action = "";
  1774. d.prototype.pool =
  1775. 0;
  1776. d.prototype.idStr = "";
  1777. d.create = function (a) {
  1778. return new d(a)
  1779. };
  1780. d.encode = function (a, b) {
  1781. b || (b = A.create());
  1782. null != a.id && Object.hasOwnProperty.call(a, "id") && b.uint32(8).int64(a.id);
  1783. null != a.progress && Object.hasOwnProperty.call(a, "progress") && b.uint32(16).int32(a.progress);
  1784. null != a.mode && Object.hasOwnProperty.call(a, "mode") && b.uint32(24).int32(a.mode);
  1785. null != a.fontsize && Object.hasOwnProperty.call(a, "fontsize") && b.uint32(32).int32(a.fontsize);
  1786. null != a.color && Object.hasOwnProperty.call(a, "color") && b.uint32(40).uint32(a.color);
  1787. null != a.midHash && Object.hasOwnProperty.call(a, "midHash") && b.uint32(50).string(a.midHash);
  1788. null != a.content && Object.hasOwnProperty.call(a, "content") && b.uint32(58).string(a.content);
  1789. null != a.ctime && Object.hasOwnProperty.call(a, "ctime") && b.uint32(64).int64(a.ctime);
  1790. null != a.weight && Object.hasOwnProperty.call(a, "weight") && b.uint32(72).int32(a.weight);
  1791. null != a.action && Object.hasOwnProperty.call(a, "action") && b.uint32(82).string(a.action);
  1792. null != a.pool && Object.hasOwnProperty.call(a, "pool") && b.uint32(88).int32(a.pool);
  1793. null != a.idStr && Object.hasOwnProperty.call(a, "idStr") && b.uint32(98).string(a.idStr);
  1794. return b
  1795. };
  1796. d.encodeDelimited = function (a, b) {
  1797. return this.encode(a, b).ldelim()
  1798. };
  1799. d.decode = function (a, b) {
  1800. a instanceof y || (a = y.create(a));
  1801. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DanmakuElem; a.pos < c;) {
  1802. var l = a.uint32();
  1803. switch (l >>> 3) {
  1804. case 1:
  1805. k.id = a.int64();
  1806. break;
  1807. case 2:
  1808. k.progress = a.int32();
  1809. break;
  1810. case 3:
  1811. k.mode = a.int32();
  1812. break;
  1813. case 4:
  1814. k.fontsize = a.int32();
  1815. break;
  1816. case 5:
  1817. k.color = a.uint32();
  1818. break;
  1819. case 6:
  1820. k.midHash = a.string();
  1821. break;
  1822. case 7:
  1823. k.content = a.string();
  1824. break;
  1825. case 8:
  1826. k.ctime = a.int64();
  1827. break;
  1828. case 9:
  1829. k.weight = a.int32();
  1830. break;
  1831. case 10:
  1832. k.action = a.string();
  1833. break;
  1834. case 11:
  1835. k.pool = a.int32();
  1836. break;
  1837. case 12:
  1838. k.idStr = a.string();
  1839. break;
  1840. default:
  1841. a.skipType(l & 7)
  1842. }
  1843. }
  1844. return k
  1845. };
  1846. d.decodeDelimited = function (a) {
  1847. a instanceof y || (a = new y(a));
  1848. return this.decode(a, a.uint32())
  1849. };
  1850. d.verify = function (a) {
  1851. return "object" !== typeof a || null === a ? "object expected" : null == a.id || !a.hasOwnProperty("id") || r.isInteger(a.id) || a.id && r.isInteger(a.id.low) &&
  1852. r.isInteger(a.id.high) ? null != a.progress && a.hasOwnProperty("progress") && !r.isInteger(a.progress) ? "progress: integer expected" : null != a.mode && a.hasOwnProperty("mode") && !r.isInteger(a.mode) ? "mode: integer expected" : null != a.fontsize && a.hasOwnProperty("fontsize") && !r.isInteger(a.fontsize) ? "fontsize: integer expected" : null != a.color && a.hasOwnProperty("color") && !r.isInteger(a.color) ? "color: integer expected" : null != a.midHash && a.hasOwnProperty("midHash") && !r.isString(a.midHash) ? "midHash: string expected" : null !=
  1853. a.content && a.hasOwnProperty("content") && !r.isString(a.content) ? "content: string expected" : null == a.ctime || !a.hasOwnProperty("ctime") || r.isInteger(a.ctime) || a.ctime && r.isInteger(a.ctime.low) && r.isInteger(a.ctime.high) ? null != a.weight && a.hasOwnProperty("weight") && !r.isInteger(a.weight) ? "weight: integer expected" : null != a.action && a.hasOwnProperty("action") && !r.isString(a.action) ? "action: string expected" : null != a.pool && a.hasOwnProperty("pool") && !r.isInteger(a.pool) ? "pool: integer expected" : null != a.idStr &&
  1854. a.hasOwnProperty("idStr") && !r.isString(a.idStr) ? "idStr: string expected" : null : "ctime: integer|Long expected" : "id: integer|Long expected"
  1855. };
  1856. d.fromObject = function (a) {
  1857. if (a instanceof p.bilibili.community.service.dm.v1.DanmakuElem) return a;
  1858. var b = new p.bilibili.community.service.dm.v1.DanmakuElem;
  1859. null != a.id && (r.Long ? (b.id = r.Long.fromValue(a.id)).unsigned = !1 : "string" === typeof a.id ? b.id = parseInt(a.id, 10) : "number" === typeof a.id ? b.id = a.id : "object" === typeof a.id && (b.id = (new r.LongBits(a.id.low >>> 0, a.id.high >>>
  1860. 0)).toNumber()));
  1861. null != a.progress && (b.progress = a.progress | 0);
  1862. null != a.mode && (b.mode = a.mode | 0);
  1863. null != a.fontsize && (b.fontsize = a.fontsize | 0);
  1864. null != a.color && (b.color = a.color >>> 0);
  1865. null != a.midHash && (b.midHash = String(a.midHash));
  1866. null != a.content && (b.content = String(a.content));
  1867. null != a.ctime && (r.Long ? (b.ctime = r.Long.fromValue(a.ctime)).unsigned = !1 : "string" === typeof a.ctime ? b.ctime = parseInt(a.ctime, 10) : "number" === typeof a.ctime ? b.ctime = a.ctime : "object" === typeof a.ctime && (b.ctime = (new r.LongBits(a.ctime.low >>>
  1868. 0, a.ctime.high >>> 0)).toNumber()));
  1869. null != a.weight && (b.weight = a.weight | 0);
  1870. null != a.action && (b.action = String(a.action));
  1871. null != a.pool && (b.pool = a.pool | 0);
  1872. null != a.idStr && (b.idStr = String(a.idStr));
  1873. return b
  1874. };
  1875. d.toObject = function (a, b) {
  1876. b || (b = {});
  1877. var c = {};
  1878. if (b.defaults) {
  1879. if (r.Long) {
  1880. var k = new r.Long(0, 0, !1);
  1881. c.id = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k
  1882. } else c.id = b.longs === String ? "0" : 0;
  1883. c.progress = 0;
  1884. c.mode = 0;
  1885. c.fontsize = 0;
  1886. c.color = 0;
  1887. c.midHash = "";
  1888. c.content = "";
  1889. r.Long ? (k = new r.Long(0, 0, !1), c.ctime =
  1890. b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k) : c.ctime = b.longs === String ? "0" : 0;
  1891. c.weight = 0;
  1892. c.action = "";
  1893. c.pool = 0;
  1894. c.idStr = ""
  1895. }
  1896. null != a.id && a.hasOwnProperty("id") && (c.id = "number" === typeof a.id ? b.longs === String ? String(a.id) : a.id : b.longs === String ? r.Long.prototype.toString.call(a.id) : b.longs === Number ? (new r.LongBits(a.id.low >>> 0, a.id.high >>> 0)).toNumber() : a.id);
  1897. null != a.progress && a.hasOwnProperty("progress") && (c.progress = a.progress);
  1898. null != a.mode && a.hasOwnProperty("mode") && (c.mode = a.mode);
  1899. null !=
  1900. a.fontsize && a.hasOwnProperty("fontsize") && (c.fontsize = a.fontsize);
  1901. null != a.color && a.hasOwnProperty("color") && (c.color = a.color);
  1902. null != a.midHash && a.hasOwnProperty("midHash") && (c.midHash = a.midHash);
  1903. null != a.content && a.hasOwnProperty("content") && (c.content = a.content);
  1904. null != a.ctime && a.hasOwnProperty("ctime") && (c.ctime = "number" === typeof a.ctime ? b.longs === String ? String(a.ctime) : a.ctime : b.longs === String ? r.Long.prototype.toString.call(a.ctime) : b.longs === Number ? (new r.LongBits(a.ctime.low >>> 0, a.ctime.high >>>
  1905. 0)).toNumber() : a.ctime);
  1906. null != a.weight && a.hasOwnProperty("weight") && (c.weight = a.weight);
  1907. null != a.action && a.hasOwnProperty("action") && (c.action = a.action);
  1908. null != a.pool && a.hasOwnProperty("pool") && (c.pool = a.pool);
  1909. null != a.idStr && a.hasOwnProperty("idStr") && (c.idStr = a.idStr);
  1910. return c
  1911. };
  1912. d.prototype.toJSON = function () {
  1913. return this.constructor.toObject(this, z.util.toJSONOptions)
  1914. };
  1915. return d
  1916. }();
  1917. return e
  1918. }();
  1919. return n
  1920. }();
  1921. return m
  1922. }();
  1923. return h
  1924. }();
  1925. return w
  1926. }();
  1927. return p
  1928. })(protobuf);
  1929. var proto_seg = protobuf.roots["default"].bilibili.community.service.dm.v1.DmSegMobileReply;
  1930.  
  1931. function htmlEscape(text) {
  1932. return text.replace(/[<>"&]/g, function (match, pos, originalText) {
  1933. switch (match) {
  1934. case "<":
  1935. return "&lt;";
  1936. case ">":
  1937. return "&gt;";
  1938. case "&":
  1939. return "&amp;";
  1940. case "\"":
  1941. return '"';
  1942. }
  1943. });
  1944. }
  1945.  
  1946. function xmlunEscape(content) {
  1947. return content.replace(';', ';')
  1948. .replace(/&amp;/g, '&')
  1949. .replace(/&lt;/g, '&')
  1950. .replace(/&gt;/g, '&')
  1951. .replace(/&apos;/g, '&')
  1952. .replace(/&quot;/g, '&')
  1953. }
  1954.  
  1955. function xml2danmu(sdanmu, user = null) {
  1956. let ldanmu = sdanmu.split('</d><d p=');
  1957.  
  1958. if (ldanmu.length === 1) {
  1959. return []
  1960. }
  1961. let tdanmu = ldanmu[0];
  1962. ldanmu[0] = tdanmu.slice(tdanmu.indexOf('<d p=') + 5, tdanmu.length);
  1963. tdanmu = ldanmu[ldanmu.length - 1];
  1964. ldanmu[ldanmu.length - 1] = tdanmu.slice(0, tdanmu.length - 8);
  1965. for (let i = 0; i < ldanmu.length; i++) {
  1966. let danmu = ldanmu[i]
  1967. let argv = danmu.substring(1, danmu.indexOf('"', 2)).split(',')
  1968. ldanmu[i] = {
  1969. color: Number(argv[3]),
  1970. content: xmlunEscape(danmu.slice(danmu.indexOf('>') + 1, danmu.length)),
  1971. ctime: Number(argv[4]),
  1972. fontsize: Number(argv[2]),
  1973. id: Number(argv[7]),
  1974. idStr: argv[7],
  1975. midHash: argv[6],
  1976. mode: Number(argv[1]),
  1977. progress: Math.round(Number(argv[0]) * 1000),
  1978. weight: 10
  1979. }
  1980. }
  1981. return ldanmu
  1982. }
  1983.  
  1984. async function loadProtoDanmu(url, timeout = null, header = null, retry = 0) {
  1985. const xhr = new XMLHttpRequest();
  1986. xhr.withCredentials = true
  1987. try {
  1988. if (timeout !== null) {
  1989. xhr.timeout = timeout
  1990. } else {
  1991. xhr.timeout = 30000
  1992. }
  1993.  
  1994. xhr.open("get", url, true);
  1995. xhr.responseType = 'arraybuffer';
  1996.  
  1997. if (header !== null) {
  1998. for (let key in header) {
  1999. xhr.setRequestHeader(key, header[key])
  2000. }
  2001. }
  2002.  
  2003. xhr.send()
  2004.  
  2005. return new Promise(
  2006. (resolve) => {
  2007. xhr.onreadystatechange = async () => {
  2008. if (xhr.readyState === 4) {
  2009. if (xhr.status === 200) {
  2010. try {
  2011. let lpdanmu = proto_seg.decode(new Uint8Array(xhr.response));
  2012. lpdanmu.elems.forEach((e) => {
  2013. if (!e.progress) e.progress = 0
  2014. })
  2015. resolve(lpdanmu.elems)
  2016. } catch (e) {
  2017. console.log(e.stack)
  2018. resolve([])
  2019. }
  2020.  
  2021. } else if (xhr.status === 304) {
  2022. resolve(null)
  2023. } else {
  2024. console.log('XhrError=', retry, '/', xhr)
  2025. if (retry < 3) {
  2026. resolve(await loadProtoDanmu(url, timeout, header, retry + 1))
  2027. } else {
  2028. resolve(null)
  2029. }
  2030. }
  2031. }
  2032. }
  2033. }
  2034. )
  2035. } catch (e) {
  2036. console.log('XhrError=', retry, '/', xhr)
  2037. if (retry < 3) {
  2038. return (await loadProtoDanmu(url, timeout, header, retry + 1))
  2039. }
  2040. }
  2041. }
  2042.  
  2043. function savedanmuStandalone(ldanmu, info = null) {
  2044. var end, head;
  2045. head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><i><chatserver>chat.bilibili.com</chatserver><chatid>0</chatid><mission>0</mission><maxlimit>0</maxlimit><state>0</state><real_name>0</real_name><source>DF</source>"
  2046. end = "</i>";
  2047. if ((info !== null)) {
  2048. head += '<info>' + htmlEscape(JSON.stringify(info)) + '</info>';
  2049. }
  2050. return head + ldanmu.join('') + end
  2051. }
  2052.  
  2053.  
  2054. function danmuObject2XML(ldanmu) {
  2055. for (let i = 0, length = ldanmu.length; i < length; i++) {
  2056. let danmu = ldanmu[i]
  2057. ldanmu[i] = `<d p="${(danmu.progress ? danmu.progress : 0) / 1000},${danmu.mode},${danmu.fontsize},${danmu.color},${danmu.ctime},${0},${danmu.midHash},${danmu.idStr}">${htmlEscape(danmu.content)}</d>`
  2058. }
  2059. return ldanmu
  2060. }
  2061.  
  2062. async function moreHistory(cid) {
  2063. let date = new Date();
  2064. date.setTime(date.getTime() - 86400000)
  2065. console.log('GetDanmuFor CID' + cid)
  2066. let aldanmu = [], ldanmu = []
  2067. let firstdate = 0;
  2068. let ndanmu, ondanmu
  2069. let url = 'https://comment.bilibili.com/' + cid + '.xml'
  2070. let sdanmu = await xhrGet(url)
  2071. ondanmu = ndanmu = Number(/<maxlimit>(.*?)</.exec(sdanmu)[1])
  2072. ldanmu = xml2danmu(sdanmu)
  2073.  
  2074. while (true) {
  2075. if (firstdate === 0 || ldanmu.length >= Math.min(ondanmu, 5000) * 0.9) {
  2076. let url = "https://api.bilibili.com/x/v2/dm/web/history/seg.so?type=1&date="
  2077. + getdate(date) + "&oid=" + cid.toString();
  2078. console.log('ndanmu:', aldanmu.length, getdate(date), url);
  2079. ldanmu = await loadProtoDanmu(url)
  2080. }
  2081. aldanmu = mergeDanmu(aldanmu, ldanmu)
  2082. if (ldanmu.length < Math.min(ondanmu, 5000) * 0.9) {
  2083. return [aldanmu, ondanmu]
  2084. }
  2085. if (ldanmu.length >= Math.min(ondanmu, 5000) * 0.9) {
  2086. let tfirstdate = getMinDate(ldanmu)
  2087. if (firstdate !== 0 && firstdate - tfirstdate < 86400)
  2088. tfirstdate = firstdate - 86400;
  2089. firstdate = tfirstdate;
  2090. date.setTime(firstdate * 1000);
  2091. }
  2092. }
  2093. }
  2094.  
  2095. function getdate(date) {
  2096. let month = Number(date.getMonth()) + 1;
  2097. if (month < 10) {
  2098. month = '0' + month
  2099. }
  2100. let sdate
  2101. if (Number(date.getDate()) < 10) {
  2102. sdate = '0' + date.getDate()
  2103. } else {
  2104. sdate = date.getDate()
  2105. }
  2106. return [date.getFullYear(), month, sdate].join('-')
  2107. }
  2108.  
  2109.  
  2110. function getMinDate(ldanmu) {
  2111. let minDate = ldanmu[0].ctime
  2112. for (let danmu of ldanmu) {
  2113. if (minDate > danmu.ctime) {
  2114. minDate = danmu.ctime
  2115. }
  2116. }
  2117. return minDate
  2118. }
  2119.  
  2120. function mergeDanmu(oldanmu, nldanmu) {
  2121. if (oldanmu.idPool === undefined) {
  2122.  
  2123. let idPool = new Set()
  2124. for (let danmu of oldanmu) {
  2125. try {
  2126. idPool.add(danmu.progress * danmu.content.length * parseInt(danmu.midHash, 16))
  2127.  
  2128. } catch (e) {
  2129. console.log(danmu)
  2130. console.log(e)
  2131. throw e
  2132. }
  2133. }
  2134. oldanmu.idPool = idPool
  2135. }
  2136. try {
  2137. for (let danmu of nldanmu) {
  2138. let ida = (danmu.progress ? danmu.progress : 1) * danmu.content.length * parseInt(danmu.midHash, 16)
  2139. if (!oldanmu.idPool.has(ida)) {
  2140. oldanmu.push(danmu)
  2141. oldanmu.idPool.add(ida)
  2142. }
  2143. }
  2144. } catch (e) {
  2145. console.log()
  2146. }
  2147.  
  2148. return oldanmu
  2149. }
  2150.  
  2151. function poolSize2Duration(poolSize) {
  2152. let lPoolSize = [
  2153. [0, 100],
  2154. [30, 300],
  2155. [60, 500],
  2156. [180, 1000],
  2157. [600, 1500],
  2158. [900, 3000],
  2159. [1500, 4000],
  2160. [2400, 6000],
  2161. [3600, 8000],
  2162. ]
  2163.  
  2164. for (let i = 0; i < lPoolSize.length; i += 1) {
  2165. if (poolSize === lPoolSize[i][1]) {
  2166. return lPoolSize[i][0]
  2167. }
  2168. }
  2169. }
  2170.  
  2171. function validateTitle(title) {
  2172. return title.replace(/[\/\\\:\*\?\"\<\>\|]/, '_')
  2173. }
  2174.  
  2175. async function allProtobufDanmu(cid, duration) {
  2176. let segIndex = 0, aldanmu = []
  2177. while (true) {
  2178. segIndex += 1
  2179.  
  2180. let tldanmu = await loadProtoDanmu('https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid='
  2181. + cid + '&segment_index=' + segIndex)
  2182. mergeDanmu(aldanmu, tldanmu)
  2183. if ((!duration || segIndex * 360 > duration) && (!tldanmu || tldanmu.length === 0)) {
  2184. break
  2185. }
  2186. }
  2187. return aldanmu
  2188. }
  2189.  
  2190. async function allProtobufDanmuXml(cid, title, ndanmu) {
  2191. let ldanmu = savedanmuStandalone(danmuObject2XML(allProtobufDanmu(cid, poolSize2Duration(ndanmu))))
  2192. downloadFile(validateTitle(title) + '.xml', ldanmu)
  2193. }
  2194.  
  2195. return [
  2196. async function downloadDanmaku(cid, title, returnStr = false) {
  2197.  
  2198.  
  2199. let [ldanmu, ndanmu] = await moreHistory(cid)
  2200. if (ldanmu.length / ndanmu > 2) {
  2201. mergeDanmu(ldanmu, await allProtobufDanmu(cid, poolSize2Duration(ndanmu)))
  2202. }
  2203. ldanmu = savedanmuStandalone(danmuObject2XML(ldanmu), {cid: cid, ndanmu: ndanmu})
  2204. if (returnStr) return ldanmu
  2205. downloadFile(validateTitle(title) + '.xml', ldanmu)
  2206. },
  2207. allProtobufDanmuXml
  2208. ]
  2209. })();
  2210.  
  2211.  
  2212. let downloadDanmakuVideo = (() => {
  2213. function validateTitle(title) {
  2214. return title.replace(/[\/\\\:\*\?\"\<\>\|]/, '_')
  2215. }
  2216.  
  2217. function downloadFile(fileName, content, type = 'text/plain;charset=utf-8') {
  2218. let aLink = document.createElement('a');
  2219. let blob
  2220. if (typeof (content) == 'string')
  2221. blob = new Blob([content], {'type': type})
  2222. else blob = content
  2223. aLink.download = fileName;
  2224. let url = URL.createObjectURL(blob)
  2225. aLink.href = url
  2226. aLink.click()
  2227. URL.revokeObjectURL(url)
  2228. }
  2229.  
  2230. return async function (videoInfo) {
  2231.  
  2232. let zip = new JSZip();
  2233. let folder = zip.folder('av' + videoInfo['aid'] + ' ' + validateTitle(videoInfo['title']))
  2234. folder.file('videoInfo.json', JSON.stringify(videoInfo))
  2235. let i = 0
  2236. for (let part of videoInfo['list']) {
  2237. i += 1
  2238. let sdanmu = await downloadDanmaku(part.cid, '', true)
  2239. let progress = (i * 100 / videoInfo['list'].length).toFixed(2)
  2240. document.title = progress + ' %'
  2241. iframe.contentWindow.postMessage({
  2242. type: 'cidComplete',
  2243. cid: part.cid,
  2244. aid: videoInfo.aid,
  2245. progress: progress,
  2246. }, '*');
  2247. await new Promise((resolve) => setTimeout(resolve, 1));
  2248.  
  2249. folder.file('p' + part.page + ' ' + validateTitle(part.part) + '_' + part.cid + '.xml', sdanmu)
  2250. await new Promise((resolve) => setTimeout(resolve, 1000));
  2251. }
  2252. zip.generateAsync({
  2253. type: "blob", compression: "DEFLATE",
  2254. compressionOptions: {
  2255. level: 9
  2256. }
  2257. }).then(function (content) {
  2258. downloadFile('av' + videoInfo['aid'] + ' ' + validateTitle(videoInfo['title']) + ".zip", content);
  2259. });
  2260. }
  2261. })()
  2262.  
  2263. let downloadedCid = []
  2264. let downloadedAid = []
  2265. let downloadingVideo = []
  2266. document.title = 'B+脚本后台'
  2267.  
  2268. const iframe = document.body.appendChild(document.createElement('iframe'));
  2269. iframe.style.display = 'none';
  2270. iframe.src = 'https://www.biliplus.com';
  2271. window.addEventListener('message', async (e) => {
  2272. if (e.origin === 'https://www.biliplus.com') {
  2273. console.log(`Top window ${window.origin} received message from iframe:`, e.data);
  2274. if (e.data.type === 'biliplusDownloadDanmaku') {
  2275. if (e.data.history !== false) {
  2276. if (downloadedCid.indexOf(e.data.cid) !== -1) {
  2277. return
  2278. }
  2279. downloadedCid.push(e.data.cid)
  2280. await downloadDanmaku(e.data.cid, e.data.title)
  2281. } else {
  2282. await allProtobufDanmu(e.data.cid, e.data.title, e.data.ndanmu)
  2283. }
  2284.  
  2285. // iframe.contentWindow.postMessage({type: 'cidComplete', cid: e.data.cid}, '*');
  2286. }
  2287. if (e.data.type === 'biliplusDownloadDanmakuVideo') {
  2288. if (downloadedAid.indexOf(e.data.videoInfo.aid) !== -1) {
  2289. iframe.contentWindow.postMessage({type: 'aidDownloaded', aid: e.data.videoInfo.aid}, '*');
  2290. return
  2291. }
  2292. downloadedAid.push(e.data.videoInfo.aid)
  2293. if (downloadingVideo.length === 0) {
  2294. downloadingVideo.push(e.data.videoInfo)
  2295. while (downloadingVideo.length !== 0) {
  2296. let videoInfo = downloadingVideo[0]
  2297. console.log('start', videoInfo.aid)
  2298. iframe.contentWindow.postMessage({type: 'aidStart', aid: videoInfo.aid}, '*');
  2299. await new Promise((resolve) => setTimeout(resolve, 1));
  2300. await downloadDanmakuVideo(videoInfo)
  2301. document.title = 'B+脚本后台'
  2302. iframe.contentWindow.postMessage({type: 'aidComplete', aid: videoInfo.aid}, '*');
  2303. await sleep(1000)
  2304. downloadingVideo = downloadingVideo.slice(1)
  2305. }
  2306. } else {
  2307. console.log('wait', e.data.videoInfo.aid)
  2308. downloadingVideo.push(e.data.videoInfo)
  2309. }
  2310.  
  2311. }
  2312. if (e.data.type === 'biliplusDurationRecover') {
  2313. let data = JSON.parse(await xhrGet('https://api.bilibili.com/x/web-interface/history/cursor?max=0&view_at=0&business='))
  2314. let video = data['data']['list'][0]
  2315. let content
  2316. if (document.querySelector("p[class='nickname']").textContent !== e.data.user) {
  2317. content = '请在B站和B+登录同一个账号'
  2318. } else if (video.history.cid !== parseInt(e.data.cid) || video.history.oid !== parseInt(e.data.aid)) {
  2319. content = 'cid不存在'
  2320. } else {
  2321. content = video.duration + '秒'
  2322. }
  2323. return iframe.contentWindow.postMessage({
  2324. type: 'recoverComplete',
  2325. cid: e.data.cid,
  2326. content: content
  2327. }, '*');
  2328.  
  2329. }
  2330. }
  2331. });
  2332. }
  2333.  
  2334.  
  2335. })();