Greasy Fork 还支持 简体中文。

Biliplus Evolved

简单的B+增强脚本

目前為 2024-02-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Biliplus Evolved
  3. // @version 0.10.10
  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. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @connect api.bilibili.com
  15. // @connect comment.bilibili.com
  16. // @connect www.bilibili.com
  17. // @connect delflare505.win
  18. // @icon https://www.biliplus.com/favicon.ico
  19. // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.9.1/jszip.min.js
  20. // @namespace https://greasyfork.org/users/927887
  21. // ==/UserScript==
  22.  
  23.  
  24. (function () {
  25.  
  26. 'use strict';
  27. let toastText = (function () {
  28. let html = `
  29. <style>
  30. .df-bubble-container {
  31. position: fixed;
  32. bottom: 20px;
  33. right: 20px;
  34. z-index: 1000;
  35. display: block !important;
  36. }
  37.  
  38. .df-bubble {
  39. background-color: #333;
  40. color: white;
  41. padding: 10px 20px;
  42. border-radius: 5px;
  43. margin-bottom: 10px;
  44. opacity: 0;
  45. transition: opacity 0.5s ease-in-out;
  46. max-width: 300px;
  47. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.2);
  48. display: block !important;
  49. }
  50.  
  51. .df-show-bubble {
  52. opacity: 1;
  53. }
  54. </style>
  55. <div class="df-bubble-container" id="bubbleContainer"></div>`
  56. document.body.insertAdjacentHTML("beforeend", html)
  57. let bubbleContainer = document.querySelector('.df-bubble-container')
  58.  
  59. function createToast(text) {
  60. console.log('toast', text)
  61. const bubble = document.createElement('div');
  62. bubble.classList.add('df-bubble');
  63. bubble.textContent = text;
  64.  
  65. bubbleContainer.appendChild(bubble);
  66. setTimeout(() => {
  67. bubble.classList.add('df-show-bubble');
  68. setTimeout(() => {
  69. bubble.classList.remove('df-show-bubble');
  70. setTimeout(() => {
  71. bubbleContainer.removeChild(bubble);
  72. }, 500); // Remove the bubble after fade out
  73. }, 3000); // Show bubble for 3 seconds
  74. }, 100); // Delay before showing the bubble
  75. }
  76.  
  77. return createToast
  78. })();
  79.  
  80. async function sleep(time) {
  81. await new Promise((resolve) => setTimeout(resolve, time));
  82. }
  83.  
  84.  
  85. async function xhrGet(url) {
  86. function isCors(url) {
  87. if (url[0] === '/') return false
  88. // Extract the domain from the URL
  89. const urlDomain = new URL(url).hostname;
  90.  
  91. // Extract the domain from the current page's URL
  92. const currentDomain = window.location.hostname;
  93.  
  94. // Check if the domains are different (CORS request)
  95. return urlDomain !== currentDomain;
  96. }
  97.  
  98. console.log('Get', url);
  99. if (isCors(url)) {
  100. // Use GM_xmlhttpRequest for cross-origin requests
  101. return new Promise((resolve) => {
  102. GM_xmlhttpRequest({
  103. method: 'GET', url: url, withCredentials: true, onload: (response) => {
  104. if (response.status === 200) {
  105. resolve(response.responseText);
  106. } else {
  107. resolve(null);
  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 = content
  140. if (typeof (content) == 'string') blob = new Blob([content], {'type': type})
  141. aLink.download = fileName;
  142. let url = URL.createObjectURL(blob)
  143. aLink.href = url
  144. aLink.click()
  145. URL.revokeObjectURL(url)
  146. }
  147.  
  148. function bv2av(str) {
  149. const table = [...'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'];
  150. const s = [11, 10, 3, 8, 4, 6];
  151. const xor = 177451812;
  152. const add = 8728348608;
  153. let result = 0;
  154. let i = 0;
  155. while (i < 6) {
  156. result += table.indexOf(str[s[i]]) * 58 ** i;
  157. i += 1;
  158. }
  159. return result - add ^ xor
  160. }
  161.  
  162. async function aidQuery() {
  163. function transform(src) {
  164. let dst = {}
  165. dst.id = src.id
  166. dst.ver = 1
  167. dst.aid = src.id
  168. dst.lastupdatets = Math.floor(new Date().getTime() / 1000)
  169. dst.lastupdate = new Date().toLocaleString();
  170. if (src.title === "已失效视频") {
  171. let pic = document.querySelector('.detail_cover')
  172. if (pic) {
  173. dst.title = document.title.slice(0, document.title.indexOf(" - "))
  174. dst.pic = pic.src
  175. }
  176. } else {
  177. dst.pic = src.cover
  178. dst.title = src.title
  179. }
  180. dst.description = src.intro
  181.  
  182. dst.tid = src.tid
  183. dst.typename = "tid_" + src.tid
  184. dst.created = src.pubtime
  185. dst.created_at = new Date(src.pubtime * 1000).toLocaleString()
  186. dst.author = src.upper.name
  187. dst.mid = src.upper.mid
  188. dst.play = src.cnt_info.play.toString()
  189. dst.coins = src.cnt_info.coin
  190. dst.review = src.cnt_info.reply
  191. dst.video_review = src.cnt_info.danmaku
  192. dst.favorites = src.cnt_info.collect
  193. dst.tag = "tag_undefined"
  194. let list = []
  195. for (let page of src.pages) {
  196. list.push({
  197. "page": page.page,
  198. "type": page.from,
  199. "cid": page.id,
  200. "vid": undefined,
  201. "part": page.title + "_时长" + page.duration + "秒",
  202. "duration": page.duration
  203. })
  204. }
  205. dst.list = list
  206. return dst
  207. }
  208.  
  209. let aid
  210. let href = new URL(window.location.href)
  211. if (href.searchParams.has("get_info")) {
  212. aid = unsafeWindow.av
  213. } else {
  214. aid = window.prompt("请输入要查询的aid或bvid", unsafeWindow.av)
  215. if (!/^\d+$/.exec(aid)) {
  216. if (/^av\d+$/.exec(aid) || /^AV\d+$/.exec(aid)) {
  217. aid = aid.substring(2)
  218. } else if (/^BV/.exec(aid)) {
  219. aid = bv2av(aid)
  220. } else {
  221. alert("请输入正确的视频号,bv号请以BV开头")
  222. return
  223. }
  224. }
  225. if (href.toString().indexOf('all/video/') === -1) {
  226. href = new URL(href.origin + `/all/video/av${aid}/`)
  227. }
  228. href.searchParams.set("get_info", '1')
  229. window.location.href = href.toString()
  230. }
  231. let url = `https://delflare505.win/getVideoInfo?aid=` + aid
  232.  
  233. let response = await xhrGet(url)
  234. let body = JSON.parse(await response)
  235. console.log(body)
  236. let videoInfo = transform(body.data)
  237. unsafeWindow.videoInfo = videoInfo
  238. if (unsafeWindow.cloudmoe) {
  239. let cacheInfo = JSON.parse(JSON.stringify(videoInfo))
  240. cacheInfo.isDetailed = true
  241. cacheInfo.keywords = ""
  242. cacheInfo = {
  243. code: 0, data: {
  244. id: cacheInfo.id, info: cacheInfo, parts: cacheInfo.list,
  245. },
  246. }
  247. unsafeWindow.cloudmoe(cacheInfo)
  248. } else {
  249. unsafeWindow.view(videoInfo)
  250. }
  251. }
  252.  
  253. sleep(200).then(() => {
  254. if (new URL(window.location.href).searchParams.has("get_info")) {
  255. aidQuery(unsafeWindow.av)
  256. }
  257. })
  258.  
  259.  
  260. class CustomEventEmitter {
  261. constructor() {
  262. this.eventListeners = {};
  263. }
  264.  
  265. addEventListener(event, callback) {
  266. if (!this.eventListeners[event]) {
  267. this.eventListeners[event] = [];
  268. }
  269. this.eventListeners[event].push(callback);
  270. }
  271.  
  272. removeEventListener(event, callback) {
  273. if (this.eventListeners[event]) {
  274. const index = this.eventListeners[event].indexOf(callback);
  275. if (index !== -1) {
  276. this.eventListeners[event].splice(index, 1);
  277. }
  278. }
  279. }
  280.  
  281. postMessage(data) {
  282. const event = 'message'
  283. console.log(data)
  284. if (this.eventListeners[event]) {
  285. this.eventListeners[event].forEach(callback => {
  286. callback({data: data});
  287. });
  288. }
  289. }
  290. }
  291.  
  292. class ObjectRegistry {
  293. constructor() {
  294. this.registeredObjects = new Set();
  295. }
  296.  
  297. register(obj) {
  298. if (this.registeredObjects.has(obj)) {
  299. throw new Error('Object is already registered.');
  300. }
  301. this.registeredObjects.add(obj);
  302. }
  303. }
  304.  
  305. const broadcastChannel = new CustomEventEmitter()
  306.  
  307. function validateTitle(title) {
  308. if (!title) return ''
  309. return title.replace(/[\/\\\:\*\?\"\<\>\|]/g, '_')
  310. }
  311.  
  312. function getPartTitle(partInfo) {
  313. let partTitle = /^\d$/.test(partInfo.page) ? 'p' : ''
  314. partTitle += partInfo.page + ' ' + validateTitle(partInfo.part) + '_' + partInfo.cid
  315. return partTitle
  316. }
  317.  
  318. function panel() {
  319. function getLocalSetting(key) {
  320. let value = GM_getValue(key)
  321. console.log('get', key, value)
  322. if (value) {
  323.  
  324. return value
  325. } else {
  326. return {}
  327. }
  328. }
  329.  
  330. function setDefaultValue(currentSetting, settingPanelOptions) {
  331. for (let option of settingPanelOptions) {
  332. if (option.id) {
  333. if (!currentSetting[option.id]) {
  334. currentSetting[option.id] = option.default
  335. }
  336. } else if (option.children) {
  337. for (let child of option.children) {
  338. if (child.id) {
  339. if (!currentSetting[child.id]) {
  340. currentSetting[child.id] = child.default
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347.  
  348. function saveLocalSetting(key, value) {
  349. console.log('save', key, value)
  350. GM_setValue(key, value)
  351. }
  352.  
  353. let settingPanelOptions = [{type: 'section', 'label': '抓取时段:'}, {
  354. type: 'row', children: [{
  355. 'type': 'numberInput',
  356. 'id': 'capturePeriodStart',
  357. label: "从视频发布起第",
  358. default: 0,
  359. suffixLabel: '天开始, ',
  360. splitter: ' '
  361. }, {
  362. 'type': 'numberInput',
  363. 'id': 'capturePeriodEnd',
  364. label: "至第",
  365. default: -1,
  366. suffixLabel: '天结束',
  367. splitter: ' '
  368. },]
  369. }, {type: 'sectionEnd'}, {
  370. type: 'row', children: [{type: 'checkbox', id: 'splitFileByTime', label: '按时间段分割弹幕文件'}]
  371. },]
  372.  
  373. let currentSetting = getLocalSetting("danmakuSetting")
  374. setDefaultValue(currentSetting, settingPanelOptions)
  375. let showSettingPanel = (function (settingPanelOptions, changeHandle) {
  376. let panelStyles = `
  377. <style>
  378. .section {
  379. font-size: 16px;
  380. margin-bottom: 10px;
  381. }
  382. .sectionEnd {
  383. border-top: 1px solid #ccc;
  384. margin-top: 10px;
  385. }
  386.  
  387. #panel {
  388. position: fixed;
  389. top: 50%;
  390. left: 50%;
  391. transform: translate(-50%, -50%);
  392. background-color: #333;
  393. color: #fff;
  394. padding: 20px;
  395. border-radius: 5px;
  396. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
  397. z-index: 999999;
  398. }
  399. .slider-label{
  400. width: 12ch;
  401. }
  402.  
  403. .apply-button {
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. background-color: #555;
  408. color: white;
  409. border: none;
  410. padding: 8px 12px;
  411. cursor: pointer;
  412. border-radius: 4px;
  413. text-decoration: none;
  414. margin-top: 10px;
  415. margin-left: auto;
  416. }
  417.  
  418. .row {
  419. display: flex;
  420. align-items: center;
  421. margin-bottom: 10px;
  422. }
  423.  
  424. .slider {
  425. flex: 1;
  426. }
  427.  
  428. .slider-value {
  429. margin-left: 10px;
  430. font-size: 14px;
  431. color: #bbb;
  432. width: 4ch;
  433. }
  434.  
  435. .selector {
  436. flex: 1;
  437. margin-right: 10px;
  438. padding: 5px;
  439. border: 1px solid #555;
  440. border-radius: 3px;
  441. background-color: #444;
  442. color: #fff;
  443. }
  444.  
  445. .number-input {
  446. width: 6ch;
  447. padding: 5px;
  448. border: 1px solid #555;
  449. border-radius: 3px;
  450. background-color: #444;
  451. color: #fff;
  452. margin-right: 10px;
  453. margin-left: 5px;
  454. }
  455.  
  456. .text-selector {
  457. width: 10ch;
  458. padding: 5px;
  459. border: 1px solid #555;
  460. border-radius: 3px;
  461. background-color: #444;
  462. color: #fff;
  463. margin-left: 5px;
  464. }
  465.  
  466. .equal-row {
  467. display: flex;
  468. justify-content: space-between;
  469. align-items: center;
  470. }
  471.  
  472. .checkbox-group {
  473. flex: 1;
  474. display: flex;
  475. justify-content: center;
  476. }
  477. </style>
  478. `
  479.  
  480. // Create the setting panel HTML string based on the provided options
  481. function createPanelHTML(options) {
  482. let html = '<div id="panel" style="display: none;">'
  483. options.forEach(option => {
  484. if (option.type === 'section') {
  485. html += `<div class="section">${option.label}</div>`;
  486. } else if (option.type === 'sectionEnd') {
  487. html += `<div class="sectionEnd"></div>`;
  488. } else if (option.type === 'slider') {
  489. html += `<div class="row">
  490. <label class="slider-label" for="${option.id}">${option.label}:</label>
  491. <input type="range" class="slider" id="${option.id}" min="${option.range[0]}" max="${option.range[1]}" step="0.01" value="${currentSetting[option.id] || option.default}">
  492. <span class="slider-value" id="${option.id}Value">${currentSetting[option.id] || option.default}</span>
  493. </div>`;
  494. } else if (option.type === 'equal-row' || option.type === 'row') {
  495. html += `<div class="${option.type}">`;
  496. option.children.forEach(child => {
  497. // Handle checkboxes
  498. if (child.type === 'checkbox') {
  499. const checked = currentSetting[child.id] !== undefined ? currentSetting[child.id] : child.default;
  500. html += `<div class="checkbox-group">
  501. <label for="${child.id}">${child.label}:</label>
  502. <input type="checkbox" id="${child.id}" ${checked ? 'checked' : ''}>
  503. </div>`;
  504. }
  505. // Handle number input
  506. else if (child.type === 'numberInput') {
  507. html += `<label for="${child.id}">${child.label}${child.splitter || ':'}</label>
  508. <input type="number" class="number-input" id="${child.id}" value="${currentSetting[child.id] || child.default}">
  509. `;
  510. if (child.suffixLabel) {
  511. html += `<span>${child.suffixLabel}</span>`
  512. }
  513. }
  514. // Handle text selector
  515. else if (child.type === 'textSelector') {
  516. let currentValue = currentSetting[child.id] || child.default
  517. html += `<label for="${child.id}">${child.label}:</label>
  518. <select class="selector text-selector" id="${child.id}">`;
  519. child.optionText.forEach((text, index) => {
  520. const value = child.optionValue[index];
  521. const selected = currentValue === value ? 'selected' : '';
  522. html += `<option value="${value}" ${selected}>${text}</option>`;
  523. });
  524. html += `</select>`;
  525. }
  526. });
  527. html += `</div>`;
  528. }
  529. });
  530. html += '<button class="apply-button" id="applyButton">应用</button></div>';
  531. return html;
  532. }
  533.  
  534. function createSettingPanel(settingPanelOptions, changeHandle) {
  535.  
  536. document.body.insertAdjacentHTML('beforeend', panelStyles);
  537. const panelHTML = createPanelHTML(settingPanelOptions);
  538. document.body.insertAdjacentHTML('beforeend', panelHTML);
  539.  
  540. const panel = document.getElementById('panel');
  541.  
  542. panel.querySelector('#applyButton').addEventListener('click', () => {
  543. panel.style.display = 'none';
  544. saveLocalSetting('danmakuSetting', currentSetting)
  545. });
  546.  
  547. const sliders = panel.querySelectorAll('.slider');
  548. const sliderValues = panel.querySelectorAll('.slider-value');
  549.  
  550. sliders.forEach((slider, index) => {
  551. slider.addEventListener('input', () => {
  552. sliderValues[index].textContent = slider.value;
  553. changeHandle[slider.id](parseFloat(slider.value), slider.id);
  554. });
  555. });
  556.  
  557. // Handle checkbox changes
  558. const checkboxes = panel.querySelectorAll('input[type="checkbox"]');
  559. checkboxes.forEach(checkbox => {
  560. checkbox.addEventListener('change', () => {
  561. changeHandle[checkbox.id](Number(checkbox.checked), checkbox.id);
  562. });
  563. });
  564.  
  565. // Handle number input changes
  566. const numberInputs = panel.querySelectorAll('.number-input');
  567. numberInputs.forEach(input => {
  568. input.addEventListener('input', () => {
  569. const value = parseFloat(input.value);
  570. if (!isNaN(value)) {
  571. changeHandle[input.id](value, input.id);
  572. }
  573. });
  574. });
  575.  
  576. // Handle text selector changes
  577. const textSelectors = panel.querySelectorAll('.text-selector');
  578. textSelectors.forEach(selector => {
  579. selector.addEventListener('change', () => {
  580. changeHandle[selector.id](selector.value, selector.id);
  581. });
  582. });
  583.  
  584. return panel
  585. }
  586.  
  587.  
  588. let panel = createSettingPanel(settingPanelOptions, changeHandle)
  589. panel.style.display = 'none'
  590. return function () {
  591. if (panel.style.display !== 'block') {
  592. panel.style.display = 'block'
  593. } else {
  594. panel.style.display = 'none'
  595. }
  596. }
  597. })(settingPanelOptions, {
  598. capturePeriodStart(value, id) {
  599. currentSetting[id] = value;
  600. }, capturePeriodEnd(value, id) {
  601. currentSetting[id] = value;
  602. }, splitFileByTime(value, id) {
  603. currentSetting[id] = value;
  604. },
  605. });
  606.  
  607. async function findCidInfo() {
  608. let cid = window.prompt("请输入要查询的cid")
  609. if (!/^\d+$/.exec(cid)) {
  610. alert("请输入一个数字")
  611. return
  612. }
  613. let response = await fetch(`/api/cidinfo?cid=${cid}`)
  614. let body = await response.json()
  615. window.alert((JSON.stringify(body.data)))
  616.  
  617. }
  618.  
  619.  
  620. (function createToolbar(config) {
  621. let html = `
  622. <style>
  623.  
  624. #triggerArea {
  625. position: fixed;
  626. top: 45%;
  627. left: 0;
  628. width: max(5%,50px);
  629. height: 30%;
  630. cursor: pointer;
  631. z-index: 999998;
  632. }
  633.  
  634. #toolbar {
  635. position: fixed;
  636. top: 50%;
  637. left: -250px;
  638. transform: translateY(-50%);
  639. background-color: #333;
  640. color: #fff;
  641. padding: 10px;
  642. border-top-right-radius: 5px;
  643. border-bottom-right-radius: 5px;
  644. cursor: grab;
  645. transition: left 0.3s;
  646. z-index: 999999;
  647. }
  648.  
  649. #toolbar:active {
  650. cursor: grabbing;
  651. }
  652.  
  653. #toolbar button {
  654. display: block;
  655. margin: 5px 0;
  656. padding: 8px;
  657. background-color: #555;
  658. border: none;
  659. color: #fff;
  660. cursor: pointer;
  661. border-radius: 3px;
  662. }
  663. </style>
  664. <div id="triggerArea"></div>
  665. <div id="toolbar"></div>
  666. `
  667. document.body.insertAdjacentHTML('beforeend', html)
  668. const triggerArea = document.getElementById('triggerArea');
  669. const toolbar = document.getElementById('toolbar');
  670. let isDragging = false;
  671. let isExpanded = false;
  672. let startY = 0;
  673. let initialTop = 0;
  674. let currentSetting = getLocalSetting('dfToolbar')
  675. if (currentSetting['offsetTopPercent']) {
  676. toolbar.setAttribute('offsetTop', currentSetting['offsetTopPercent'] * window.innerHeight)
  677. }
  678. console.log('createToolbar', config)
  679. for (let option of Object.keys(config.options)) {
  680. let button = document.createElement("button")
  681. button.innerText = option
  682. button.addEventListener('click', config.options[option])
  683. toolbar.appendChild(button)
  684. }
  685.  
  686.  
  687. function expandToolbar() {
  688. if (!isExpanded) {
  689. toolbar.style.left = '0';
  690. isExpanded = true;
  691. }
  692. }
  693.  
  694. function collapseToolbar() {
  695. if (isExpanded) {
  696. toolbar.style.left = '-250px';
  697. isExpanded = false;
  698. }
  699. }
  700.  
  701. triggerArea.addEventListener('mouseenter', () => {
  702. expandToolbar();
  703. });
  704.  
  705. triggerArea.addEventListener('mouseleave', () => {
  706. collapseToolbar();
  707. if (isDragging) {
  708. isDragging = false
  709. dragEndHandle()
  710. }
  711. });
  712.  
  713. toolbar.addEventListener('mouseenter', () => {
  714. expandToolbar();
  715. });
  716.  
  717. toolbar.addEventListener('mouseleave', () => {
  718. if (!isDragging) {
  719. collapseToolbar();
  720. }
  721. });
  722.  
  723. toolbar.addEventListener('mousedown', (e) => {
  724. if (e.target === toolbar) {
  725. console.log(e.type, e)
  726. isDragging = true;
  727. startY = e.clientY;
  728. initialTop = toolbar.offsetTop;
  729. }
  730. });
  731.  
  732.  
  733. let draggingHandle = (e) => {
  734. if (!isDragging) return;
  735. const deltaY = e.clientY - startY;
  736. toolbar.style.top = `${initialTop + deltaY}px`;
  737. }
  738.  
  739. let dragEndHandle = (e) => {
  740. if (isDragging) {
  741. isDragging = false;
  742. currentSetting.offsetTopPercent = toolbar.offsetTop / window.innerHeight
  743. saveLocalSetting('dfToolbar', currentSetting)
  744. }
  745. }
  746.  
  747. window.addEventListener('mousemove', draggingHandle);
  748. window.addEventListener('mouseup', dragEndHandle);
  749.  
  750. expandToolbar()
  751. setTimeout(collapseToolbar, 3000)
  752. })({
  753. options: {
  754. "下载选项": showSettingPanel, "CID 反查": findCidInfo, "AID 查询": aidQuery
  755. }
  756. });
  757. return currentSetting
  758. }
  759.  
  760. function client() {
  761. let registeredTimestamp = new Date().getTime()
  762.  
  763.  
  764. console.log('biliplus script running')
  765.  
  766. function getPageAid() {
  767. let aid
  768. if (/\/BV/.exec(window.location.href)) {
  769. aid = bv2av(/BV[a-zA-Z0-9]+/.exec(window.location.href)[0])
  770. } else {
  771. aid = /av(\d+)/.exec(window.location.href)[1]
  772. }
  773. return Number(aid)
  774. }
  775.  
  776. function xmlunEscape(content) {
  777. return content.replace(/, /g, ';')
  778. .replace(/&amp;/g, '&')
  779. .replace(/&lt;/g, '<')
  780. .replace(/&gt;/g, '>')
  781. .replace(/&apos;/g, "'")
  782. .replace(/&quot;/g, '"')
  783. }
  784.  
  785. let createElement = function (sHtml) {
  786. // 创建一个可复用的包装元素
  787. let recycled = document.createElement('div'), // 创建标签简易匹配
  788. reg = /^<([a-zA-Z]+)(?=\s|\/>|>)[\s\S]*>$/, // 某些元素HTML标签必须插入特定的父标签内,才能产生合法元素
  789. // 另规避:ie7-某些元素innerHTML只读
  790. // 创建这些需要包装的父标签hash
  791. hash = {
  792. 'colgroup': 'table',
  793. 'col': 'colgroup',
  794. 'thead': 'table',
  795. 'tfoot': 'table',
  796. 'tbody': 'table',
  797. 'tr': 'tbody',
  798. 'th': 'tr',
  799. 'td': 'tr',
  800. 'optgroup': 'select',
  801. 'option': 'optgroup',
  802. 'legend': 'fieldset'
  803. };
  804. // 闭包重载方法(预定义变量避免重复创建,调用执行更快,成员私有化)
  805. createElement = function (sHtml) {
  806. // 若不包含标签,调用内置方法创建并返回元素
  807. if (!reg.test(sHtml)) {
  808. return document.createElement(sHtml);
  809. }
  810. // hash中是否包含匹配的标签名
  811. let tagName = hash[RegExp.$1.toLowerCase()];
  812. // 若无,向包装元素innerHTML,创建/截取并返回元素
  813. if (!tagName) {
  814. recycled.innerHTML = sHtml;
  815. return recycled.removeChild(recycled.firstChild);
  816. }
  817. // 若匹配hash标签,迭代包装父标签,并保存迭代层次
  818. let deep = 0, element = recycled;
  819. do {
  820. sHtml = '<' + tagName + '>' + sHtml + '</' + tagName + '>';
  821. deep++;
  822. } while (tagName = hash[tagName]);
  823. element.innerHTML = sHtml;
  824. // 根据迭代层次截取被包装的子元素
  825. do {
  826. element = element.removeChild(element.firstChild);
  827. } while (--deep > -1);
  828. // 最终返回需要创建的元素
  829. return element;
  830. }
  831. // 执行方法并返回结果
  832. return createElement(sHtml);
  833. }
  834.  
  835. async function parseVideoInfo(aid) {
  836. let videoInfo
  837. if (unsafeWindow.videoInfo && window.location.href.includes('/video/')) {
  838. return unsafeWindow.videoInfo
  839. }
  840. if (aid === undefined) {
  841. aid = getPageAid()
  842. }
  843. try {
  844. let videoPage = await xhrGet('https://www.biliplus.com/video/av' + aid + '/')
  845. videoInfo = JSON.parse(xmlunEscape(/({"id":.*?})\);/.exec(videoPage)[1]))
  846. videoInfo['aid'] = videoInfo['id']
  847. } catch (e) {
  848. console.log(e)
  849. let videoPage = await xhrGet('https://www.biliplus.com/all/video/av' + aid + '/')
  850. let url = /(\/api\/view_all\?.*?)'/.exec(videoPage)[1]
  851. url = 'https://www.biliplus.com' + url
  852. let data = JSON.parse(xmlunEscape(await xhrGet(url)))['data']
  853. videoInfo = data['info']
  854. videoInfo['list'] = data['parts']
  855. }
  856. if (videoInfo.created) {
  857. videoInfo.videoPublishDate = videoInfo.created
  858. }
  859. console.log(videoInfo)
  860. if (window.location.href.includes('/video/')) {
  861. unsafeWindow.videoInfo = videoInfo
  862. }
  863. return videoInfo
  864. }
  865.  
  866. (function searchFix() {
  867. if (window.location.href.indexOf('api/do.php') === -1) return
  868.  
  869. function searchOption() {
  870. let searchField = document.querySelector("#searchField > fieldset")
  871. let searchDiv = document.querySelector("#searchField > fieldset > div:nth-child(1)")
  872. searchDiv.insertAdjacentHTML('afterend', `
  873. <style>
  874. .dropdown {
  875. background-color: #f2f2f2;
  876. padding: 4px;
  877. border-radius: 2px;
  878. }
  879.  
  880. .dropdown option {
  881. padding: 10px;
  882. font-size: 14px;
  883. color: #333;
  884. }
  885.  
  886. .dropdown option:hover {
  887. background-color: #e5e5e5;
  888. }
  889. </style>
  890. <select id="alive-section" class="dropdown">
  891. <option value="连载动画">连载动画</option>
  892. <option value="完结动画">完结动画</option>
  893. <option value="国产动画">国产动画</option>
  894. <option value="欧美电影">欧美电影</option>
  895. <option value="日本电影">日本电影</option>
  896. <option value="国产电影">国产电影</option>
  897. <option value="布袋戏">布袋戏</option>
  898. <option value="国产剧">国产剧</option>
  899. <option value="海外剧">海外剧</option>
  900. <option value="" selected="">视频分区</option>
  901. </select>
  902. <select id="dead-section" class="dropdown">
  903. <option value="连载剧集">连载剧集</option>
  904. <option value="完结剧集">完结剧集</option>
  905. <option value="国产">国产</option>
  906. <option value="日剧">日剧</option>
  907. <option value="美剧">美剧</option>
  908. <option value="其他">其他</option>
  909. <option value="特摄">特摄</option>
  910. <option value="剧场版">剧场版</option>
  911. <option value="" selected="">下架分区</option>
  912. </select>
  913. <select id="poster" class="dropdown">
  914. <option value="928123">哔哩哔哩番剧</option>
  915. <option value="11783021">哔哩哔哩番剧出差</option>
  916. <option value="15773384">哔哩哔哩电影</option>
  917. <option value="4856007">迷影社</option>
  918. <option value="" selected="">UP主</option>
  919. </select>
  920. `)
  921. let aliveSection = searchField.querySelector("select[id='alive-section']")
  922. let deadSection = searchField.querySelector("select[id='dead-section']")
  923. let poster = searchField.querySelector("select[id='poster']")
  924. let searchInput = document.querySelector("#searchField > fieldset > div:nth-child(1) > input[type=search]")
  925.  
  926. function setSection(section) {
  927. let content = searchInput.value
  928. if (section !== "") {
  929. section = ' @' + section
  930. }
  931. if (/ @\S+/.exec(content)) {
  932. content = content.replace(/ @\S+/, section)
  933. } else content += section
  934. searchInput.value = content
  935. }
  936.  
  937. function setPoster(uid) {
  938. if (uid !== "") {
  939. uid = ' @m=' + uid
  940. }
  941. let content = searchInput.value
  942. if (/ @m=\d+/.exec(content)) {
  943. content = content.replace(/ @m=\d+/, uid)
  944. } else content += uid
  945. searchInput.value = content
  946. }
  947.  
  948. aliveSection.addEventListener('change', (event) => {
  949. if (deadSection.value !== "") {
  950. deadSection.value = ""
  951. }
  952. setSection(event.target.value)
  953. })
  954. deadSection.addEventListener('change', (event) => {
  955. if (aliveSection.value !== "") {
  956. aliveSection.value = ""
  957. }
  958. setSection(event.target.value)
  959. })
  960. poster.addEventListener('change', (event) => {
  961. setPoster(event.target.value)
  962. })
  963. }
  964.  
  965. searchOption()
  966. unsafeWindow.openOrigin = unsafeWindow.open
  967. unsafeWindow.open = function (link) {
  968. console.log('window.open', link)
  969. if (link) {
  970. unsafeWindow.openOrigin(link)
  971. }
  972. }
  973. let getjson = unsafeWindow.parent.getjsonReal = unsafeWindow.parent.getjson
  974. let aidList = []
  975. let irrelevantArchive = []
  976. let allArchive = []
  977.  
  978. async function joinCallback(url, callback, n) {
  979. if (url[0] === '/') url = 'https:' + url
  980. let word = /word=(.*?)(&|$)/.exec(url)[1]
  981. let wordList = []
  982. for (let keyword of decodeURIComponent(word).replace(/([^ ])@/, '$1 @').split(' ')) {
  983. if (keyword[0] !== '@') {
  984. wordList.push(keyword)
  985. }
  986. }
  987. let pn = /p=(\d+)/.exec(url)
  988. pn = pn ? pn[1] : '1'
  989. if (pn === '1') {
  990. aidList = []
  991. irrelevantArchive = []
  992. allArchive = []
  993. }
  994.  
  995. let searchResult = JSON.parse(await xhrGet(url))
  996. let archive = []
  997. searchResult['data']['items']['archive'].forEach(function (item) {
  998. if (item.goto === 'av') {
  999. if (aidList.indexOf(item.param) === -1) {
  1000. aidList.push(item.param)
  1001. let isRelevant = false
  1002. for (let keyword of wordList) {
  1003. for (let key of ['title', 'desc']) {
  1004. if (item[key].indexOf(keyword) !== -1) {
  1005. isRelevant = true
  1006. }
  1007. }
  1008. }
  1009. if (isRelevant) {
  1010. archive.push(item)
  1011. } else {
  1012. irrelevantArchive.push(item)
  1013. }
  1014. allArchive.push(item)
  1015. }
  1016. } else {
  1017. archive.push(item)
  1018. }
  1019. })
  1020.  
  1021. try {
  1022. let aidSearchUrl = '/api/search?word=' + word + '&page=' + pn
  1023. let aidSearchResult = JSON.parse((await xhrGet(aidSearchUrl)))['result']
  1024. aidSearchResult.forEach(function (video) {
  1025. if (aidList.indexOf(video.aid) === -1) {
  1026. let item = {
  1027. author: video.author,
  1028. cover: video.pic,
  1029. created: new Date(video.created.replace(/-/g, '/')).getTime() / 1000,
  1030. review: video.review,
  1031. desc: video.description,
  1032. goto: "av",
  1033. param: video.aid,
  1034. play: video.play,
  1035. title: video.title,
  1036. }
  1037.  
  1038. let isRelevant = false
  1039. for (let keyword of wordList) {
  1040. for (let key of ['title', 'desc']) {
  1041. if (item[key].indexOf(keyword) !== -1) {
  1042. isRelevant = true
  1043. }
  1044. }
  1045. }
  1046. if (isRelevant) {
  1047. archive.push(item)
  1048. } else {
  1049. irrelevantArchive.push(item)
  1050. }
  1051. allArchive.push(item)
  1052. }
  1053. })
  1054. } catch (e) {
  1055. console.log(e)
  1056. }
  1057.  
  1058. if (archive.length === 0) {
  1059. archive = irrelevantArchive
  1060. irrelevantArchive = []
  1061. }
  1062. searchResult['data']['items']['archive'] = archive
  1063. callback(searchResult, n)
  1064. return
  1065. }
  1066.  
  1067.  
  1068. unsafeWindow.getjson = unsafeWindow.parent.getjson = function (url, callback, n) {
  1069. if (url.indexOf("search_api") !== -1 && url.indexOf("source=biliplus") !== -1) {
  1070. try {
  1071.  
  1072. return joinCallback(url, callback, n)
  1073. } catch (e) {
  1074. console.log(e)
  1075. return getjson(url, callback, n)
  1076. }
  1077. } else return getjson(url, callback, n)
  1078.  
  1079. };
  1080. unsafeWindow.doSearch()
  1081.  
  1082.  
  1083. broadcastChannel.addEventListener('message', function (event) {
  1084. console.log(event.data)
  1085. if (event.data.type === 'aidComplete') {
  1086. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  1087. if (elem) elem.textContent = '下载完成'
  1088. }
  1089. if (event.data.type === 'aidDownloaded') {
  1090. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  1091. if (elem) elem.textContent = '已下载'
  1092. }
  1093. if (event.data.type === 'aidStart') {
  1094. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  1095. if (elem) elem.textContent = '开始下载'
  1096. }
  1097. if (event.data.type === 'cidComplete') {
  1098. let elem = document.querySelector('[id="av' + event.data.aid + '"]')
  1099. if (elem) elem.textContent = event.data.progress + "%"
  1100. }
  1101. })
  1102.  
  1103. document.addEventListener("DOMNodeInserted", async (msg) => {
  1104. if (msg.target.nodeName === '#text') {
  1105. let aidElem = msg.target.parentElement.parentElement
  1106. .querySelector('div[class="video-card-desc"]')
  1107. if (!aidElem) {
  1108. return
  1109. }
  1110. console.log(aidElem)
  1111. let link = msg.target.parentElement.parentElement.parentElement.getAttribute("data-link")
  1112. if (link) {
  1113. console.log(link)
  1114. msg.target.parentElement.parentElement.parentElement.removeAttribute("data-link")
  1115. msg.target.parentElement.parentElement.parentElement.addEventListener('click', async function (event) {
  1116. console.log(event)
  1117. event.preventDefault()
  1118. if (event.target.className !== 'download') {
  1119. unsafeWindow.openOrigin(link)
  1120. }
  1121. })
  1122. }
  1123.  
  1124. let aid = parseInt(aidElem.textContent.slice(2))
  1125. if (!aidElem.querySelector('[class="download"]')) {
  1126. let downloadButton = createElement('<div class="download" style="display:inline-block;float:right;border-radius:5px;border:1px solid #AAA;' + 'background:#DDD;padding:8px 20px;cursor:pointer" id="av' + aid + '">下载弹幕</div>')
  1127. window.moved = true
  1128.  
  1129. downloadButton.addEventListener('click', async function (event) {
  1130. event.preventDefault()
  1131. console.log('download', aid)
  1132. if (downloadButton.textContent !== '下载弹幕') return
  1133. downloadButton.textContent = '等待下载'
  1134. let videoInfo = await parseVideoInfo(aid)
  1135. broadcastChannel.postMessage({
  1136. type: 'biliplusDownloadDanmakuVideo',
  1137. videoInfo: videoInfo,
  1138. timestamp: registeredTimestamp
  1139. })
  1140. })
  1141. aidElem.appendChild(downloadButton)
  1142. }
  1143. let timeago = msg.target.parentElement
  1144. for (let video of allArchive) {
  1145. if (video.param === aid && video.goto === 'av') {
  1146. let text = timeago.getAttribute('title') + ' 播放:' + video['play']
  1147. if (video['danmaku']) text += ' 弹幕:' + video['danmaku']
  1148. if (video['review']) text += ' 评论:' + video['review']
  1149. timeago.textContent = text
  1150. }
  1151. }
  1152. }
  1153. })
  1154.  
  1155. })();
  1156.  
  1157. (function historyFix() {
  1158.  
  1159. if (window.location.href.indexOf('/video/') === -1) return
  1160. const registry = new ObjectRegistry();
  1161. let aid = getPageAid()
  1162.  
  1163. unsafeWindow.downloadVideoDanmaku = async function (aid, videoInfo) {
  1164. registry.register('downloadVideoDanmaku')
  1165. if (!videoInfo) {
  1166. videoInfo = await parseVideoInfo(aid)
  1167. }
  1168. console.log('downloadVideoDanmaku', videoInfo)
  1169.  
  1170. broadcastChannel.postMessage({
  1171. type: 'biliplusDownloadDanmakuVideo', videoInfo: videoInfo, timestamp: registeredTimestamp
  1172. })
  1173. }
  1174.  
  1175. function getEpisodePublishDate(episode) {
  1176. let dateTimeString = episode.pub_real_time || episode.ctime
  1177. if (!dateTimeString) {
  1178. return null
  1179. }
  1180. const unixTimestamp = Date.parse(dateTimeString);
  1181. return Math.floor(unixTimestamp / 1000); // Convert milliseconds to seconds
  1182. }
  1183.  
  1184. async function popupPageSelector() {
  1185. async function builder(aid) {
  1186. if (!aid) {
  1187. aid = getPageAid()
  1188. }
  1189. let videoInfo = await parseVideoInfo(aid)
  1190. let partHtml = ''
  1191.  
  1192. for (let partInfo of videoInfo.list) {
  1193. let partTitle = getPartTitle(partInfo)
  1194. partHtml += `<tr draggable="true"><td>
  1195. <input type="checkbox" checked id="part_cid_${partInfo.cid}"></td><td>${partTitle}</td></tr>`
  1196. }
  1197. let html = `
  1198. <style>
  1199. .popup {
  1200. position: fixed;
  1201. z-index: 1;
  1202. left: 0;
  1203. top: 0;
  1204. width: 100%;
  1205. height: 100%;
  1206. overflow: auto;
  1207. background-color: rgb(0,0,0);
  1208. background-color: rgba(0,0,0,0.4);
  1209. }
  1210.  
  1211. #draggableTable {
  1212. display: block;
  1213. max-height: 80vh;
  1214. overflow-y: auto;
  1215. border-collapse: collapse;
  1216. width: 100%;
  1217. }
  1218.  
  1219. .popup-content {
  1220. background-color: #fefefe;
  1221.  
  1222. display: block;
  1223. max-height: 90vh;
  1224. overflow-y: auto;
  1225. margin: 5vh auto;
  1226. padding: 20px;
  1227. border: 1px solid #888;
  1228. width: min(80%, 400px);
  1229. }
  1230.  
  1231.  
  1232. .close-btn {
  1233. color: #aaa;
  1234. float: right;
  1235. font-size: 28px;
  1236. font-weight: bold;
  1237. }
  1238.  
  1239. .close-btn:hover,
  1240. .close-btn:focus {
  1241. color: black;
  1242. text-decoration: none;
  1243. cursor: pointer;
  1244. }
  1245.  
  1246.  
  1247. input[type="checkbox"] {
  1248. transform: scale(1.5);
  1249. margin-right: 10px;
  1250. cursor: pointer;
  1251. }
  1252.  
  1253. #draggableTable td {
  1254. padding: 10px;
  1255. }
  1256.  
  1257. </style>
  1258. <body>
  1259. <div id="popup" class="popup" style="display: none">
  1260. <div class="popup-content">
  1261. <span class="close-btn">&times;</span>
  1262. <div class="button-row mb-3">
  1263. <button type="button" class="btn btn-primary" id="button0">下载0项</button>
  1264. <button type="button" class="btn btn-primary" id="button1">反选</button>
  1265. <button type="button" class="btn btn-primary" id="button2" disabled>区间选择</button>
  1266. <button type="button" class="btn btn-primary" id="button3" disabled>拼接</button>
  1267. </div>
  1268.  
  1269. <table id="draggableTable" class="table">
  1270. <tbody>
  1271. ${partHtml}
  1272. </tbody>
  1273. </table>
  1274. </div>
  1275. </div>
  1276. </body>
  1277. </html>
  1278.  
  1279.  
  1280. `
  1281.  
  1282. document.body.insertAdjacentHTML("beforeend", html)
  1283. if (videoInfo.list[0].duration) {
  1284. document.getElementById("button3").removeAttribute("disabled")
  1285. } else {
  1286. document.getElementById("button3").title = "仅限AID查询功能"
  1287. }
  1288.  
  1289. function js() {
  1290. document.querySelector(".close-btn").onclick = function () {
  1291. document.getElementById("popup").style.display = "none";
  1292. }
  1293.  
  1294. let dragSrcEl = null;
  1295.  
  1296. function handleDragStart(e) {
  1297. dragSrcEl = this;
  1298. e.dataTransfer.effectAllowed = 'move';
  1299. e.dataTransfer.setData('text/html', this.innerHTML);
  1300. }
  1301.  
  1302. function handleDragOver(e) {
  1303. if (e.preventDefault) {
  1304. e.preventDefault(); // Necessary. Allows us to drop.
  1305. }
  1306. e.dataTransfer.dropEffect = 'move';
  1307. return false;
  1308. }
  1309.  
  1310. function handleDrop(e) {
  1311. if (e.stopPropagation) {
  1312. e.stopPropagation(); // stops the browser from redirecting.
  1313. }
  1314. if (dragSrcEl !== this) {
  1315. dragSrcEl.innerHTML = this.innerHTML;
  1316. registerItem(dragSrcEl)
  1317. this.innerHTML = e.dataTransfer.getData('text/html');
  1318. registerItem(this)
  1319. }
  1320. return false;
  1321. }
  1322.  
  1323. function handleDragEnd(e) {
  1324. this.style.opacity = '1';
  1325. }
  1326.  
  1327.  
  1328. function updateSelectedCount() {
  1329. const selectedCount =
  1330. document.querySelectorAll(
  1331. '#draggableTable input[type="checkbox"]:checked').length;
  1332. document.getElementById('button0').innerText = `下载${selectedCount}项`
  1333. }
  1334.  
  1335. updateSelectedCount()
  1336.  
  1337. let lastClick = null
  1338. let currentClick = null
  1339.  
  1340.  
  1341. function registerItem(item) {
  1342. let checkbox = item.querySelector('input[type="checkbox"]');
  1343. item.addEventListener('dragstart', handleDragStart, false);
  1344. item.addEventListener('dragover', handleDragOver, false);
  1345. item.addEventListener('drop', handleDrop, false);
  1346. item.addEventListener('dragend', handleDragEnd, false);
  1347. item.addEventListener('click', function (e) {
  1348. if (e.target.type !== 'checkbox') {
  1349. checkbox.checked = !checkbox.checked
  1350. }
  1351. if (checkbox.checked) {
  1352. lastClick = currentClick
  1353. currentClick = item
  1354. if (lastClick !== null) {
  1355. document.getElementById('button2').removeAttribute('disabled')
  1356. }
  1357. }
  1358.  
  1359. updateSelectedCount()
  1360. })
  1361. }
  1362.  
  1363. document.querySelectorAll('#draggableTable tr').forEach(registerItem)
  1364.  
  1365. document.getElementById('button1').addEventListener('click', () => {
  1366. document.querySelectorAll('#draggableTable input[type="checkbox"]').forEach(checkbox => {
  1367. checkbox.checked = !checkbox.checked;
  1368. });
  1369. updateSelectedCount()
  1370. })
  1371. document.getElementById('button2').addEventListener('click', () => {
  1372. let parent = lastClick.parentElement
  1373. let sectionStart = false
  1374. for (let child of parent.childNodes) {
  1375. if (child === lastClick || child === currentClick) {
  1376. if (!sectionStart) {
  1377. sectionStart = true
  1378. } else {
  1379. break
  1380. }
  1381. }
  1382. if (sectionStart) {
  1383. child.querySelector("input").checked = true
  1384. }
  1385. }
  1386. updateSelectedCount()
  1387. })
  1388. document.getElementById('popup').addEventListener('click', function (event) {
  1389. if (!event.target.closest('.popup-content')) {
  1390. document.getElementById('popup').style.display = 'none';
  1391. }
  1392. });
  1393. }
  1394.  
  1395. let popup = document.getElementById('popup')
  1396.  
  1397. js()
  1398. return popup
  1399. }
  1400.  
  1401. let popup = document.getElementById('popup')
  1402. if (!popup) {
  1403. popup = await builder(aid)
  1404. }
  1405. if (popup.style.display === 'none') {
  1406. popup.style.display = 'block'
  1407. }
  1408. popup.querySelector('#button0').addEventListener('click', async (e) => {
  1409. let videoInfo = await parseVideoInfo(aid)
  1410. videoInfo = JSON.parse(JSON.stringify(videoInfo))
  1411. videoInfo.list = videoInfo.list.filter((partInfo) => {
  1412. return popup.querySelector(`#part_cid_${partInfo.cid}`).checked
  1413. })
  1414. await unsafeWindow.downloadVideoDanmaku(aid, videoInfo)
  1415. })
  1416.  
  1417. popup.querySelector('#button3').addEventListener('click', async (e) => {
  1418. let videoInfo = await parseVideoInfo(aid)
  1419. videoInfo = JSON.parse(JSON.stringify(videoInfo))
  1420. let cidMap = {}
  1421. videoInfo.list.forEach((partInfo) => {
  1422. cidMap[partInfo.cid] = partInfo
  1423. })
  1424. videoInfo.list = []
  1425. for (let checkBox of document.querySelectorAll(
  1426. '#draggableTable input[type="checkbox"]:checked')) {
  1427. videoInfo.list.push(cidMap[Number(checkBox.id.substring(9))])
  1428. }
  1429. broadcastChannel.postMessage({
  1430. type: 'concatDanmaku', videoInfo: videoInfo, timestamp: registeredTimestamp
  1431. })
  1432. })
  1433. }
  1434.  
  1435. unsafeWindow.popupPageSelector = popupPageSelector
  1436. document.addEventListener("DOMNodeInserted", async (msg) => {
  1437. if (msg.target.id) {
  1438. switch (msg.target.id) {
  1439. case 'danmaku_container': {
  1440. let historyButton = msg.target.querySelector('a[href^="/open/moepus.powered"]')
  1441. let cid = /#(\d+)/.exec(historyButton.getAttribute('href'))[1]
  1442. historyButton.onclick = async function () {
  1443.  
  1444. console.log('biliplusDownloadDanmaku', {
  1445. 'cid': cid,
  1446. 'title': document.querySelector('[class="videotitle"]').textContent + ' ' + document.querySelector('[id="cid_' + cid + '"]').innerText,
  1447. 'timestamp': registeredTimestamp
  1448. })
  1449. broadcastChannel.postMessage({
  1450. type: 'biliplusDownloadDanmaku',
  1451. cid: cid,
  1452. title: document.querySelector('[class="videotitle"]').textContent + ' ' + document.querySelector('[id="cid_' + cid + '"]').innerText,
  1453.  
  1454. timestamp: registeredTimestamp
  1455. })
  1456. }
  1457. historyButton.removeAttribute('href')
  1458.  
  1459. let commentButton = msg.target.querySelector('a[href^="https://comment.bilibili.com"]')
  1460. commentButton.removeAttribute('href')
  1461. commentButton.removeAttribute('onClick')
  1462. commentButton.addEventListener('click', async function () {
  1463. registry.register('commentButton' + cid)
  1464. let commentText = await xhrGet("/danmaku/" + cid + ".xml")
  1465. if (!commentText || commentText.indexOf("<state>2</state>") !== -1) {
  1466. broadcastChannel.postMessage({
  1467. type: 'biliplusDownloadDanmaku',
  1468. ndanmu: /<maxlimit>(\d+)<\/maxlimit>/.exec(commentText)?.[1],
  1469. cid: cid,
  1470. title: document.querySelector('[class="videotitle"]').textContent + ' ' + document.querySelector('[id="cid_' + cid + '"]').innerText,
  1471. history: false,
  1472. timestamp: registeredTimestamp
  1473. })
  1474. } else {
  1475. downloadFile(cid + '.xml', commentText)
  1476. }
  1477. })
  1478. break
  1479. }
  1480. case 'favorite': {
  1481. msg.target.parentElement.appendChild(createElement('<span id="downloadDanmaku"><a href="javascript:" onclick="window.downloadVideoDanmaku()">' + '<div class="solidbox pink" id="av' + getPageAid() + '">下载视频弹幕</div></a></span>'))
  1482. break
  1483. }
  1484. case 'part1': {
  1485. msg.target.parentElement.insertAdjacentHTML(
  1486. 'beforeend',
  1487. '<div class="solidbox pointer" onclick="window.downloadVideoDanmaku()">下载视频弹幕</div>' +
  1488. '<div class="solidbox pointer" onclick="window.popupPageSelector()">选择分P下载</div>')
  1489. break
  1490. }
  1491. case 'bgBlur': {
  1492. let bangumi = unsafeWindow.bangumi
  1493. if (!bangumi.isBangumi) break
  1494. let bangumiList = document.querySelector("#bangumi_list")
  1495. bangumiList.insertAdjacentHTML('beforeend', '' +
  1496. '<div class="solidbox pointer">下载剧集弹幕</div>')
  1497. bangumiList.lastChild.addEventListener('click', function (event) {
  1498. registry.register('downloadBangumiDanmaku')
  1499. console.log(event.target)
  1500. if (event.target.textContent !== '下载中') {
  1501. event.target.textContent = "下载中"
  1502. } else {
  1503. return
  1504. }
  1505. let apiCache = bangumi.apiCache
  1506. let response = apiCache[Object.keys(apiCache)[0]].result
  1507. let videoInfo = {
  1508. aid: 'ss' + response.season_id, title: response.title, list: [], detail: response,
  1509. }
  1510. for (let episode of response.episodes) {
  1511. if (episode.episode_type === -1 || episode.section_type === 1 || episode.section_type === 2) continue
  1512. let partInfo = {
  1513. page: episode.index ? episode.index : episode.title,
  1514. part: episode.index_title ? episode.index_title : episode.long_title,
  1515. cid: episode.cid,
  1516. duration: episode.duration,
  1517. videoPublishDate: getEpisodePublishDate(episode)
  1518. }
  1519. videoInfo.list.push(partInfo)
  1520. }
  1521. unsafeWindow.downloadVideoDanmaku(null, videoInfo)
  1522. })
  1523. }
  1524. }
  1525. }
  1526. })
  1527. })();
  1528.  
  1529. (async function mediaLinkFix() {
  1530. if (!window.location.href.includes('media/md')) return
  1531. let html = await xhrGet(window.location.href.replace("biliplus", "bilibili"))
  1532. console.log(html)
  1533. let seasonId = /"season_id":(\d+)/.exec(html)
  1534. if (seasonId) {
  1535. window.location.href = 'https://www.biliplus.com/bangumi/play/ss' + seasonId[1]
  1536. }
  1537. })();
  1538. }
  1539.  
  1540.  
  1541. function server() {
  1542.  
  1543. let videoPublishDate = null
  1544.  
  1545. let [downloadDanmaku, downloadDanmakuToZip, allProtobufDanmu, concatDanmaku] = (function () {
  1546. !function (z) {
  1547. var y = {
  1548. 1: [function (p, w) {
  1549. w.exports = function (h, m) {
  1550. for (var n = Array(arguments.length - 1), e = 0, d = 2, a = !0; d < arguments.length;) n[e++] = arguments[d++];
  1551. return new Promise(function (b, c) {
  1552. n[e] = function (k) {
  1553. if (a) if (a = !1, k) c(k); else {
  1554. for (var l = Array(arguments.length - 1), q = 0; q < l.length;) l[q++] = arguments[q];
  1555. b.apply(null, l)
  1556. }
  1557. };
  1558. try {
  1559. h.apply(m || null, n)
  1560. } catch (k) {
  1561. a && (a = !1, c(k))
  1562. }
  1563. })
  1564. }
  1565. }, {}], 2: [function (p, w, h) {
  1566. h.length = function (e) {
  1567. var d = e.length;
  1568. if (!d) return 0;
  1569. for (var a = 0; 1 < --d % 4 && "=" === e.charAt(d);) ++a;
  1570. return Math.ceil(3 * e.length) / 4 - a
  1571. };
  1572. var m = Array(64), n = Array(123);
  1573. for (p = 0; 64 > p;) n[m[p] = 26 > p ? p + 65 : 52 > p ? p + 71 : 62 > p ? p - 4 : p - 59 | 43] = p++;
  1574. h.encode = function (e, d, a) {
  1575. for (var b, c = null, k = [], l = 0, q = 0; d < a;) {
  1576. var f = e[d++];
  1577. switch (q) {
  1578. case 0:
  1579. k[l++] = m[f >> 2];
  1580. b = (3 & f) << 4;
  1581. q = 1;
  1582. break;
  1583. case 1:
  1584. k[l++] = m[b | f >> 4];
  1585. b = (15 & f) << 2;
  1586. q = 2;
  1587. break;
  1588. case 2:
  1589. k[l++] = m[b | f >> 6], k[l++] = m[63 & f], q = 0
  1590. }
  1591. 8191 < l && ((c || (c = [])).push(String.fromCharCode.apply(String, k)), l = 0)
  1592. }
  1593. 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))), c.join("")) : String.fromCharCode.apply(String, k.slice(0, l))
  1594. };
  1595. h.decode = function (e, d, a) {
  1596. for (var b, c = a, k = 0, l = 0; l < e.length;) {
  1597. var q = e.charCodeAt(l++);
  1598. if (61 === q && 1 < k) break;
  1599. if ((q = n[q]) === z) throw Error("invalid encoding");
  1600. switch (k) {
  1601. case 0:
  1602. b = q;
  1603. k = 1;
  1604. break;
  1605. case 1:
  1606. d[a++] = b << 2 | (48 & q) >> 4;
  1607. b = q;
  1608. k = 2;
  1609. break;
  1610. case 2:
  1611. d[a++] = (15 & b) << 4 | (60 & q) >> 2;
  1612. b = q;
  1613. k = 3;
  1614. break;
  1615. case 3:
  1616. d[a++] = (3 & b) << 6 | q, k = 0
  1617. }
  1618. }
  1619. if (1 === k) throw Error("invalid encoding");
  1620. return a - c
  1621. };
  1622. h.test = function (e) {
  1623. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)
  1624. }
  1625. }, {}], 3: [function (p, w) {
  1626. function h() {
  1627. this.t = {}
  1628. }
  1629.  
  1630. (w.exports = h).prototype.on = function (m, n, e) {
  1631. return (this.t[m] || (this.t[m] = [])).push({fn: n, ctx: e || this}), this
  1632. };
  1633. h.prototype.off = function (m, n) {
  1634. 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;
  1635. return this
  1636. };
  1637. h.prototype.emit = function (m) {
  1638. var n = this.t[m];
  1639. if (n) {
  1640. for (var e = [], d = 1; d < arguments.length;) e.push(arguments[d++]);
  1641. for (d = 0; d < n.length;) n[d].fn.apply(n[d++].ctx, e)
  1642. }
  1643. return this
  1644. }
  1645. }, {}], 4: [function (p, w) {
  1646. function h(a) {
  1647. return "undefined" != typeof Float32Array ? function () {
  1648. function b(v, g, t) {
  1649. q[0] = v;
  1650. g[t] = f[0];
  1651. g[t + 1] = f[1];
  1652. g[t + 2] = f[2];
  1653. g[t + 3] = f[3]
  1654. }
  1655.  
  1656. function c(v, g, t) {
  1657. q[0] = v;
  1658. g[t] = f[3];
  1659. g[t + 1] = f[2];
  1660. g[t + 2] = f[1];
  1661. g[t + 3] = f[0]
  1662. }
  1663.  
  1664. function k(v, g) {
  1665. return f[0] = v[g], f[1] = v[g + 1], f[2] = v[g + 2], f[3] = v[g + 3], q[0]
  1666. }
  1667.  
  1668. function l(v, g) {
  1669. return f[3] = v[g], f[2] = v[g + 1], f[1] = v[g + 2], f[0] = v[g + 3], q[0]
  1670. }
  1671.  
  1672. var q = new Float32Array([-0]), f = new Uint8Array(q.buffer), u = 128 === f[3];
  1673. a.writeFloatLE = u ? b : c;
  1674. a.writeFloatBE = u ? c : b;
  1675. a.readFloatLE = u ? k : l;
  1676. a.readFloatBE = u ? l : k
  1677. }() : function () {
  1678. function b(k, l, q, f) {
  1679. var u = 0 > l ? 1 : 0;
  1680. 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 {
  1681. var v = Math.floor(Math.log(l) / Math.LN2);
  1682. k((u << 31 | v + 127 << 23 | 8388607 & Math.round(l * Math.pow(2, -v) * 8388608)) >>> 0, q, f)
  1683. }
  1684. }
  1685.  
  1686. function c(k, l, q) {
  1687. q = k(l, q);
  1688. k = 2 * (q >> 31) + 1;
  1689. l = q >>> 23 & 255;
  1690. q &= 8388607;
  1691. return 255 === l ? q ? NaN : 1 / 0 * k : 0 === l ? 1.401298464324817E-45 * k * q : k * Math.pow(2, l - 150) * (q + 8388608)
  1692. }
  1693.  
  1694. a.writeFloatLE = b.bind(null, m);
  1695. a.writeFloatBE = b.bind(null, n);
  1696. a.readFloatLE = c.bind(null, e);
  1697. a.readFloatBE = c.bind(null, d)
  1698. }(), "undefined" != typeof Float64Array ? function () {
  1699. function b(v, g, t) {
  1700. q[0] = v;
  1701. g[t] = f[0];
  1702. g[t + 1] = f[1];
  1703. g[t + 2] = f[2];
  1704. g[t + 3] = f[3];
  1705. g[t + 4] = f[4];
  1706. g[t + 5] = f[5];
  1707. g[t + 6] = f[6];
  1708. g[t + 7] = f[7]
  1709. }
  1710.  
  1711. function c(v, g, t) {
  1712. q[0] = v;
  1713. g[t] = f[7];
  1714. g[t + 1] = f[6];
  1715. g[t + 2] = f[5];
  1716. g[t + 3] = f[4];
  1717. g[t + 4] = f[3];
  1718. g[t + 5] = f[2];
  1719. g[t + 6] = f[1];
  1720. g[t + 7] = f[0]
  1721. }
  1722.  
  1723. function k(v, g) {
  1724. return f[0] = v[g], f[1] = v[g + 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]
  1725. }
  1726.  
  1727. function l(v, g) {
  1728. 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]
  1729. }
  1730.  
  1731. var q = new Float64Array([-0]), f = new Uint8Array(q.buffer), u = 128 === f[7];
  1732. a.writeDoubleLE = u ? b : c;
  1733. a.writeDoubleBE = u ? c : b;
  1734. a.readDoubleLE = u ? k : l;
  1735. a.readDoubleBE = u ? l : k
  1736. }() : function () {
  1737. function b(k, l, q, f, u, v) {
  1738. var g = 0 > f ? 1 : 0;
  1739. 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, 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 {
  1740. var t = Math.floor(Math.log(f) / Math.LN2);
  1741. 1024 === t && (t = 1023);
  1742. k(4503599627370496 * (f *= Math.pow(2, -t)) >>> 0, u, v + l);
  1743. k((g << 31 | t + 1023 << 20 | 1048576 * f & 1048575) >>> 0, u, v + q)
  1744. }
  1745. }
  1746.  
  1747. function c(k, l, q, f, u) {
  1748. l = k(f, u + l);
  1749. f = k(f, u + q);
  1750. k = 2 * (f >> 31) + 1;
  1751. q = f >>> 20 & 2047;
  1752. l = 4294967296 * (1048575 & f) + l;
  1753. return 2047 === q ? l ? NaN : 1 / 0 * k : 0 === q ? 4.9E-324 * k * l : k * Math.pow(2, q - 1075) * (l + 4503599627370496)
  1754. }
  1755.  
  1756. a.writeDoubleLE = b.bind(null, m, 0, 4);
  1757. a.writeDoubleBE = b.bind(null, n, 4, 0);
  1758. a.readDoubleLE = c.bind(null, e, 0, 4);
  1759. a.readDoubleBE = c.bind(null, d, 4, 0)
  1760. }(), a
  1761. }
  1762.  
  1763. function m(a, b, c) {
  1764. b[c] = 255 & a;
  1765. b[c + 1] = a >>> 8 & 255;
  1766. b[c + 2] = a >>> 16 & 255;
  1767. b[c + 3] = a >>> 24
  1768. }
  1769.  
  1770. function n(a, b, c) {
  1771. b[c] = a >>> 24;
  1772. b[c + 1] = a >>> 16 & 255;
  1773. b[c + 2] = a >>> 8 & 255;
  1774. b[c + 3] = 255 & a
  1775. }
  1776.  
  1777. function e(a, b) {
  1778. return (a[b] | a[b + 1] << 8 | a[b + 2] << 16 | a[b + 3] << 24) >>> 0
  1779. }
  1780.  
  1781. function d(a, b) {
  1782. return (a[b] << 24 | a[b + 1] << 16 | a[b + 2] << 8 | a[b + 3]) >>> 0
  1783. }
  1784.  
  1785. w.exports = h(h)
  1786. }, {}], 5: [function (p, w, h) {
  1787. w.exports = function (m) {
  1788. try {
  1789. var n = eval("require")(m);
  1790. if (n && (n.length || Object.keys(n).length)) return n
  1791. } catch (e) {
  1792. }
  1793. return null
  1794. }
  1795. }, {}], 6: [function (p, w) {
  1796. w.exports = function (h, m, n) {
  1797. var e = n || 8192, d = e >>> 1, a = null, b = e;
  1798. return function (c) {
  1799. if (1 > c || d < c) return h(c);
  1800. e < b + c && (a = h(e), b = 0);
  1801. c = m.call(a, b, b += c);
  1802. return 7 & b && (b = 1 + (7 | b)), c
  1803. }
  1804. }
  1805. }, {}], 7: [function (p, w, h) {
  1806. h.length = function (m) {
  1807. 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;
  1808. return n
  1809. };
  1810. h.read = function (m, n, e) {
  1811. if (1 > e - n) return "";
  1812. 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);
  1813. return a ? (c && a.push(String.fromCharCode.apply(String, b.slice(0, c))), a.join("")) : String.fromCharCode.apply(String, b.slice(0, c))
  1814. };
  1815. h.write = function (m, n, e) {
  1816. 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);
  1817. return e - b
  1818. }
  1819. }, {}], 8: [function (p, w, h) {
  1820. function m() {
  1821. n.Reader.n(n.BufferReader);
  1822. n.util.n()
  1823. }
  1824.  
  1825. var n = h;
  1826. n.build = "minimal";
  1827. n.Writer = p(16);
  1828. n.BufferWriter = p(17);
  1829. n.Reader = p(9);
  1830. n.BufferReader = p(10);
  1831. n.util = p(15);
  1832. n.rpc = p(12);
  1833. n.roots = p(11);
  1834. n.configure = m;
  1835. n.Writer.n(n.BufferWriter);
  1836. m()
  1837. }, {10: 10, 11: 11, 12: 12, 15: 15, 16: 16, 17: 17, 9: 9}], 9: [function (p, w) {
  1838. function h(f, u) {
  1839. return RangeError("index out of range: " + f.pos + " + " + (u || 1) + " > " + f.len)
  1840. }
  1841.  
  1842. function m(f) {
  1843. this.buf = f;
  1844. this.pos = 0;
  1845. this.len = f.length
  1846. }
  1847.  
  1848. function n() {
  1849. var f = new c(0, 0), u = 0;
  1850. if (!(4 < this.len - this.pos)) {
  1851. for (; 3 > u; ++u) {
  1852. if (this.pos >= this.len) throw h(this);
  1853. if (f.lo = (f.lo | (127 & this.buf[this.pos]) << 7 * u) >>> 0, 128 > this.buf[this.pos++]) return f
  1854. }
  1855. return f.lo = (f.lo | (127 & this.buf[this.pos++]) << 7 * u) >>> 0, f
  1856. }
  1857. for (; 4 > u; ++u) if (f.lo = (f.lo | (127 & this.buf[this.pos]) << 7 * u) >>> 0, 128 > this.buf[this.pos++]) return f;
  1858. 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;
  1859. if (u = 0, 4 < this.len - this.pos) for (; 5 > u; ++u) {
  1860. if (f.hi = (f.hi | (127 & this.buf[this.pos]) << 7 * u + 3) >>> 0, 128 > this.buf[this.pos++]) return f
  1861. } else for (; 5 > u; ++u) {
  1862. if (this.pos >= this.len) throw h(this);
  1863. if (f.hi = (f.hi | (127 & this.buf[this.pos]) << 7 * u + 3) >>> 0, 128 > this.buf[this.pos++]) return f
  1864. }
  1865. throw Error("invalid varint encoding");
  1866. }
  1867.  
  1868. function e(f, u) {
  1869. return (f[u - 4] | f[u - 3] << 8 | f[u - 2] << 16 | f[u - 1] << 24) >>> 0
  1870. }
  1871.  
  1872. function d() {
  1873. if (this.pos + 8 > this.len) throw h(this, 8);
  1874. return new c(e(this.buf, this.pos += 4), e(this.buf, this.pos += 4))
  1875. }
  1876.  
  1877. w.exports = m;
  1878. var a, b = p(15), c = b.LongBits, k = b.utf8, l,
  1879. q = "undefined" != typeof Uint8Array ? function (f) {
  1880. if (f instanceof Uint8Array || Array.isArray(f)) return new m(f);
  1881. throw Error("illegal buffer");
  1882. } : function (f) {
  1883. if (Array.isArray(f)) return new m(f);
  1884. throw Error("illegal buffer");
  1885. };
  1886. m.create = b.Buffer ? function (f) {
  1887. return (m.create = function (u) {
  1888. return b.Buffer.isBuffer(u) ? new a(u) : q(u)
  1889. })(f)
  1890. } : q;
  1891. m.prototype.i = b.Array.prototype.subarray || b.Array.prototype.slice;
  1892. m.prototype.uint32 = (l = 4294967295, function () {
  1893. 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;
  1894. if ((this.pos += 5) > this.len) throw this.pos = this.len, h(this, 10);
  1895. return l
  1896. });
  1897. m.prototype.int32 = function () {
  1898. return 0 | this.uint32()
  1899. };
  1900. m.prototype.sint32 = function () {
  1901. var f = this.uint32();
  1902. return f >>> 1 ^ -(1 & f) | 0
  1903. };
  1904. m.prototype.bool = function () {
  1905. return 0 !== this.uint32()
  1906. };
  1907. m.prototype.fixed32 = function () {
  1908. if (this.pos + 4 > this.len) throw h(this, 4);
  1909. return e(this.buf, this.pos += 4)
  1910. };
  1911. m.prototype.sfixed32 = function () {
  1912. if (this.pos + 4 > this.len) throw h(this, 4);
  1913. return 0 | e(this.buf, this.pos += 4)
  1914. };
  1915. m.prototype["float"] = function () {
  1916. if (this.pos + 4 > this.len) throw h(this, 4);
  1917. var f = b["float"].readFloatLE(this.buf, this.pos);
  1918. return this.pos += 4, f
  1919. };
  1920. m.prototype["double"] = function () {
  1921. if (this.pos + 8 > this.len) throw h(this, 4);
  1922. var f = b["float"].readDoubleLE(this.buf, this.pos);
  1923. return this.pos += 8, f
  1924. };
  1925. m.prototype.bytes = function () {
  1926. var f = this.uint32(), u = this.pos, v = this.pos + f;
  1927. if (v > this.len) throw h(this, f);
  1928. 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)
  1929. };
  1930. m.prototype.string = function () {
  1931. var f = this.bytes();
  1932. return k.read(f, 0, f.length)
  1933. };
  1934. m.prototype.skip = function (f) {
  1935. if ("number" == typeof f) {
  1936. if (this.pos + f > this.len) throw h(this, f);
  1937. this.pos += f
  1938. } else {
  1939. do if (this.pos >= this.len) throw h(this); while (128 & this.buf[this.pos++])
  1940. }
  1941. return this
  1942. };
  1943. m.prototype.skipType = function (f) {
  1944. switch (f) {
  1945. case 0:
  1946. this.skip();
  1947. break;
  1948. case 1:
  1949. this.skip(8);
  1950. break;
  1951. case 2:
  1952. this.skip(this.uint32());
  1953. break;
  1954. case 3:
  1955. for (; 4 != (f = 7 & this.uint32());) this.skipType(f);
  1956. break;
  1957. case 5:
  1958. this.skip(4);
  1959. break;
  1960. default:
  1961. throw Error("invalid wire type " + f + " at offset " + this.pos);
  1962. }
  1963. return this
  1964. };
  1965. m.n = function (f) {
  1966. a = f;
  1967. var u = b.Long ? "toLong" : "toNumber";
  1968. b.merge(m.prototype, {
  1969. int64: function () {
  1970. return n.call(this)[u](!1)
  1971. }, uint64: function () {
  1972. return n.call(this)[u](!0)
  1973. }, sint64: function () {
  1974. return n.call(this).zzDecode()[u](!1)
  1975. }, fixed64: function () {
  1976. return d.call(this)[u](!0)
  1977. }, sfixed64: function () {
  1978. return d.call(this)[u](!1)
  1979. }
  1980. })
  1981. }
  1982. }, {15: 15}], 10: [function (p, w) {
  1983. function h(e) {
  1984. m.call(this, e)
  1985. }
  1986.  
  1987. w.exports = h;
  1988. var m = p(9);
  1989. (h.prototype = Object.create(m.prototype)).constructor = h;
  1990. var n = p(15);
  1991. n.Buffer && (h.prototype.i = n.Buffer.prototype.slice);
  1992. h.prototype.string = function () {
  1993. var e = this.uint32();
  1994. return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + e, this.len))
  1995. }
  1996. }, {15: 15, 9: 9}], 11: [function (p, w) {
  1997. w.exports = {}
  1998. }, {}], 12: [function (p, w, h) {
  1999. h.Service = p(13)
  2000. }, {13: 13}], 13: [function (p, w) {
  2001. function h(n, e, d) {
  2002. if ("function" != typeof n) throw TypeError("rpcImpl must be a function");
  2003. m.EventEmitter.call(this);
  2004. this.rpcImpl = n;
  2005. this.requestDelimited = !!e;
  2006. this.responseDelimited = !!d
  2007. }
  2008.  
  2009. w.exports = h;
  2010. var m = p(15);
  2011. ((h.prototype = Object.create(m.EventEmitter.prototype)).constructor = h).prototype.rpcCall = function k(e, d, a, b, c) {
  2012. if (!b) throw TypeError("request must be specified");
  2013. var l = this;
  2014. if (!c) return m.asPromise(k, l, e, d, a, b);
  2015. if (!l.rpcImpl) return setTimeout(function () {
  2016. c(Error("already ended"))
  2017. }, 0), z;
  2018. try {
  2019. return l.rpcImpl(e, d[l.requestDelimited ? "encodeDelimited" : "encode"](b).finish(), function (q, f) {
  2020. if (q) return l.emit("error", q, e), c(q);
  2021. if (null === f) return l.end(!0), z;
  2022. if (!(f instanceof a)) try {
  2023. f = a[l.responseDelimited ? "decodeDelimited" : "decode"](f)
  2024. } catch (u) {
  2025. return l.emit("error", u, e), c(u)
  2026. }
  2027. return l.emit("data", f, e), c(null, f)
  2028. })
  2029. } catch (q) {
  2030. return l.emit("error", q, e), setTimeout(function () {
  2031. c(q)
  2032. }, 0), z
  2033. }
  2034. };
  2035. h.prototype.end = function (e) {
  2036. return this.rpcImpl && (e || this.rpcImpl(null, null, null), this.rpcImpl = null, this.emit("end").off()), this
  2037. }
  2038. }, {15: 15}], 14: [function (p, w) {
  2039. function h(a, b) {
  2040. this.lo = a >>> 0;
  2041. this.hi = b >>> 0
  2042. }
  2043.  
  2044. w.exports = h;
  2045. var m = p(15), n = h.zero = new h(0, 0);
  2046. n.toNumber = function () {
  2047. return 0
  2048. };
  2049. n.zzEncode = n.zzDecode = function () {
  2050. return this
  2051. };
  2052. n.length = function () {
  2053. return 1
  2054. };
  2055. var e = h.zeroHash = "\x00\x00\x00\x00\x00\x00\x00\x00";
  2056. h.fromNumber = function (a) {
  2057. if (0 === a) return n;
  2058. var b = 0 > a;
  2059. b && (a = -a);
  2060. var c = a >>> 0;
  2061. a = (a - c) / 4294967296 >>> 0;
  2062. return b && (a = ~a >>> 0, c = ~c >>> 0, 4294967295 < ++c && (c = 0, 4294967295 < ++a && (a = 0))), new h(c, a)
  2063. };
  2064. h.from = function (a) {
  2065. if ("number" == typeof a) return h.fromNumber(a);
  2066. if (m.isString(a)) {
  2067. if (!m.Long) return h.fromNumber(parseInt(a, 10));
  2068. a = m.Long.fromString(a)
  2069. }
  2070. return a.low || a.high ? new h(a.low >>> 0, a.high >>> 0) : n
  2071. };
  2072. h.prototype.toNumber = function (a) {
  2073. if (!a && this.hi >>> 31) {
  2074. a = 1 + ~this.lo >>> 0;
  2075. var b = ~this.hi >>> 0;
  2076. return a || (b = b + 1 >>> 0), -(a + 4294967296 * b)
  2077. }
  2078. return this.lo + 4294967296 * this.hi
  2079. };
  2080. h.prototype.toLong = function (a) {
  2081. return m.Long ? new m.Long(0 | this.lo, 0 | this.hi, !!a) : {
  2082. low: 0 | this.lo, high: 0 | this.hi, unsigned: !!a
  2083. }
  2084. };
  2085. var d = String.prototype.charCodeAt;
  2086. h.fromHash = function (a) {
  2087. 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)
  2088. };
  2089. h.prototype.toHash = function () {
  2090. 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 >>> 16 & 255, this.hi >>> 24)
  2091. };
  2092. h.prototype.zzEncode = function () {
  2093. var a = this.hi >> 31;
  2094. return this.hi = ((this.hi << 1 | this.lo >>> 31) ^ a) >>> 0, this.lo = (this.lo << 1 ^ a) >>> 0, this
  2095. };
  2096. h.prototype.zzDecode = function () {
  2097. var a = -(1 & this.lo);
  2098. return this.lo = ((this.lo >>> 1 | this.hi << 31) ^ a) >>> 0, this.hi = (this.hi >>> 1 ^ a) >>> 0, this
  2099. };
  2100. h.prototype.length = function () {
  2101. var a = this.lo, b = (this.lo >>> 28 | this.hi << 4) >>> 0, c = this.hi >>> 24;
  2102. 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
  2103. }
  2104. }, {15: 15}], 15: [function (p, w, h) {
  2105. function m(e, d, a) {
  2106. for (var b = Object.keys(d), c = 0; c < b.length; ++c) e[b[c]] !== z && a || (e[b[c]] = d[b[c]]);
  2107. return e
  2108. }
  2109.  
  2110. function n(e) {
  2111. function d(a, b) {
  2112. if (!(this instanceof d)) return new d(a, b);
  2113. Object.defineProperty(this, "message", {
  2114. get: function () {
  2115. return a
  2116. }
  2117. });
  2118. Error.captureStackTrace ? Error.captureStackTrace(this, d) : Object.defineProperty(this, "stack", {value: Error().stack || ""});
  2119. b && m(this, b)
  2120. }
  2121.  
  2122. return (d.prototype = Object.create(Error.prototype)).constructor = d, Object.defineProperty(d.prototype, "name", {
  2123. get: function () {
  2124. return e
  2125. }
  2126. }), d.prototype.toString = function () {
  2127. return this.name + ": " + this.message
  2128. }, d
  2129. }
  2130.  
  2131. h.asPromise = p(1);
  2132. h.base64 = p(2);
  2133. h.EventEmitter = p(3);
  2134. h["float"] = p(4);
  2135. h.inquire = p(5);
  2136. h.utf8 = p(7);
  2137. h.pool = p(6);
  2138. h.LongBits = p(14);
  2139. h.global = "undefined" != typeof window && window || "undefined" != typeof global && global || "undefined" != typeof self && self || this;
  2140. h.emptyArray = Object.freeze ? Object.freeze([]) : [];
  2141. h.emptyObject = Object.freeze ? Object.freeze({}) : {};
  2142. h.isNode = !!(h.global.process && h.global.process.versions && h.global.process.versions.node);
  2143. h.isInteger = Number.isInteger || function (e) {
  2144. return "number" == typeof e && isFinite(e) && Math.floor(e) === e
  2145. };
  2146. h.isString = function (e) {
  2147. return "string" == typeof e || e instanceof String
  2148. };
  2149. h.isObject = function (e) {
  2150. return e && "object" == typeof e
  2151. };
  2152. h.isset = h.isSet = function (e, d) {
  2153. var a = e[d];
  2154. return !(null == a || !e.hasOwnProperty(d)) && ("object" != typeof a || 0 < (Array.isArray(a) ? a.length : Object.keys(a).length))
  2155. };
  2156. h.Buffer = function () {
  2157. try {
  2158. var e = h.inquire("buffer").Buffer;
  2159. return e.prototype.utf8Write ? e : null
  2160. } catch (d) {
  2161. return null
  2162. }
  2163. }();
  2164. h.r = null;
  2165. h.u = null;
  2166. h.newBuffer = function (e) {
  2167. 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)
  2168. };
  2169. h.Array = "undefined" != typeof Uint8Array ? Uint8Array : Array;
  2170. h.Long = h.global.dcodeIO && h.global.dcodeIO.Long || h.global.Long || h.inquire("long");
  2171. h.key2Re = /^true|false|0|1$/;
  2172. h.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
  2173. h.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
  2174. h.longToHash = function (e) {
  2175. return e ? h.LongBits.from(e).toHash() : h.LongBits.zeroHash
  2176. };
  2177. h.longFromHash = function (e, d) {
  2178. var a = h.LongBits.fromHash(e);
  2179. return h.Long ? h.Long.fromBits(a.lo, a.hi, d) : a.toNumber(!!d)
  2180. };
  2181. h.merge = m;
  2182. h.lcFirst = function (e) {
  2183. return e.charAt(0).toLowerCase() + e.substring(1)
  2184. };
  2185. h.newError = n;
  2186. h.ProtocolError = n("ProtocolError");
  2187. h.oneOfGetter = function (e) {
  2188. for (var d = {}, a = 0; a < e.length; ++a) d[e[a]] = 1;
  2189. return function () {
  2190. 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]
  2191. }
  2192. };
  2193. h.oneOfSetter = function (e) {
  2194. return function (d) {
  2195. for (var a = 0; a < e.length; ++a) e[a] !== d && delete this[e[a]]
  2196. }
  2197. };
  2198. h.toJSONOptions = {longs: String, enums: String, bytes: String, json: !0};
  2199. h.n = function () {
  2200. var e = h.Buffer;
  2201. e ? (h.r = e.from !== Uint8Array.from && e.from || function (d, a) {
  2202. return new e(d, a)
  2203. }, h.u = e.allocUnsafe || function (d) {
  2204. return new e(d)
  2205. }) : h.r = h.u = null
  2206. }
  2207. }, {1: 1, 14: 14, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7}], 16: [function (p, w) {
  2208. function h(g, t, x) {
  2209. this.fn = g;
  2210. this.len = t;
  2211. this.next = z;
  2212. this.val = x
  2213. }
  2214.  
  2215. function m() {
  2216. }
  2217.  
  2218. function n(g) {
  2219. this.head = g.head;
  2220. this.tail = g.tail;
  2221. this.len = g.len;
  2222. this.next = g.states
  2223. }
  2224.  
  2225. function e() {
  2226. this.len = 0;
  2227. this.tail = this.head = new h(m, 0, 0);
  2228. this.states = null
  2229. }
  2230.  
  2231. function d(g, t, x) {
  2232. t[x] = 255 & g
  2233. }
  2234.  
  2235. function a(g, t) {
  2236. this.len = g;
  2237. this.next = z;
  2238. this.val = t
  2239. }
  2240.  
  2241. function b(g, t, x) {
  2242. for (; g.hi;) t[x++] = 127 & g.lo | 128, g.lo = (g.lo >>> 7 | g.hi << 25) >>> 0, g.hi >>>= 7;
  2243. for (; 127 < g.lo;) t[x++] = 127 & g.lo | 128, g.lo >>>= 7;
  2244. t[x++] = g.lo
  2245. }
  2246.  
  2247. function c(g, t, x) {
  2248. t[x] = 255 & g;
  2249. t[x + 1] = g >>> 8 & 255;
  2250. t[x + 2] = g >>> 16 & 255;
  2251. t[x + 3] = g >>> 24
  2252. }
  2253.  
  2254. w.exports = e;
  2255. var k, l = p(15), q = l.LongBits, f = l.base64, u = l.utf8;
  2256. e.create = l.Buffer ? function () {
  2257. return (e.create = function () {
  2258. return new k
  2259. })()
  2260. } : function () {
  2261. return new e
  2262. };
  2263. e.alloc = function (g) {
  2264. return new l.Array(g)
  2265. };
  2266. l.Array !== Array && (e.alloc = l.pool(e.alloc, l.Array.prototype.subarray));
  2267. e.prototype.e = function (g, t, x) {
  2268. return this.tail = this.tail.next = new h(g, t, x), this.len += t, this
  2269. };
  2270. (a.prototype = Object.create(h.prototype)).fn = function (g, t, x) {
  2271. for (; 127 < g;) t[x++] = 127 & g | 128, g >>>= 7;
  2272. t[x] = g
  2273. };
  2274. e.prototype.uint32 = function (g) {
  2275. 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
  2276. };
  2277. e.prototype.int32 = function (g) {
  2278. return 0 > g ? this.e(b, 10, q.fromNumber(g)) : this.uint32(g)
  2279. };
  2280. e.prototype.sint32 = function (g) {
  2281. return this.uint32((g << 1 ^ g >> 31) >>> 0)
  2282. };
  2283. e.prototype.int64 = e.prototype.uint64 = function (g) {
  2284. g = q.from(g);
  2285. return this.e(b, g.length(), g)
  2286. };
  2287. e.prototype.sint64 = function (g) {
  2288. g = q.from(g).zzEncode();
  2289. return this.e(b, g.length(), g)
  2290. };
  2291. e.prototype.bool = function (g) {
  2292. return this.e(d, 1, g ? 1 : 0)
  2293. };
  2294. e.prototype.sfixed32 = e.prototype.fixed32 = function (g) {
  2295. return this.e(c, 4, g >>> 0)
  2296. };
  2297. e.prototype.sfixed64 = e.prototype.fixed64 = function (g) {
  2298. g = q.from(g);
  2299. return this.e(c, 4, g.lo).e(c, 4, g.hi)
  2300. };
  2301. e.prototype["float"] = function (g) {
  2302. return this.e(l["float"].writeFloatLE, 4, g)
  2303. };
  2304. e.prototype["double"] = function (g) {
  2305. return this.e(l["float"].writeDoubleLE, 8, g)
  2306. };
  2307. var v = l.Array.prototype.set ? function (g, t, x) {
  2308. t.set(g, x)
  2309. } : function (g, t, x) {
  2310. for (var B = 0; B < g.length; ++B) t[x + B] = g[B]
  2311. };
  2312. e.prototype.bytes = function (g) {
  2313. var t = g.length >>> 0;
  2314. if (!t) return this.e(d, 1, 0);
  2315. if (l.isString(g)) {
  2316. var x = e.alloc(t = f.length(g));
  2317. f.decode(g, x, 0);
  2318. g = x
  2319. }
  2320. return this.uint32(t).e(v, t, g)
  2321. };
  2322. e.prototype.string = function (g) {
  2323. var t = u.length(g);
  2324. return t ? this.uint32(t).e(u.write, t, g) : this.e(d, 1, 0)
  2325. };
  2326. e.prototype.fork = function () {
  2327. return this.states = new n(this), this.head = this.tail = new h(m, 0, 0), this.len = 0, this
  2328. };
  2329. e.prototype.reset = function () {
  2330. 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
  2331. };
  2332. e.prototype.ldelim = function () {
  2333. var g = this.head, t = this.tail, x = this.len;
  2334. return this.reset().uint32(x), x && (this.tail.next = g.next, this.tail = t, this.len += x), this
  2335. };
  2336. e.prototype.finish = function () {
  2337. for (var g = this.head.next, t = this.constructor.alloc(this.len), x = 0; g;) g.fn(g.val, t, x), x += g.len, g = g.next;
  2338. return t
  2339. };
  2340. e.n = function (g) {
  2341. k = g
  2342. }
  2343. }, {15: 15}], 17: [function (p, w) {
  2344. function h() {
  2345. n.call(this)
  2346. }
  2347.  
  2348. function m(b, c, k) {
  2349. 40 > b.length ? e.utf8.write(b, c, k) : c.utf8Write(b, k)
  2350. }
  2351.  
  2352. w.exports = h;
  2353. var n = p(16);
  2354. (h.prototype = Object.create(n.prototype)).constructor = h;
  2355. var e = p(15), d = e.Buffer;
  2356. h.alloc = function (b) {
  2357. return (h.alloc = e.u)(b)
  2358. };
  2359. var a = d && d.prototype instanceof Uint8Array && "set" === d.prototype.set.name ? function (b, c, k) {
  2360. c.set(b, k)
  2361. } : function (b, c, k) {
  2362. if (b.copy) b.copy(c, k, 0, b.length); else for (var l = 0; l < b.length;) c[k++] = b[l++]
  2363. };
  2364. h.prototype.bytes = function (b) {
  2365. e.isString(b) && (b = e.r(b, "base64"));
  2366. var c = b.length >>> 0;
  2367. return this.uint32(c), c && this.e(a, c, b), this
  2368. };
  2369. h.prototype.string = function (b) {
  2370. var c = d.byteLength(b);
  2371. return this.uint32(c), c && this.e(m, c, b), this
  2372. }
  2373. }, {15: 15, 16: 16}]
  2374. };
  2375. var A = {};
  2376. var r = function h(w) {
  2377. var m = A[w];
  2378. return m || y[w][0].call(m = A[w] = {exports: {}}, h, m, m.exports), m.exports
  2379. }(8);
  2380. r.util.global.protobuf = r;
  2381. "function" == typeof define && define.amd && define(["long"], function (w) {
  2382. return w && w.isLong && (r.util.Long = w, r.configure()), r
  2383. });
  2384. "object" == typeof module && module && module.exports && (module.exports = r)
  2385. }();
  2386. (function (z) {
  2387. var y = z.Reader, A = z.Writer, r = z.util, p = z.roots["default"] || (z.roots["default"] = {});
  2388. p.bilibili = function () {
  2389. var w = {};
  2390. w.community = function () {
  2391. var h = {};
  2392. h.service = function () {
  2393. var m = {};
  2394. m.dm = function () {
  2395. var n = {};
  2396. n.v1 = function () {
  2397. var e = {};
  2398. e.DmWebViewReply = function () {
  2399. function d(a) {
  2400. this.specialDms = [];
  2401. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  2402. }
  2403.  
  2404. d.prototype.state = 0;
  2405. d.prototype.text = "";
  2406. d.prototype.textSide = "";
  2407. d.prototype.dmSge = null;
  2408. d.prototype.flag = null;
  2409. d.prototype.specialDms = r.emptyArray;
  2410. d.create = function (a) {
  2411. return new d(a)
  2412. };
  2413. d.encode = function (a, b) {
  2414. b || (b = A.create());
  2415. null != a.state && Object.hasOwnProperty.call(a, "state") && b.uint32(8).int32(a.state);
  2416. null != a.text && Object.hasOwnProperty.call(a, "text") && b.uint32(18).string(a.text);
  2417. null != a.textSide && Object.hasOwnProperty.call(a, "textSide") && b.uint32(26).string(a.textSide);
  2418. null != a.dmSge && Object.hasOwnProperty.call(a, "dmSge") && p.bilibili.community.service.dm.v1.DmSegConfig.encode(a.dmSge, b.uint32(34).fork()).ldelim();
  2419. null != a.flag && Object.hasOwnProperty.call(a, "flag") && p.bilibili.community.service.dm.v1.DanmakuFlagConfig.encode(a.flag, b.uint32(42).fork()).ldelim();
  2420. if (null != a.specialDms && a.specialDms.length) for (var c = 0; c < a.specialDms.length; ++c) b.uint32(50).string(a.specialDms[c]);
  2421. return b
  2422. };
  2423. d.encodeDelimited = function (a, b) {
  2424. return this.encode(a, b).ldelim()
  2425. };
  2426. d.decode = function (a, b) {
  2427. a instanceof y || (a = y.create(a));
  2428. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DmWebViewReply; a.pos < c;) {
  2429. var l = a.uint32();
  2430. switch (l >>> 3) {
  2431. case 1:
  2432. k.state = a.int32();
  2433. break;
  2434. case 2:
  2435. k.text = a.string();
  2436. break;
  2437. case 3:
  2438. k.textSide = a.string();
  2439. break;
  2440. case 4:
  2441. k.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.decode(a, a.uint32());
  2442. break;
  2443. case 5:
  2444. k.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.decode(a, a.uint32());
  2445. break;
  2446. case 6:
  2447. k.specialDms && k.specialDms.length || (k.specialDms = []);
  2448. k.specialDms.push(a.string());
  2449. break;
  2450. default:
  2451. a.skipType(l & 7)
  2452. }
  2453. }
  2454. return k
  2455. };
  2456. d.decodeDelimited = function (a) {
  2457. a instanceof y || (a = new y(a));
  2458. return this.decode(a, a.uint32())
  2459. };
  2460. d.verify = function (a) {
  2461. if ("object" !== typeof a || null === a) return "object expected";
  2462. if (null != a.state && a.hasOwnProperty("state") && !r.isInteger(a.state)) return "state: integer expected";
  2463. if (null != a.text && a.hasOwnProperty("text") && !r.isString(a.text)) return "text: string expected";
  2464. if (null != a.textSide && a.hasOwnProperty("textSide") && !r.isString(a.textSide)) return "textSide: string expected";
  2465. if (null != a.dmSge && a.hasOwnProperty("dmSge")) {
  2466. var b = p.bilibili.community.service.dm.v1.DmSegConfig.verify(a.dmSge);
  2467. if (b) return "dmSge." + b
  2468. }
  2469. if (null != a.flag && a.hasOwnProperty("flag") && (b = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.verify(a.flag))) return "flag." + b;
  2470. if (null != a.specialDms && a.hasOwnProperty("specialDms")) {
  2471. if (!Array.isArray(a.specialDms)) return "specialDms: array expected";
  2472. for (b = 0; b < a.specialDms.length; ++b) if (!r.isString(a.specialDms[b])) return "specialDms: string[] expected"
  2473. }
  2474. return null
  2475. };
  2476. d.fromObject = function (a) {
  2477. if (a instanceof p.bilibili.community.service.dm.v1.DmWebViewReply) return a;
  2478. var b = new p.bilibili.community.service.dm.v1.DmWebViewReply;
  2479. null != a.state && (b.state = a.state | 0);
  2480. null != a.text && (b.text = String(a.text));
  2481. null != a.textSide && (b.textSide = String(a.textSide));
  2482. if (null != a.dmSge) {
  2483. if ("object" !== typeof a.dmSge) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.dmSge: object expected");
  2484. b.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.fromObject(a.dmSge)
  2485. }
  2486. if (null != a.flag) {
  2487. if ("object" !== typeof a.flag) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.flag: object expected");
  2488. b.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.fromObject(a.flag)
  2489. }
  2490. if (a.specialDms) {
  2491. if (!Array.isArray(a.specialDms)) throw TypeError(".bilibili.community.service.dm.v1.DmWebViewReply.specialDms: array expected");
  2492. b.specialDms = [];
  2493. for (var c = 0; c < a.specialDms.length; ++c) b.specialDms[c] = String(a.specialDms[c])
  2494. }
  2495. return b
  2496. };
  2497. d.toObject = function (a, b) {
  2498. b || (b = {});
  2499. var c = {};
  2500. if (b.arrays || b.defaults) c.specialDms = [];
  2501. b.defaults && (c.state = 0, c.text = "", c.textSide = "", c.dmSge = null, c.flag = null);
  2502. null != a.state && a.hasOwnProperty("state") && (c.state = a.state);
  2503. null != a.text && a.hasOwnProperty("text") && (c.text = a.text);
  2504. null != a.textSide && a.hasOwnProperty("textSide") && (c.textSide = a.textSide);
  2505. null != a.dmSge && a.hasOwnProperty("dmSge") && (c.dmSge = p.bilibili.community.service.dm.v1.DmSegConfig.toObject(a.dmSge, b));
  2506. null != a.flag && a.hasOwnProperty("flag") && (c.flag = p.bilibili.community.service.dm.v1.DanmakuFlagConfig.toObject(a.flag, b));
  2507. if (a.specialDms && a.specialDms.length) {
  2508. c.specialDms = [];
  2509. for (var k = 0; k < a.specialDms.length; ++k) c.specialDms[k] = a.specialDms[k]
  2510. }
  2511. return c
  2512. };
  2513. d.prototype.toJSON = function () {
  2514. return this.constructor.toObject(this, z.util.toJSONOptions)
  2515. };
  2516. return d
  2517. }();
  2518. e.DmSegConfig = function () {
  2519. function d(a) {
  2520. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  2521. }
  2522.  
  2523. d.prototype.pageSize = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  2524. d.prototype.total = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  2525. d.create = function (a) {
  2526. return new d(a)
  2527. };
  2528. d.encode = function (a, b) {
  2529. b || (b = A.create());
  2530. null != a.pageSize && Object.hasOwnProperty.call(a, "pageSize") && b.uint32(8).int64(a.pageSize);
  2531. null != a.total && Object.hasOwnProperty.call(a, "total") && b.uint32(16).int64(a.total);
  2532. return b
  2533. };
  2534. d.encodeDelimited = function (a, b) {
  2535. return this.encode(a, b).ldelim()
  2536. };
  2537. d.decode = function (a, b) {
  2538. a instanceof y || (a = y.create(a));
  2539. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DmSegConfig; a.pos < c;) {
  2540. var l = a.uint32();
  2541. switch (l >>> 3) {
  2542. case 1:
  2543. k.pageSize = a.int64();
  2544. break;
  2545. case 2:
  2546. k.total = a.int64();
  2547. break;
  2548. default:
  2549. a.skipType(l & 7)
  2550. }
  2551. }
  2552. return k
  2553. };
  2554. d.decodeDelimited = function (a) {
  2555. a instanceof y || (a = new y(a));
  2556. return this.decode(a, a.uint32())
  2557. };
  2558. d.verify = function (a) {
  2559. 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) ? 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"
  2560. };
  2561. d.fromObject = function (a) {
  2562. if (a instanceof p.bilibili.community.service.dm.v1.DmSegConfig) return a;
  2563. var b = new p.bilibili.community.service.dm.v1.DmSegConfig;
  2564. 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" === 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()));
  2565. 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()));
  2566. return b
  2567. };
  2568. d.toObject = function (a, b) {
  2569. b || (b = {});
  2570. var c = {};
  2571. if (b.defaults) {
  2572. if (r.Long) {
  2573. var k = new r.Long(0, 0, !1);
  2574. c.pageSize = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k
  2575. } else c.pageSize = b.longs === String ? "0" : 0;
  2576. 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
  2577. }
  2578. 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 >>> 0, a.pageSize.high >>> 0)).toNumber() : a.pageSize);
  2579. 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);
  2580. return c
  2581. };
  2582. d.prototype.toJSON = function () {
  2583. return this.constructor.toObject(this, z.util.toJSONOptions)
  2584. };
  2585. return d
  2586. }();
  2587. e.DanmakuFlagConfig = function () {
  2588. function d(a) {
  2589. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  2590. }
  2591.  
  2592. d.prototype.recFlag = 0;
  2593. d.prototype.recText = "";
  2594. d.prototype.recSwitch = 0;
  2595. d.create = function (a) {
  2596. return new d(a)
  2597. };
  2598. d.encode = function (a, b) {
  2599. b || (b = A.create());
  2600. null != a.recFlag && Object.hasOwnProperty.call(a, "recFlag") && b.uint32(8).int32(a.recFlag);
  2601. null != a.recText && Object.hasOwnProperty.call(a, "recText") && b.uint32(18).string(a.recText);
  2602. null != a.recSwitch && Object.hasOwnProperty.call(a, "recSwitch") && b.uint32(24).int32(a.recSwitch);
  2603. return b
  2604. };
  2605. d.encodeDelimited = function (a, b) {
  2606. return this.encode(a, b).ldelim()
  2607. };
  2608. d.decode = function (a, b) {
  2609. a instanceof y || (a = y.create(a));
  2610. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DanmakuFlagConfig; a.pos < c;) {
  2611. var l = a.uint32();
  2612. switch (l >>> 3) {
  2613. case 1:
  2614. k.recFlag = a.int32();
  2615. break;
  2616. case 2:
  2617. k.recText = a.string();
  2618. break;
  2619. case 3:
  2620. k.recSwitch = a.int32();
  2621. break;
  2622. default:
  2623. a.skipType(l & 7)
  2624. }
  2625. }
  2626. return k
  2627. };
  2628. d.decodeDelimited = function (a) {
  2629. a instanceof y || (a = new y(a));
  2630. return this.decode(a, a.uint32())
  2631. };
  2632. d.verify = function (a) {
  2633. return "object" !== typeof a || 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
  2634. };
  2635. d.fromObject = function (a) {
  2636. if (a instanceof p.bilibili.community.service.dm.v1.DanmakuFlagConfig) return a;
  2637. var b = new p.bilibili.community.service.dm.v1.DanmakuFlagConfig;
  2638. null != a.recFlag && (b.recFlag = a.recFlag | 0);
  2639. null != a.recText && (b.recText = String(a.recText));
  2640. null != a.recSwitch && (b.recSwitch = a.recSwitch | 0);
  2641. return b
  2642. };
  2643. d.toObject = function (a, b) {
  2644. b || (b = {});
  2645. var c = {};
  2646. b.defaults && (c.recFlag = 0, c.recText = "", c.recSwitch = 0);
  2647. null != a.recFlag && a.hasOwnProperty("recFlag") && (c.recFlag = a.recFlag);
  2648. null != a.recText && a.hasOwnProperty("recText") && (c.recText = a.recText);
  2649. null != a.recSwitch && a.hasOwnProperty("recSwitch") && (c.recSwitch = a.recSwitch);
  2650. return c
  2651. };
  2652. d.prototype.toJSON = function () {
  2653. return this.constructor.toObject(this, z.util.toJSONOptions)
  2654. };
  2655. return d
  2656. }();
  2657. e.DmSegMobileReply = function () {
  2658. function d(a) {
  2659. this.elems = [];
  2660. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  2661. }
  2662.  
  2663. d.prototype.elems = r.emptyArray;
  2664. d.create = function (a) {
  2665. return new d(a)
  2666. };
  2667. d.encode = function (a, b) {
  2668. b || (b = A.create());
  2669. 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();
  2670. return b
  2671. };
  2672. d.encodeDelimited = function (a, b) {
  2673. return this.encode(a, b).ldelim()
  2674. };
  2675. d.decode = function (a, b) {
  2676. a instanceof y || (a = y.create(a));
  2677. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DmSegMobileReply; a.pos < c;) {
  2678. var l = a.uint32();
  2679. switch (l >>> 3) {
  2680. case 1:
  2681. k.elems && k.elems.length || (k.elems = []);
  2682. k.elems.push(p.bilibili.community.service.dm.v1.DanmakuElem.decode(a, a.uint32()));
  2683. break;
  2684. default:
  2685. a.skipType(l & 7)
  2686. }
  2687. }
  2688. return k
  2689. };
  2690. d.decodeDelimited = function (a) {
  2691. a instanceof y || (a = new y(a));
  2692. return this.decode(a, a.uint32())
  2693. };
  2694. d.verify = function (a) {
  2695. if ("object" !== typeof a || null === a) return "object expected";
  2696. if (null != a.elems && a.hasOwnProperty("elems")) {
  2697. if (!Array.isArray(a.elems)) return "elems: array expected";
  2698. for (var b = 0; b < a.elems.length; ++b) {
  2699. var c = p.bilibili.community.service.dm.v1.DanmakuElem.verify(a.elems[b]);
  2700. if (c) return "elems." + c
  2701. }
  2702. }
  2703. return null
  2704. };
  2705. d.fromObject = function (a) {
  2706. if (a instanceof p.bilibili.community.service.dm.v1.DmSegMobileReply) return a;
  2707. var b = new p.bilibili.community.service.dm.v1.DmSegMobileReply;
  2708. if (a.elems) {
  2709. if (!Array.isArray(a.elems)) throw TypeError(".bilibili.community.service.dm.v1.DmSegMobileReply.elems: array expected");
  2710. b.elems = [];
  2711. for (var c = 0; c < a.elems.length; ++c) {
  2712. if ("object" !== typeof a.elems[c]) throw TypeError(".bilibili.community.service.dm.v1.DmSegMobileReply.elems: object expected");
  2713. b.elems[c] = p.bilibili.community.service.dm.v1.DanmakuElem.fromObject(a.elems[c])
  2714. }
  2715. }
  2716. return b
  2717. };
  2718. d.toObject = function (a, b) {
  2719. b || (b = {});
  2720. var c = {};
  2721. if (b.arrays || b.defaults) c.elems = [];
  2722. if (a.elems && a.elems.length) {
  2723. c.elems = [];
  2724. for (var k = 0; k < a.elems.length; ++k) c.elems[k] = p.bilibili.community.service.dm.v1.DanmakuElem.toObject(a.elems[k], b)
  2725. }
  2726. return c
  2727. };
  2728. d.prototype.toJSON = function () {
  2729. return this.constructor.toObject(this, z.util.toJSONOptions)
  2730. };
  2731. return d
  2732. }();
  2733. e.DanmakuElem = function () {
  2734. function d(a) {
  2735. if (a) for (var b = Object.keys(a), c = 0; c < b.length; ++c) null != a[b[c]] && (this[b[c]] = a[b[c]])
  2736. }
  2737.  
  2738. d.prototype.id = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  2739. d.prototype.progress = 0;
  2740. d.prototype.mode = 0;
  2741. d.prototype.fontsize = 0;
  2742. d.prototype.color = 0;
  2743. d.prototype.midHash = "";
  2744. d.prototype.content = "";
  2745. d.prototype.ctime = r.Long ? r.Long.fromBits(0, 0, !1) : 0;
  2746. d.prototype.weight = 0;
  2747. d.prototype.action = "";
  2748. d.prototype.pool = 0;
  2749. d.prototype.idStr = "";
  2750. d.create = function (a) {
  2751. return new d(a)
  2752. };
  2753. d.encode = function (a, b) {
  2754. b || (b = A.create());
  2755. null != a.id && Object.hasOwnProperty.call(a, "id") && b.uint32(8).int64(a.id);
  2756. null != a.progress && Object.hasOwnProperty.call(a, "progress") && b.uint32(16).int32(a.progress);
  2757. null != a.mode && Object.hasOwnProperty.call(a, "mode") && b.uint32(24).int32(a.mode);
  2758. null != a.fontsize && Object.hasOwnProperty.call(a, "fontsize") && b.uint32(32).int32(a.fontsize);
  2759. null != a.color && Object.hasOwnProperty.call(a, "color") && b.uint32(40).uint32(a.color);
  2760. null != a.midHash && Object.hasOwnProperty.call(a, "midHash") && b.uint32(50).string(a.midHash);
  2761. null != a.content && Object.hasOwnProperty.call(a, "content") && b.uint32(58).string(a.content);
  2762. null != a.ctime && Object.hasOwnProperty.call(a, "ctime") && b.uint32(64).int64(a.ctime);
  2763. null != a.weight && Object.hasOwnProperty.call(a, "weight") && b.uint32(72).int32(a.weight);
  2764. null != a.action && Object.hasOwnProperty.call(a, "action") && b.uint32(82).string(a.action);
  2765. null != a.pool && Object.hasOwnProperty.call(a, "pool") && b.uint32(88).int32(a.pool);
  2766. null != a.idStr && Object.hasOwnProperty.call(a, "idStr") && b.uint32(98).string(a.idStr);
  2767. return b
  2768. };
  2769. d.encodeDelimited = function (a, b) {
  2770. return this.encode(a, b).ldelim()
  2771. };
  2772. d.decode = function (a, b) {
  2773. a instanceof y || (a = y.create(a));
  2774. for (var c = void 0 === b ? a.len : a.pos + b, k = new p.bilibili.community.service.dm.v1.DanmakuElem; a.pos < c;) {
  2775. var l = a.uint32();
  2776. switch (l >>> 3) {
  2777. case 1:
  2778. k.id = a.int64();
  2779. break;
  2780. case 2:
  2781. k.progress = a.int32();
  2782. break;
  2783. case 3:
  2784. k.mode = a.int32();
  2785. break;
  2786. case 4:
  2787. k.fontsize = a.int32();
  2788. break;
  2789. case 5:
  2790. k.color = a.uint32();
  2791. break;
  2792. case 6:
  2793. k.midHash = a.string();
  2794. break;
  2795. case 7:
  2796. k.content = a.string();
  2797. break;
  2798. case 8:
  2799. k.ctime = a.int64();
  2800. break;
  2801. case 9:
  2802. k.weight = a.int32();
  2803. break;
  2804. case 10:
  2805. k.action = a.string();
  2806. break;
  2807. case 11:
  2808. k.pool = a.int32();
  2809. break;
  2810. case 12:
  2811. k.idStr = a.string();
  2812. break;
  2813. default:
  2814. a.skipType(l & 7)
  2815. }
  2816. }
  2817. return k
  2818. };
  2819. d.decodeDelimited = function (a) {
  2820. a instanceof y || (a = new y(a));
  2821. return this.decode(a, a.uint32())
  2822. };
  2823. d.verify = function (a) {
  2824. 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) && 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 != 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 && a.hasOwnProperty("idStr") && !r.isString(a.idStr) ? "idStr: string expected" : null : "ctime: integer|Long expected" : "id: integer|Long expected"
  2825. };
  2826. d.fromObject = function (a) {
  2827. if (a instanceof p.bilibili.community.service.dm.v1.DanmakuElem) return a;
  2828. var b = new p.bilibili.community.service.dm.v1.DanmakuElem;
  2829. 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 >>> 0)).toNumber()));
  2830. null != a.progress && (b.progress = a.progress | 0);
  2831. null != a.mode && (b.mode = a.mode | 0);
  2832. null != a.fontsize && (b.fontsize = a.fontsize | 0);
  2833. null != a.color && (b.color = a.color >>> 0);
  2834. null != a.midHash && (b.midHash = String(a.midHash));
  2835. null != a.content && (b.content = String(a.content));
  2836. 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 >>> 0, a.ctime.high >>> 0)).toNumber()));
  2837. null != a.weight && (b.weight = a.weight | 0);
  2838. null != a.action && (b.action = String(a.action));
  2839. null != a.pool && (b.pool = a.pool | 0);
  2840. null != a.idStr && (b.idStr = String(a.idStr));
  2841. return b
  2842. };
  2843. d.toObject = function (a, b) {
  2844. b || (b = {});
  2845. var c = {};
  2846. if (b.defaults) {
  2847. if (r.Long) {
  2848. var k = new r.Long(0, 0, !1);
  2849. c.id = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k
  2850. } else c.id = b.longs === String ? "0" : 0;
  2851. c.progress = 0;
  2852. c.mode = 0;
  2853. c.fontsize = 0;
  2854. c.color = 0;
  2855. c.midHash = "";
  2856. c.content = "";
  2857. r.Long ? (k = new r.Long(0, 0, !1), c.ctime = b.longs === String ? k.toString() : b.longs === Number ? k.toNumber() : k) : c.ctime = b.longs === String ? "0" : 0;
  2858. c.weight = 0;
  2859. c.action = "";
  2860. c.pool = 0;
  2861. c.idStr = ""
  2862. }
  2863. 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);
  2864. null != a.progress && a.hasOwnProperty("progress") && (c.progress = a.progress);
  2865. null != a.mode && a.hasOwnProperty("mode") && (c.mode = a.mode);
  2866. null != a.fontsize && a.hasOwnProperty("fontsize") && (c.fontsize = a.fontsize);
  2867. null != a.color && a.hasOwnProperty("color") && (c.color = a.color);
  2868. null != a.midHash && a.hasOwnProperty("midHash") && (c.midHash = a.midHash);
  2869. null != a.content && a.hasOwnProperty("content") && (c.content = a.content);
  2870. 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 >>> 0)).toNumber() : a.ctime);
  2871. null != a.weight && a.hasOwnProperty("weight") && (c.weight = a.weight);
  2872. null != a.action && a.hasOwnProperty("action") && (c.action = a.action);
  2873. null != a.pool && a.hasOwnProperty("pool") && (c.pool = a.pool);
  2874. null != a.idStr && a.hasOwnProperty("idStr") && (c.idStr = a.idStr);
  2875. return c
  2876. };
  2877. d.prototype.toJSON = function () {
  2878. return this.constructor.toObject(this, z.util.toJSONOptions)
  2879. };
  2880. return d
  2881. }();
  2882. return e
  2883. }();
  2884. return n
  2885. }();
  2886. return m
  2887. }();
  2888. return h
  2889. }();
  2890. return w
  2891. }();
  2892. return p
  2893. })(protobuf);
  2894. var proto_seg = protobuf.roots["default"].bilibili.community.service.dm.v1.DmSegMobileReply;
  2895.  
  2896. function htmlEscape(text, skipQuot) {
  2897. if (!text) return text
  2898. text = text.replace(/[\x00-\x08\x0b-\x0c\x0e-\x1f]/g, ' ')
  2899.  
  2900. function fn(match, pos, originalText) {
  2901. switch (match) {
  2902. case "<":
  2903. return "&lt;";
  2904. case ">":
  2905. return "&gt;";
  2906. case "&":
  2907. return "&amp;";
  2908. case "\"":
  2909. return '"';
  2910. }
  2911. }
  2912.  
  2913. if (!skipQuot) {
  2914. return text.replace(/[<>"&]/g, fn);
  2915. } else {
  2916. return text.replace(/[<>&]/g, fn);
  2917.  
  2918. }
  2919. }
  2920.  
  2921. function xmlunEscape(content) {
  2922. return content.replace(';', ';')
  2923. .replace(/&amp;/g, '&')
  2924. .replace(/&lt;/g, '<')
  2925. .replace(/&gt;/g, '>')
  2926. .replace(/&apos;/g, "'")
  2927. .replace(/&quot;/g, '"')
  2928. }
  2929.  
  2930. function xml2danmu(sdanmu, user = null) {
  2931. let ldanmu = sdanmu.split('</d><d p=');
  2932.  
  2933. if (ldanmu.length === 1) {
  2934. return []
  2935. }
  2936. let tdanmu = ldanmu[0];
  2937. ldanmu[0] = tdanmu.slice(tdanmu.indexOf('<d p=') + 5, tdanmu.length);
  2938. tdanmu = ldanmu[ldanmu.length - 1];
  2939. ldanmu[ldanmu.length - 1] = tdanmu.slice(0, tdanmu.length - 8);
  2940. for (let i = 0; i < ldanmu.length; i++) {
  2941. let danmu = ldanmu[i]
  2942. let argv = danmu.substring(1, danmu.indexOf('"', 2)).split(',')
  2943. ldanmu[i] = {
  2944. color: Number(argv[3]),
  2945. content: xmlunEscape(danmu.slice(danmu.indexOf('>') + 1, danmu.length)),
  2946. ctime: Number(argv[4]),
  2947. fontsize: Number(argv[2]),
  2948. id: Number(argv[7]),
  2949. idStr: argv[7],
  2950. midHash: argv[6],
  2951. mode: Number(argv[1]),
  2952. progress: Math.round(Number(argv[0]) * 1000),
  2953. weight: 10
  2954. }
  2955. }
  2956. return ldanmu
  2957. }
  2958.  
  2959. async function loadProtoDanmu(url, timeout = null, header = null, retry = 0) {
  2960. if (header === null) {
  2961. header = {
  2962. "referer": 'https://www.bilibili.com/bangumi/play/ep790784',
  2963. origin: 'https://www.bilibili.com',
  2964. 'sec-fetch-site': 'same-site'
  2965. }
  2966. }
  2967. while (true) {
  2968. try {
  2969. let result = await new Promise((resolve) => {
  2970. GM_xmlhttpRequest({
  2971. method: 'GET',
  2972. url: url,
  2973. responseType: 'arraybuffer',
  2974. headers: header,
  2975. timeout: timeout || 30000,
  2976. withCredentials: true,
  2977. onload: (response) => {
  2978. if (response.status === 200) {
  2979. let lpdanmu;
  2980. try {
  2981. lpdanmu = proto_seg.decode(new Uint8Array(response.response));
  2982. } catch (e) {
  2983. console.log('XhrError=', retry);
  2984. if (retry < 3) {
  2985. return resolve(loadProtoDanmu(url, timeout, header, retry + 1));
  2986. } else {
  2987. return resolve(null);
  2988. }
  2989. }
  2990. try {
  2991. lpdanmu.elems.forEach((e) => {
  2992. if (!e.progress) e.progress = 0;
  2993. });
  2994. resolve(lpdanmu.elems);
  2995. } catch (e) {
  2996. console.log(e.stack);
  2997. resolve([]);
  2998. }
  2999. } else if (response.status === 304) {
  3000. resolve([]);
  3001. } else {
  3002. console.log(response.status, response);
  3003. resolve(null);
  3004. }
  3005. },
  3006. onerror: (error) => {
  3007. console.log('XhrError=', retry);
  3008. retry += 1;
  3009. if (retry > 3) {
  3010. setTimeout(() => resolve(null), 10 * 1000);
  3011. } else {
  3012. setTimeout(() => resolve(null), retry * 2 * 1000);
  3013. }
  3014. },
  3015. });
  3016. });
  3017.  
  3018. if (result === null) {
  3019. retry += 1;
  3020. } else {
  3021. return result;
  3022. }
  3023. } catch (e) {
  3024. console.log('XhrError=', retry);
  3025. retry += 1;
  3026. }
  3027. await sleep(1000)
  3028. if (retry > 3) {
  3029. setTimeout(() => resolve(null), 10 * 1000);
  3030. } else {
  3031. setTimeout(() => resolve(null), retry * 2 * 1000);
  3032. }
  3033. }
  3034. }
  3035.  
  3036. function savedanmuStandalone(ldanmu, info = null) {
  3037. var end, head;
  3038. 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>"
  3039. end = "</i>";
  3040. if ((info !== null)) {
  3041. head += '<info>' + htmlEscape(JSON.stringify(info), true) + '</info>';
  3042. }
  3043. return head + ldanmu.join('') + end
  3044. }
  3045.  
  3046.  
  3047. function danmuObject2XML(ldanmu) {
  3048. for (let i = 0, length = ldanmu.length; i < length; i++) {
  3049. let danmu = ldanmu[i]
  3050. ldanmu[i] = `<d p="${(danmu.progress ? danmu.progress : 0) / 1000},${danmu.mode},${danmu.fontsize},${danmu.color},${danmu.ctime},${0},${danmu.midHash},${danmu.id}">${htmlEscape(danmu.content)}</d>`
  3051. }
  3052. return ldanmu
  3053. }
  3054.  
  3055.  
  3056. async function moreHistory(cid) {
  3057. let date = new Date();
  3058. if (videoPublishDate && currentSetting.capturePeriodEnd !== -1) {
  3059. date.setTime((videoPublishDate + currentSetting.capturePeriodEnd * 86400) * 1000)
  3060. } else {
  3061. date.setTime(date.getTime() - 86400000)
  3062. }
  3063. console.log('GetDanmuFor CID' + cid)
  3064. let aldanmu = [], ldanmu = []
  3065. let firstdate = 0;
  3066. let ndanmu, ondanmu
  3067. let url = 'https://comment.bilibili.com/' + cid + '.xml'
  3068. let sdanmu = await xhrGet(url)
  3069. ondanmu = ndanmu = Number(/<maxlimit>(.*?)</.exec(sdanmu)[1])
  3070. ldanmu = xml2danmu(sdanmu)
  3071. while (true) {
  3072. if (firstdate !== 0) {
  3073. await sleep(2000)
  3074. }
  3075. if (firstdate === 0 || ldanmu.length >= Math.min(ondanmu, 5000) * 0.5) {
  3076. let url = "https://api.bilibili.com/x/v2/dm/web/history/seg.so?type=1&date=" + dateObjectToDateStr(date) + "&oid=" + cid.toString();
  3077. console.log('ndanmu:', aldanmu.length, dateObjectToDateStr(date), url);
  3078. ldanmu = await loadProtoDanmu(url)
  3079. }
  3080. aldanmu = mergeDanmu(aldanmu, ldanmu)
  3081. document.title = aldanmu.length.toString()
  3082. toastText(dateObjectToDateStr(date) + '/' + aldanmu.length)
  3083. if (ldanmu.length < Math.min(ondanmu, 5000) * 0.5) {
  3084. return [aldanmu, ondanmu]
  3085. }
  3086. if (ldanmu.length >= Math.min(ondanmu, 5000) * 0.5) {
  3087. let tfirstdate = getMinDate(ldanmu)
  3088. if (firstdate !== 0 && firstdate - tfirstdate < 86400) tfirstdate = firstdate - 86400;
  3089. firstdate = tfirstdate;
  3090. date.setTime(firstdate * 1000);
  3091. }
  3092. if (videoPublishDate && currentSetting.capturePeriodStart !== 0) {
  3093. if (videoPublishDate + currentSetting.capturePeriodStart > date.getTime() / 1000) {
  3094. return [aldanmu, ondanmu]
  3095. }
  3096. }
  3097. }
  3098. }
  3099.  
  3100.  
  3101. function timestampToFullDateStr(timestamp) {
  3102. const date = new Date(timestamp * 1000); // Convert seconds to milliseconds
  3103. const year = date.getFullYear();
  3104. const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Month is zero-indexed
  3105. const day = date.getDate().toString().padStart(2, '0');
  3106. const hour = date.getHours().toString().padStart(2, '0');
  3107. const minute = date.getMinutes().toString().padStart(2, '0');
  3108. const second = date.getSeconds().toString().padStart(2, '0');
  3109.  
  3110. return `${year}-${month}-${day}-${hour}-${minute}-${second}`;
  3111. }
  3112.  
  3113.  
  3114. function dateObjectToDateStr(date) {
  3115. const year = date.getFullYear();
  3116. const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Month is zero-indexed
  3117. const day = date.getDate().toString().padStart(2, '0');
  3118.  
  3119. return `${year}-${month}-${day}`;
  3120. }
  3121.  
  3122.  
  3123. function getMinDate(ldanmu) {
  3124. let minDate = ldanmu[0].ctime
  3125. for (let danmu of ldanmu) {
  3126. if (minDate > danmu.ctime) {
  3127. minDate = danmu.ctime
  3128. }
  3129. }
  3130. return minDate
  3131. }
  3132.  
  3133. function mergeDanmu(oldanmu, nldanmu) {
  3134. if (oldanmu.idPool === undefined) {
  3135.  
  3136. let idPool = new Set()
  3137. for (let danmu of oldanmu) {
  3138. try {
  3139. idPool.add(danmu.progress * danmu.content.length * parseInt(danmu.midHash, 16))
  3140.  
  3141. } catch (e) {
  3142. console.log(danmu)
  3143. console.log(e)
  3144. throw e
  3145. }
  3146. }
  3147. oldanmu.idPool = idPool
  3148. }
  3149. try {
  3150. for (let danmu of nldanmu) {
  3151. let ida = (danmu.progress ? danmu.progress : 1) * danmu.content.length * parseInt(danmu.midHash, 16)
  3152. if (!oldanmu.idPool.has(ida)) {
  3153. oldanmu.push(danmu)
  3154. oldanmu.idPool.add(ida)
  3155. }
  3156. }
  3157. } catch (e) {
  3158. console.log()
  3159. }
  3160.  
  3161. return oldanmu
  3162. }
  3163.  
  3164. function poolSize2Duration(poolSize) {
  3165. let lPoolSize = [[0, 100], [30, 300], [60, 500], [180, 1000], [600, 1500], [900, 3000], [1500, 4000], [2400, 6000], [3600, 8000],]
  3166.  
  3167. for (let i = 0; i < lPoolSize.length; i += 1) {
  3168. if (poolSize === lPoolSize[i][1]) {
  3169. return lPoolSize[i][0]
  3170. }
  3171. }
  3172. }
  3173.  
  3174. async function allProtobufDanmu(cid, duration) {
  3175. toastText("实时弹幕:", cid)
  3176. let segIndex = 0, aldanmu = []
  3177. while (true) {
  3178. segIndex += 1
  3179. let tldanmu = await loadProtoDanmu('https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=' + cid + '&segment_index=' + segIndex)
  3180. mergeDanmu(aldanmu, tldanmu)
  3181. toastText(aldanmu.length)
  3182. if ((!duration || segIndex * 360 > duration) && (!tldanmu || tldanmu.length === 0)) {
  3183. break
  3184. }
  3185. await sleep(500)
  3186. }
  3187. toastText('下载完成')
  3188. return aldanmu
  3189. }
  3190.  
  3191. async function allProtobufDanmuXml(cid, title, ndanmu) {
  3192. let ldanmu = savedanmuStandalone(danmuObject2XML(await allProtobufDanmu(cid, poolSize2Duration(ndanmu))))
  3193. downloadFile(validateTitle(title) + '.xml', ldanmu)
  3194. }
  3195.  
  3196. async function downloadDanmaku(cid, info) {
  3197. toastText("全弹幕:" + cid)
  3198. if (currentSetting.capturePeriodStart !== 0 || currentSetting.capturePeriodEnd !== -1) {
  3199. toastText("下载时段:第" + currentSetting.capturePeriodStart + '-' + currentSetting.capturePeriodEnd + '天')
  3200. toastText(videoPublishDate ? "视频发布日期:" + dateObjectToDateStr(new Date(videoPublishDate * 1000)) : "未知日期:由弹幕判断")
  3201. }
  3202. let [ldanmu, ndanmu] = await moreHistory(cid)
  3203. if (ldanmu.length > ndanmu * 2 || ((currentSetting.capturePeriodStart !== 0 || currentSetting.capturePeriodEnd !== -1) && ldanmu.length > ndanmu * 0.8)) {
  3204. let sldanmu = await allProtobufDanmu(cid, poolSize2Duration(ndanmu))
  3205. mergeDanmu(ldanmu, sldanmu)
  3206. }
  3207. if (currentSetting.capturePeriodStart !== 0 || currentSetting.capturePeriodEnd !== -1) {
  3208. let publishDate = videoPublishDate || getMinDate(ldanmu)
  3209. let start = publishDate + currentSetting.capturePeriodStart * 86400 - 1
  3210. let end = currentSetting.capturePeriodEnd > 0 ? publishDate + currentSetting.capturePeriodEnd * 86400 : 1e12
  3211. console.log('before', ldanmu.length)
  3212. ldanmu = ldanmu.filter(danmu => {
  3213. return danmu.ctime > start && danmu.ctime < end
  3214. })
  3215. console.log('after', ldanmu.length)
  3216. }
  3217. if (!info) {
  3218. info = {}
  3219. }
  3220. info.cid = cid
  3221. info.ndanmu = ndanmu
  3222.  
  3223. toastText('下载完成')
  3224. return new DownloadResult(ldanmu, info)
  3225. }
  3226.  
  3227. class DownloadResult {
  3228. constructor(ldanmu, info) {
  3229. this.ldanmu = ldanmu
  3230. this.info = info
  3231. }
  3232.  
  3233. toXml() {
  3234. return savedanmuStandalone(danmuObject2XML(this.ldanmu), this.info)
  3235. }
  3236.  
  3237. dumpFile(title) {
  3238. downloadFile(validateTitle(title) + '.xml', this.toXml())
  3239. }
  3240.  
  3241. splitByTime(folder) {
  3242. this.ldanmu.sort((a, b) => {
  3243. return a.ctime - b.ctime
  3244. })
  3245.  
  3246. let i = 0
  3247. const chunkSize = 3000
  3248. while (i * chunkSize < this.ldanmu.length) {
  3249. let tldanmu = this.ldanmu.slice(i * chunkSize, (i + 1) * chunkSize)
  3250. let lastTs = tldanmu[tldanmu.length - 1].ctime
  3251. let fileName = timestampToFullDateStr(lastTs) + '_' + this.info.cid + '.xml'
  3252. folder.file(fileName, new DownloadResult(tldanmu, this.info).toXml())
  3253. i += 1
  3254. }
  3255. }
  3256. }
  3257.  
  3258. async function downloadDanmakuToZip(cid, folder, partTitle, partInfo, spiltFileFlag) {
  3259. let result = await downloadDanmaku(cid, '', partInfo)
  3260. if (!spiltFileFlag) {
  3261. let sdanmu = result.toXml()
  3262. await sleep(1);
  3263. folder.file(partTitle + '.xml', sdanmu)
  3264. await sleep(1);
  3265. } else {
  3266. let partFolder = folder.folder(partTitle)
  3267. result.splitByTime(partFolder)
  3268. }
  3269. }
  3270.  
  3271. async function concatDanmaku(videoInfo) {
  3272. let aldanmu = []
  3273.  
  3274. let posOffset = 0
  3275.  
  3276. for (let partInfo of videoInfo.list) {
  3277. let ldanmu = await allProtobufDanmu(partInfo.cid, partInfo.duration)
  3278. ldanmu.forEach((danmu) => {
  3279. danmu.progress = danmu.progress + posOffset * 1000
  3280. })
  3281. posOffset += partInfo.duration
  3282. aldanmu = aldanmu.concat(ldanmu)
  3283. }
  3284. let xml = savedanmuStandalone(danmuObject2XML(aldanmu), videoInfo)
  3285. downloadFile(`av${videoInfo.id} ${validateTitle(videoInfo.title)}.xml`, xml)
  3286. }
  3287.  
  3288. return [downloadDanmaku,
  3289.  
  3290. downloadDanmakuToZip,
  3291.  
  3292. allProtobufDanmuXml,
  3293. concatDanmaku]
  3294. })();
  3295.  
  3296. let downloadDanmakuVideo = (() => {
  3297.  
  3298. return async function (videoInfo) {
  3299. let zip = new JSZip();
  3300. let title
  3301. let aid
  3302. if (typeof videoInfo['aid'] === 'number') {
  3303. aid = videoInfo['aid']
  3304. title = 'av' + videoInfo['aid'] + ' ' + validateTitle(videoInfo['title'])
  3305. } else {
  3306. title = videoInfo['aid'] + ' ' + validateTitle(videoInfo['title'])
  3307. aid = Number(videoInfo['aid'].substring(2))
  3308. }
  3309. title = validateTitle(title)
  3310. console.log('title= ' + title)
  3311. let folder = zip.folder(title)
  3312. folder.file('videoInfo.json', JSON.stringify(videoInfo))
  3313. let i = 0
  3314.  
  3315. if (typeof videoInfo['aid'] === 'number' || videoInfo['aid'].startsWith('av')) {
  3316. try {
  3317. let pageList = JSON.parse(await xhrGet(`https://api.bilibili.com/x/player/pagelist?aid=${aid}&jsonp=jsonp`))
  3318. if (pageList.code === 0) {
  3319. for (let page of pageList['data']) {
  3320. let matched = false
  3321. for (let part of videoInfo['list']) {
  3322. if (part.cid === page.cid) {
  3323. part.duration = page.duration
  3324. matched = true
  3325. break
  3326. }
  3327. }
  3328. if (!matched) {
  3329. videoInfo['list'].push(page)
  3330. }
  3331. }
  3332. }
  3333. } catch (e) {
  3334. console.error(e, e.stack)
  3335. }
  3336. }
  3337.  
  3338.  
  3339. if (videoInfo.videoPublishDate) {
  3340. videoPublishDate = videoInfo.videoPublishDate
  3341. }
  3342.  
  3343. for (let partInfo of videoInfo['list']) {
  3344. i += 1
  3345. partInfo.title = partInfo.part
  3346. partInfo.aid = aid
  3347. let partTitle = getPartTitle(partInfo)
  3348. if (partInfo.videoPublishDate) {
  3349. videoPublishDate = partInfo.videoPublishDate
  3350. }
  3351. toastText(partTitle)
  3352. let progress = (i * 100 / videoInfo['list'].length).toFixed(2)
  3353. document.title = progress + ' %'
  3354. await downloadDanmakuToZip(partInfo.cid, folder, partTitle, partInfo, currentSetting['splitFileByTime'])
  3355. broadcastChannel.postMessage({
  3356. type: 'cidComplete', cid: partInfo.cid, aid: videoInfo.aid, progress: progress,
  3357. }, '*');
  3358. if (partInfo.videoPublishDate) {
  3359. videoPublishDate = null
  3360. }
  3361. }
  3362. let result = await zip.generateAsync({
  3363. type: "blob", compression: "DEFLATE", compressionOptions: {
  3364. level: 9
  3365. }
  3366. })
  3367. videoPublishDate = null
  3368. downloadFile(title + '.zip', result);
  3369. }
  3370. })()
  3371.  
  3372. let downloadedCid = []
  3373. let downloadedAid = []
  3374. let downloadingVideo = []
  3375. broadcastChannel.addEventListener('message', async (e) => {
  3376. if (e.data.type === 'biliplusDownloadDanmaku') {
  3377. if (e.data.history !== false) {
  3378. if (downloadedCid.indexOf(e.data.cid) !== -1) {
  3379. return
  3380. }
  3381. downloadedCid.push(e.data.cid);
  3382. (await downloadDanmaku(e.data.cid, e.data)).dumpFile(e.data.title)
  3383. } else {
  3384. await allProtobufDanmu(e.data.cid, e.data.title, e.data.ndanmu)
  3385. }
  3386. }
  3387. if (e.data.type === 'biliplusDownloadDanmakuVideo') {
  3388. if (downloadedAid.indexOf(e.data.videoInfo.aid) !== -1) {
  3389. broadcastChannel.postMessage({type: 'aidDownloaded', aid: e.data.videoInfo.aid}, '*');
  3390. return
  3391. }
  3392. downloadedAid.push(e.data.videoInfo.aid)
  3393. if (downloadingVideo.length === 0) {
  3394. downloadingVideo.push(e.data.videoInfo)
  3395. while (downloadingVideo.length !== 0) {
  3396. let videoInfo = downloadingVideo[0]
  3397. console.log('start', videoInfo.aid)
  3398. broadcastChannel.postMessage({type: 'aidStart', aid: videoInfo.aid}, '*');
  3399. await new Promise((resolve) => setTimeout(resolve, 1));
  3400. await downloadDanmakuVideo(videoInfo)
  3401. document.title = '下载完成'
  3402. broadcastChannel.postMessage({type: 'aidComplete', aid: videoInfo.aid}, '*');
  3403. await sleep(1000)
  3404. downloadingVideo = downloadingVideo.slice(1)
  3405. }
  3406. } else {
  3407. console.log('wait', e.data.videoInfo.aid)
  3408. downloadingVideo.push(e.data.videoInfo)
  3409. }
  3410.  
  3411. }
  3412. if (e.data.type === 'concatDanmaku') {
  3413. await concatDanmaku(e.data.videoInfo)
  3414. }
  3415. });
  3416. }
  3417.  
  3418. let currentSetting = panel()
  3419. client()
  3420. server()
  3421.  
  3422.  
  3423. })();