Biliplus Evolved

简单的B+增强脚本

目前为 2023-10-16 提交的版本,查看 最新版本

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