Biliplus Evolved

简单的B+增强脚本

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

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