Biliplus Evolved

简单的B+增强脚本

目前为 2023-02-14 提交的版本,查看 最新版本

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