dpaaaa

dpaaaadpaaaa

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/489648/1341736/dpaaaa.js

  1. window.dpPlugins =
  2. window.dpPlugins ||
  3. (function (e) {
  4. var t = {
  5. version: "1.1.5",
  6. init: function (s, i) {
  7. (t = Object.assign(i || {}, t)),
  8. window.m3u8Parser ||
  9. t.loadJs(
  10. "https://cdn.staticfile.org/m3u8-parser/7.1.0/m3u8-parser.min.js"
  11. ),
  12. window.localforage ||
  13. t.loadJs(
  14. "https://cdn.staticfile.org/localforage/1.10.0/localforage.min.js"
  15. ),
  16. t.ready(s).then(() => {
  17. e.forEach((e) => {
  18. const i = new e(s, t);
  19. s.plugins[i.constructor.name] = i;
  20. });
  21. });
  22. },
  23. ready: function (e) {
  24. return new Promise(function (t, s) {
  25. e.isReady
  26. ? t()
  27. : e.video.duration > 0 || e.video.readyState > 2
  28. ? ((e.isReady = !0), t())
  29. : (e.video.ondurationchange = function () {
  30. (e.video.ondurationchange = null), (e.isReady = !0), t();
  31. });
  32. });
  33. },
  34. query: function (e, t = document) {
  35. return t.querySelector(e);
  36. },
  37. queryAll: function (e, t = document) {
  38. return t.querySelectorAll(e);
  39. },
  40. append: function (e, t) {
  41. return (
  42. t instanceof Element
  43. ? Node.prototype.appendChild.call(e, t)
  44. : e.insertAdjacentHTML("beforeend", String(t)),
  45. e.lastElementChild || e.lastChild
  46. );
  47. },
  48. prepend: function (e, t) {
  49. return (
  50. t instanceof Element
  51. ? Node.prototype.insertBefore.call(
  52. e,
  53. t,
  54. e.firstElementChild || e.firstChild
  55. )
  56. : e.insertAdjacentHTML("afterbegin", String(t)),
  57. e.firstElementChild || e.firstChild
  58. );
  59. },
  60. insertAfter: function (e, s) {
  61. var i = e.parentNode;
  62. return i.lastChild == e
  63. ? t.append(i, s)
  64. : ((s = t.append(i, s)),
  65. Node.prototype.insertBefore.call(i, s, e.nextSibling));
  66. },
  67. remove: function (e) {
  68. return Node.prototype.removeChild.call(e?.parentNode || document, e);
  69. },
  70. setStyle: function (e, t, s) {
  71. if ("object" == typeof t) {
  72. for (const s in t) e.style[s] = t[s];
  73. return e;
  74. }
  75. return (e.style[t] = s), e;
  76. },
  77. };
  78. return (
  79. console.info(
  80. "\n %c dpPlugins v" +
  81. t.version +
  82. " %c https://scriptcat.org/zh-CN/users/13895 \n",
  83. "color: #fadfa3; background: #030307; padding:5px 0;",
  84. "background: #fadfa3; padding:5px 0;"
  85. ),
  86. t
  87. );
  88. })([
  89. class HlsEvents {
  90. constructor(e) {
  91. (this.player = e),
  92. (this.hls = this.player.plugins.hls),
  93. (this.now = Date.now()),
  94. (this.currentTime = 0),
  95. (this.fragLoadError = 0),
  96. this.player.events.type("video_end") ||
  97. this.player.events.playerEvents.push("video_end"),
  98. this.player.on("video_end", () => {
  99. this.switchUrl();
  100. }),
  101. this.player.on("quality_end", () => {
  102. this.hls &&
  103. (this.hls.destroy(),
  104. (this.hls = this.player.plugins.hls),
  105. localStorage.setItem(
  106. "dplayer-defaultQuality",
  107. this.player.quality.name
  108. ),
  109. this.onEvents());
  110. }),
  111. this.player.on("destroy", () => {
  112. this.hls && this.hls.destroy();
  113. }),
  114. this.onEvents();
  115. }
  116. onEvents() {
  117. if (this.hls) {
  118. const e = window.Hls || unsafeWindow.Hls;
  119. this.hls.on(e.Events.ERROR, (t, s) => {
  120. if (
  121. (this.hls.media.currentTime > 0 &&
  122. (this.currentTime = this.hls.media.currentTime),
  123. s.fatal)
  124. )
  125. switch (
  126. (this.player.notice(
  127. `当前带宽: ${
  128. Math.round(
  129. (this.hls.bandwidthEstimate / 1024 / 1024 / 8) * 100
  130. ) / 100
  131. } MB/s`
  132. ),
  133. s.type)
  134. ) {
  135. case e.ErrorTypes.NETWORK_ERROR:
  136. s.details === e.ErrorDetails.MANIFEST_LOAD_ERROR ||
  137. s.details === e.ErrorDetails.MANIFEST_LOAD_TIMEOUT ||
  138. s.details === e.ErrorDetails.MANIFEST_PARSING_ERROR
  139. ? this.hls.loadSource(this.hls.url)
  140. : s.details === e.ErrorDetails.FRAG_LOAD_ERROR
  141. ? this.fragLoadError < 10 &&
  142. (this.fragLoadError++,
  143. this.hls.loadSource(this.hls.url),
  144. (this.hls.media.currentTime = this.currentTime),
  145. this.hls.media.play())
  146. : this.hls.startLoad();
  147. break;
  148. case e.ErrorTypes.MEDIA_ERROR:
  149. this.hls.recoverMediaError();
  150. break;
  151. default:
  152. this.player.notice("视频播放异常,请刷新重试"),
  153. this.hls.destroy();
  154. }
  155. else if (s.type === e.ErrorTypes.NETWORK_ERROR)
  156. if (
  157. s.details === e.ErrorDetails.FRAG_LOAD_ERROR &&
  158. this.isUrlExpires(this.hls.url)
  159. )
  160. return (
  161. (this.fragLoadError = 0),
  162. (this.now = Date.now()),
  163. this.hls.stopLoad(),
  164. this.player.plugins?.Appreciation.isAppreciation()
  165. .catch((e) =>
  166. Object.keys(localStorage).forEach(
  167. (e) => e.startsWith("dp") && localStorage.removeItem(e)
  168. )
  169. )
  170. .finally(() => {
  171. this.player.events.trigger("video_start");
  172. })
  173. );
  174. });
  175. }
  176. }
  177. switchUrl() {
  178. if (
  179. this.hls &&
  180. this.hls.hasOwnProperty("data") &&
  181. this.hls.levelController &&
  182. !this.hls.levelController.currentLevelIndex
  183. ) {
  184. const e = (this.hls.url = this.player.quality.url);
  185. fetch(e)
  186. .then((e) => (e.ok ? e.text() : Promise.reject()))
  187. .then((t) => {
  188. const s = new (
  189. window.m3u8Parser || unsafeWindow.m3u8Parser
  190. ).Parser();
  191. s.push(t), s.end();
  192. const i = e.replace(/media.m3u8.+/, ""),
  193. a = s.manifest.segments;
  194. this.hls.bufferController.details.fragments.forEach(function (
  195. t,
  196. s
  197. ) {
  198. const l = a[s];
  199. Object.assign(t, { baseurl: e, relurl: l.uri, url: i + l.uri });
  200. }),
  201. this.hls.startLoad(this.player.video.currentTime);
  202. });
  203. }
  204. }
  205. isUrlExpires(e) {
  206. var t =
  207. arguments.length > 1 && void 0 !== arguments[1]
  208. ? arguments[1]
  209. : 6e3,
  210. s = e.match(/&x-oss-expires=(\d+)&/);
  211. return s
  212. ? +"".concat(s[1], "000") - t < Date.now()
  213. : Date.now() - this.now > 3e5 - t;
  214. }
  215. },
  216. class ImageEnhancer {
  217. constructor(e, t) {
  218. (this.player = e),
  219. Object.assign(this.player.user.storageName, {
  220. imageenhancer: "dplayer-imageenhancer",
  221. }),
  222. Object.assign(this.player.user.default, { imageenhancer: 0 }),
  223. this.player.user.init(),
  224. (this.imageenhancer = this.player.user.get("imageenhancer")),
  225. this.imageenhancer &&
  226. (this.player.video.style.filter =
  227. "contrast(1.01) brightness(1.05) saturate(1.1)"),
  228. (this.player.template.imageEnhancer = t.append(
  229. t.query(
  230. ".dplayer-setting-origin-panel",
  231. this.player.template.settingBox
  232. ),
  233. '<div class="dplayer-setting-item dplayer-setting-imageenhancer"><span class="dplayer-label">画质增强</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  234. )),
  235. (this.player.template.imageEnhancerToggle = t.query(
  236. "input",
  237. this.player.template.imageEnhancer
  238. )),
  239. (this.player.template.imageEnhancerToggle.checked =
  240. this.imageenhancer),
  241. this.player.template.imageEnhancer.addEventListener("click", () => {
  242. (this.imageenhancer =
  243. this.player.template.imageEnhancerToggle.checked =
  244. !this.player.template.imageEnhancerToggle.checked),
  245. this.player.user.set("imageenhancer", Number(this.imageenhancer)),
  246. (this.player.video.style.filter = this.imageenhancer
  247. ? "contrast(1.01) brightness(1.05) saturate(1.1)"
  248. : ""),
  249. this.player.notice(
  250. "画质增强: " + (this.imageenhancer ? "开启" : "关闭")
  251. );
  252. }),
  253. this.player.on("playing", () => {
  254. this.imageenhancer &&
  255. (this.player.video.style.filter =
  256. "contrast(1.01) brightness(1.05) saturate(1.1)");
  257. });
  258. }
  259. },
  260. class SoundEnhancer {
  261. constructor(e, t) {
  262. (this.player = e),
  263. (this.Joysound = window.Joysound || unsafeWindow.Joysound),
  264. (this.localforage = window.localforage || unsafeWindow.localforage),
  265. (this.joySound = null),
  266. (this.offset = null),
  267. Object.assign(this.player.user.storageName, {
  268. soundenhancer: "dplayer-soundenhancer",
  269. volumeenhancer: "dplayer-volumeenhancer",
  270. }),
  271. Object.assign(this.player.user.default, {
  272. soundenhancer: 0,
  273. volumeenhancer: 0,
  274. }),
  275. this.player.user.init(),
  276. (this.player.template.soundEnhancer = t.append(
  277. t.query(
  278. ".dplayer-setting-origin-panel",
  279. this.player.template.settingBox
  280. ),
  281. '<div class="dplayer-setting-item dplayer-setting-soundenhancer"><span class="dplayer-label">音质增强</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  282. )),
  283. (this.player.template.soundEnhancerToggle = t.query(
  284. "input",
  285. this.player.template.soundEnhancer
  286. )),
  287. (this.player.template.soundEnhancerToggle.checked =
  288. !!this.player.user.get("soundenhancer")),
  289. this.player.template.soundEnhancer.addEventListener("click", () => {
  290. let e = (this.player.template.soundEnhancerToggle.checked =
  291. !this.player.template.soundEnhancerToggle.checked);
  292. this.player.user.set("soundenhancer", Number(e)),
  293. this.switchJoysound(e);
  294. }),
  295. (this.player.template.gainBox = t.prepend(
  296. t.query(
  297. ".dplayer-setting-origin-panel",
  298. this.player.template.settingBox
  299. ),
  300. '<div class="dplayer-setting-item dplayer-setting-danmaku dplayer-setting-gain" style="display: block;"><span class="dplayer-label">音量增强</span><div class="dplayer-danmaku-bar-wrap dplayer-gain-bar-wrap"><div class="dplayer-danmaku-bar dplayer-gain-bar"><div class="dplayer-danmaku-bar-inner dplayer-gain-bar-inner" style="width: 0%;"><span class="dplayer-thumb"></span></div></div></div></div>'
  301. )),
  302. (this.player.template.gainBarWrap =
  303. this.player.template.gainBox.querySelector(
  304. ".dplayer-gain-bar-wrap"
  305. )),
  306. (this.player.bar.elements.gain =
  307. this.player.template.gainBox.querySelector(
  308. ".dplayer-gain-bar-inner"
  309. ));
  310. const s = (e) => {
  311. const t = e || window.event;
  312. let s =
  313. ((t.clientX || t.changedTouches[0].clientX) -
  314. this.getElementViewLeft(this.player.template.gainBarWrap)) /
  315. 130;
  316. this.switchGainValue(s);
  317. },
  318. i = () => {
  319. document.removeEventListener("touchend", i),
  320. document.removeEventListener("touchmove", s),
  321. document.removeEventListener("mouseup", i),
  322. document.removeEventListener("mousemove", s),
  323. this.player.template.gainBox.classList.remove(
  324. "dplayer-setting-danmaku-active"
  325. );
  326. };
  327. this.player.template.gainBarWrap.addEventListener("click", (e) => {
  328. const t = e || window.event;
  329. let s =
  330. ((t.clientX || t.changedTouches[0].clientX) -
  331. this.getElementViewLeft(this.player.template.gainBarWrap)) /
  332. 130;
  333. this.switchGainValue(s);
  334. }),
  335. this.player.template.gainBarWrap.addEventListener(
  336. "touchstart",
  337. () => {
  338. document.addEventListener("touchmove", s),
  339. document.addEventListener("touchend", i),
  340. this.player.template.gainBox.classList.add(
  341. "dplayer-setting-danmaku-active"
  342. );
  343. }
  344. ),
  345. this.player.template.gainBarWrap.addEventListener("mousedown", () => {
  346. document.addEventListener("mousemove", s),
  347. document.addEventListener("mouseup", i),
  348. this.player.template.gainBox.classList.add(
  349. "dplayer-setting-danmaku-active"
  350. );
  351. }),
  352. this.player.on("playing", () => {
  353. this.localforage.getItem("playing").then((e) => {
  354. (e = e || 0),
  355. ++e < 1e3 &&
  356. ((this.player.plugins.hls.data = !0),
  357. this.localforage.setItem("playing", e));
  358. }),
  359. this.player.video.joySound || this.init();
  360. });
  361. }
  362. init() {
  363. if (this.Joysound && this.Joysound.isSupport()) {
  364. (this.joySound = new this.Joysound()),
  365. this.joySound.init(this.player.video),
  366. (this.player.video.joySound = !0);
  367. let e = this.player.user.get("soundenhancer");
  368. e && this.switchJoysound(e);
  369. let t = this.player.user.get("volumeenhancer");
  370. t && this.switchGainValue(t);
  371. }
  372. }
  373. switchJoysound(e) {
  374. this.joySound
  375. ? (this.joySound.setEnabled(e),
  376. this.player.notice("音质增强: " + (e ? "开启" : "关闭")))
  377. : this.player.notice("Joysound 未完成初始化");
  378. }
  379. switchGainValue(e) {
  380. this.joySound
  381. ? ((e = Math.min(Math.max(e, 0), 1)),
  382. this.player.bar.set("gain", e, "width"),
  383. this.player.user.set("volumeenhancer", e),
  384. this.joySound.setVolume(e),
  385. this.player.notice(`音量增强: ${100 + Math.floor(100 * e)}%`))
  386. : this.player.notice("Joysound 未完成初始化");
  387. }
  388. getElementViewLeft(e) {
  389. const t =
  390. window.scrollY ||
  391. window.pageYOffset ||
  392. document.body.scrollTop +
  393. ((document.documentElement && document.documentElement.scrollTop) ||
  394. 0);
  395. if (e.getBoundingClientRect) {
  396. if ("number" != typeof this.offset) {
  397. let e = document.createElement("div");
  398. (e.style.cssText = "position:absolute;top:0;left:0;"),
  399. document.body.appendChild(e),
  400. (this.offset = -e.getBoundingClientRect().top - t),
  401. document.body.removeChild(e),
  402. (e = null);
  403. }
  404. return e.getBoundingClientRect().left + this.offset;
  405. }
  406. {
  407. let t = e.offsetLeft,
  408. s = e.offsetParent;
  409. const i =
  410. document.body.scrollLeft + document.documentElement.scrollLeft;
  411. if (
  412. document.fullscreenElement ||
  413. document.mozFullScreenElement ||
  414. document.webkitFullscreenElement
  415. )
  416. for (; null !== s && s !== e; )
  417. (t += s.offsetLeft), (s = s.offsetParent);
  418. else for (; null !== s; ) (t += s.offsetLeft), (s = s.offsetParent);
  419. return t - i;
  420. }
  421. }
  422. },
  423. class AspectRatio {
  424. constructor(e) {
  425. (this.player = e),
  426. (this.value = null),
  427. this.player.template.controller
  428. .querySelector(".dplayer-icons-right")
  429. .insertAdjacentHTML(
  430. "afterbegin",
  431. '<div class="dplayer-quality dplayer-aspectRatio"><button class="dplayer-icon dplayer-quality-icon">画面比例</button><div class="dplayer-quality-mask"><div class="dplayer-quality-list dplayer-aspectRatio-list"><div class="dplayer-quality-item" data-value="none">原始比例</div><div class="dplayer-quality-item" data-value="cover">自动裁剪</div><div class="dplayer-quality-item" data-value="fill">拉伸填充</div><div class="dplayer-quality-item" data-value="">系统默认</div></div></div></div>'
  432. ),
  433. (this.player.template.aspectRatioButton =
  434. this.player.template.controller.querySelector(
  435. ".dplayer-aspectRatio button"
  436. )),
  437. (this.player.template.aspectRatioList =
  438. this.player.template.controller.querySelector(
  439. ".dplayer-aspectRatio-list"
  440. )),
  441. this.player.template.aspectRatioList.addEventListener(
  442. "click",
  443. (e) => {
  444. e.target.classList.contains("dplayer-quality-item") &&
  445. ((this.value = e.target.dataset.value),
  446. (this.player.video.style["object-fit"] =
  447. e.target.dataset.value),
  448. (this.player.template.aspectRatioButton.innerText =
  449. e.target.innerText));
  450. }
  451. ),
  452. this.player.on("playing", () => {
  453. this.value && (this.player.video.style["object-fit"] = this.value);
  454. });
  455. }
  456. },
  457. class SelectEpisode {
  458. constructor(e, t) {
  459. (this.player = e),
  460. Array.isArray(this.player.options.fileList) &&
  461. this.player.options.fileList.length > 1 &&
  462. this.player.options.file &&
  463. (this.player.events.type("episode_end") ||
  464. this.player.events.playerEvents.push("episode_end"),
  465. this.player.on("episode_end", () => {
  466. this.switchVideo();
  467. }),
  468. (this.player.fileIndex = (
  469. this.player.options.fileList || []
  470. ).findIndex(
  471. (e, t) => e.file_id === this.player.options.file.file_id
  472. )),
  473. t.prepend(
  474. this.player.template.controller.querySelector(
  475. ".dplayer-icons-right"
  476. ),
  477. '<style>.episode .content{max-width: 360px;max-height: 330px;width: auto;height: auto;box-sizing: border-box;overflow: hidden auto;position: absolute;left: 0px;transition: all 0.38s ease-in-out 0s;bottom: 52px;transform: scale(0);z-index: 2;}.episode .content .list{background-color: rgba(0,0,0,.3);height: 100%;}.episode .content .video-item{color: #fff;cursor: pointer;font-size: 14px;line-height: 35px;overflow: hidden;padding: 0 10px;text-overflow: ellipsis;text-align: center;white-space: nowrap;}.episode .content .active{background-color: rgba(0,0,0,.3);color: #0df;}</style><div class="dplayer-quality episode"><button class="dplayer-icon prev-icon" title="上一集"><svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M757.527273 190.138182L382.510545 490.123636a28.020364 28.020364 0 0 0 0 43.752728l375.016728 299.985454a28.020364 28.020364 0 0 0 45.474909-21.876363V212.014545a28.020364 28.020364 0 0 0-45.474909-21.876363zM249.949091 221.509818a28.020364 28.020364 0 0 0-27.973818 27.973818v525.032728a28.020364 28.020364 0 1 0 55.994182 0V249.483636a28.020364 28.020364 0 0 0-28.020364-27.973818zM747.054545 270.242909v483.514182L444.834909 512l302.173091-241.757091z"></path></svg></button><button class="dplayer-icon dplayer-quality-icon episode-icon">选集</button><button class="dplayer-icon next-icon" title="下一集"><svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M248.506182 190.138182l374.970182 299.985454a28.020364 28.020364 0 0 1 0 43.752728L248.552727 833.861818a28.020364 28.020364 0 0 1-45.521454-21.876363V212.014545c0-23.505455 27.182545-36.538182 45.521454-21.876363z m507.485091 31.371636c15.453091 0 28.020364 12.567273 28.020363 27.973818v525.032728a28.020364 28.020364 0 1 1-55.994181 0V249.483636c0-15.453091 12.520727-27.973818 27.973818-27.973818zM258.978909 270.242909v483.514182L561.198545 512 258.978909 270.242909z"></path></svg></button><div class="content"><div class="list"></div></div></div>'
  478. ),
  479. (this.player.template.episodeButton =
  480. this.player.template.controller.querySelector(
  481. ".episode .episode-icon"
  482. )),
  483. (this.player.template.episodePrevButton =
  484. this.player.template.controller.querySelector(
  485. ".episode .prev-icon"
  486. )),
  487. (this.player.template.episodeNextButton =
  488. this.player.template.controller.querySelector(
  489. ".episode .next-icon"
  490. )),
  491. (this.player.template.episodeContent =
  492. this.player.template.controller.querySelector(
  493. ".episode .content"
  494. )),
  495. (this.player.template.episodeList =
  496. this.player.template.controller.querySelector(".episode .list")),
  497. this.player.options.fileList.forEach((e, s) => {
  498. t.append(
  499. this.player.template.episodeList,
  500. '<div class="video-item" data-index="' +
  501. s +
  502. '" title="' +
  503. e.name +
  504. '">' +
  505. e.name +
  506. "</div>"
  507. );
  508. }),
  509. (this.player.template.episodeVideoItems =
  510. this.player.template.controller.querySelectorAll(
  511. ".episode .video-item"
  512. )),
  513. this.player.template.episodeVideoItems.length &&
  514. this.player.fileIndex >= 0 &&
  515. this.player.template.episodeVideoItems[
  516. this.player.fileIndex
  517. ].classList.add("active"),
  518. this.player.template.mask.addEventListener("click", () => {
  519. this.hide();
  520. }),
  521. this.player.template.episodeButton.addEventListener(
  522. "click",
  523. (e) => {
  524. "scale(1)" ===
  525. this.player.template.episodeContent.style.transform
  526. ? this.hide()
  527. : this.show();
  528. }
  529. ),
  530. this.player.template.episodeList.addEventListener("click", (e) => {
  531. e.target.classList.contains("video-item") &&
  532. !e.target.classList.contains("active") &&
  533. (this.player.template.episodeVideoItems[
  534. this.player.fileIndex
  535. ].classList.remove("active"),
  536. e.target.classList.add("active"),
  537. (this.player.fileIndex = 1 * e.target.dataset.index),
  538. (this.player.options.file =
  539. this.player.options.fileList[this.player.fileIndex]),
  540. this.hide(),
  541. this.player.events.trigger("episode_start"),
  542. this.player.notice(
  543. "准备播放:" + this.player.options.file.name,
  544. 5e3
  545. ));
  546. }),
  547. this.player.template.episodePrevButton.addEventListener(
  548. "click",
  549. (e) => {
  550. const t = this.player.fileIndex - 1;
  551. t >= 0
  552. ? (this.player.template.episodeVideoItems[
  553. this.player.fileIndex
  554. ].classList.remove("active"),
  555. this.player.template.episodeVideoItems[t].classList.add(
  556. "active"
  557. ),
  558. (this.player.fileIndex = t),
  559. (this.player.options.file =
  560. this.player.options.fileList[this.player.fileIndex]),
  561. this.hide(),
  562. this.player.events.trigger("episode_start"),
  563. this.player.notice(
  564. "准备播放:" + this.player.options.file.name,
  565. 5e3
  566. ))
  567. : this.player.notice("没有上一集了");
  568. }
  569. ),
  570. this.player.template.episodeNextButton.addEventListener(
  571. "click",
  572. (e) => {
  573. const t = this.player.fileIndex + 1;
  574. t <= this.player.options.fileList.length - 1
  575. ? (this.player.template.episodeVideoItems[
  576. this.player.fileIndex
  577. ].classList.remove("active"),
  578. this.player.template.episodeVideoItems[t].classList.add(
  579. "active"
  580. ),
  581. (this.player.fileIndex = t),
  582. (this.player.options.file =
  583. this.player.options.fileList[this.player.fileIndex]),
  584. this.hide(),
  585. this.player.events.trigger("episode_start"),
  586. this.player.notice(
  587. "准备播放:" + this.player.options.file.name,
  588. 5e3
  589. ))
  590. : this.player.notice("没有下一集了");
  591. }
  592. ));
  593. }
  594. switchVideo() {
  595. this.player.switchVideo({ url: this.player.quality.url, type: "hls" }),
  596. (this.player.video.oncanplay = () => {
  597. (this.player.video.oncanplay = null),
  598. this.player.play(),
  599. this.player.events.trigger("quality_end");
  600. });
  601. }
  602. show() {
  603. (this.player.template.episodeContent.style.transform = "scale(1)"),
  604. this.player.template.mask.classList.add("dplayer-mask-show");
  605. }
  606. hide() {
  607. (this.player.template.episodeContent.style.transform = "scale(0)"),
  608. this.player.template.mask.classList.remove("dplayer-mask-show");
  609. }
  610. },
  611. class AutoNextEpisode {
  612. constructor(e, t) {
  613. (this.player = e),
  614. Object.assign(this.player.user.storageName, {
  615. autonextepisode: "dplayer-autonextepisode",
  616. }),
  617. Object.assign(this.player.user.default, { autonextepisode: 0 }),
  618. this.player.user.init(),
  619. (this.autonextepisode = this.player.user.get("autonextepisode")),
  620. (this.player.template.autoNextEpisode = t.append(
  621. t.query(
  622. ".dplayer-setting-origin-panel",
  623. this.player.template.settingBox
  624. ),
  625. '<div class="dplayer-setting-item dplayer-setting-autonextepisode"><span class="dplayer-label">自动下一集</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  626. )),
  627. (this.player.template.autoNextEpisodeToggle = t.query(
  628. "input",
  629. this.player.template.autoNextEpisode
  630. )),
  631. (this.player.template.autoNextEpisodeToggle.checked =
  632. this.autonextepisode),
  633. this.player.template.autoNextEpisode.addEventListener("click", () => {
  634. (this.autonextepisode =
  635. this.player.template.autoNextEpisodeToggle.checked =
  636. !this.player.template.autoNextEpisodeToggle.checked),
  637. this.player.user.set(
  638. "autonextepisode",
  639. Number(this.autonextepisode)
  640. ),
  641. this.player.notice(
  642. "自动播放下集: " + (this.autonextepisode ? "开启" : "关闭")
  643. );
  644. }),
  645. this.player.on("ended", () => {
  646. this.autonextepisode &&
  647. this.player.template.episodeNextButton &&
  648. this.player.template.episodeNextButton.click();
  649. });
  650. }
  651. },
  652. class MemoryPlay {
  653. constructor(e, t) {
  654. (this.player = e),
  655. (this.file_id = this.player.options?.file?.file_id),
  656. (this.hasMemoryDisplay = !1),
  657. Object.assign(this.player.user.storageName, {
  658. automemoryplay: "dplayer-automemoryplay",
  659. }),
  660. Object.assign(this.player.user.default, { automemoryplay: 0 }),
  661. this.player.user.init(),
  662. (this.automemoryplay = this.player.user.get("automemoryplay")),
  663. (this.player.template.autoMemoryPlay = t.append(
  664. t.query(
  665. ".dplayer-setting-origin-panel",
  666. this.player.template.settingBox
  667. ),
  668. '<div class="dplayer-setting-item dplayer-setting-automemoryplay"><span class="dplayer-label">自动记忆播放</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  669. )),
  670. (this.player.template.autoMemoryPlayToggle = t.query(
  671. "input",
  672. this.player.template.autoMemoryPlay
  673. )),
  674. (this.player.template.autoMemoryPlayToggle.checked =
  675. this.automemoryplay),
  676. this.player.template.autoMemoryPlay.addEventListener("click", () => {
  677. (this.automemoryplay =
  678. this.player.template.autoMemoryPlayToggle.checked =
  679. !this.player.template.autoMemoryPlayToggle.checked),
  680. this.player.user.set(
  681. "automemoryplay",
  682. Number(this.automemoryplay)
  683. ),
  684. this.player.notice(
  685. "自动记忆播放: " + (this.automemoryplay ? "开启" : "关闭")
  686. );
  687. }),
  688. this.player.on("quality_end", () => {
  689. this.file_id !== this.player.options?.file?.file_id &&
  690. ((this.file_id = this.player.options?.file?.file_id),
  691. (this.hasMemoryDisplay = !1)),
  692. this.run();
  693. }),
  694. (document.onvisibilitychange = () => {
  695. if ("hidden" === document.visibilityState) {
  696. const {
  697. video: { currentTime: e, duration: t },
  698. } = this.player;
  699. this.setTime(this.file_id, e, t);
  700. }
  701. }),
  702. (window.onbeforeunload = () => {
  703. const {
  704. video: { currentTime: e, duration: t },
  705. } = this.player;
  706. this.setTime(this.file_id, e, t);
  707. }),
  708. this.run();
  709. }
  710. run() {
  711. if (!1 === this.hasMemoryDisplay) {
  712. this.hasMemoryDisplay = !0;
  713. const {
  714. video: { currentTime: e, duration: t },
  715. } = this.player,
  716. s = this.getTime(this.file_id);
  717. if (s && s > e)
  718. if (this.automemoryplay)
  719. this.player.seek(s),
  720. this.player.video.paused && this.player.play();
  721. else {
  722. const e = this.formatTime(s);
  723. let t = document.createElement("div");
  724. t.setAttribute("class", "memory-play-wrap"),
  725. t.setAttribute(
  726. "style",
  727. "display: block;position: absolute;left: 33px;bottom: 66px;font-size: 15px;padding: 7px;border-radius: 3px;color: #fff;z-index:100;background: rgba(0,0,0,.5);"
  728. ),
  729. (t.innerHTML =
  730. "上次播放到:" +
  731. e +
  732. '&nbsp;&nbsp;<a href="javascript:void(0);" class="play-jump" style="text-decoration: none;color: #06c;"> 跳转播放 &nbsp;</a><em class="close-btn" style="display: inline-block;width: 15px;height: 15px;vertical-align: middle;cursor: pointer;background: url(https://nd-static.bdstatic.com/m-static/disk-share/widget/pageModule/share-file-main/fileType/video/img/video-flash-closebtn_15f0e97.png) no-repeat;"></em>'),
  733. this.player.container.insertBefore(t, null);
  734. let i = setTimeout(() => {
  735. this.player.container.removeChild(t);
  736. }, 15e3);
  737. (t.querySelector(".close-btn").onclick = () => {
  738. this.player.container.removeChild(t), clearTimeout(i);
  739. }),
  740. (t.querySelector(".play-jump").onclick = () => {
  741. this.player.seek(s),
  742. this.player.container.removeChild(t),
  743. clearTimeout(i);
  744. });
  745. }
  746. }
  747. }
  748. getTime(e) {
  749. return localStorage.getItem("video_" + e) || 0;
  750. }
  751. setTime(e, t, s) {
  752. e &&
  753. t &&
  754. ((e = "video_" + e),
  755. t <= 60 || t + 120 >= s
  756. ? localStorage.removeItem(e)
  757. : localStorage.setItem(e, t));
  758. }
  759. formatTime(e) {
  760. var t = Math.round(e),
  761. s = Math.floor(t / 3600),
  762. i = Math.floor((t - 3600 * s) / 60),
  763. a = t - 3600 * s - 60 * i;
  764. return (
  765. i < 10 && (i = "0" + i),
  766. a < 10 && (a = "0" + a),
  767. 0 === s ? i + ":" + a : s + ":" + i + ":" + a
  768. );
  769. }
  770. },
  771. class SkipPosition {
  772. constructor(e, t) {
  773. (this.player = e),
  774. (this.file_id = this.player.options?.file?.file_id),
  775. (this.timer = null),
  776. Object.assign(this.player.user.storageName, {
  777. skipposition: "dplayer-skipposition",
  778. skipstarttime: "dplayer-skipstarttime",
  779. skipendtime: "dplayer-endtime",
  780. }),
  781. Object.assign(this.player.user.default, {
  782. skipposition: 0,
  783. skipstarttime: 0,
  784. skipendtime: 0,
  785. }),
  786. this.player.user.init(),
  787. (this.skipposition = this.player.user.get("skipposition")),
  788. (this.skipstarttime = this.player.user.get("skipstarttime")),
  789. (this.skipendtime = this.player.user.get("skipendtime")),
  790. (this.player.template.skipPosition = t.append(
  791. t.query(
  792. ".dplayer-setting-origin-panel",
  793. this.player.template.settingBox
  794. ),
  795. '<div class="dplayer-setting-item dplayer-setting-skipposition"><span class="dplayer-label">跳过片头片尾</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  796. )),
  797. (this.player.template.skipPositionToggle = t.query(
  798. "input",
  799. this.player.template.skipPosition
  800. )),
  801. (this.player.template.skipPositionToggle.checked = this.skipposition),
  802. (this.player.template.skipPositionBox = t.insertAfter(
  803. this.player.template.settingBox,
  804. '<div class="dplayer-setting-skipposition-item" style="display: none;right: 155px;position: absolute;bottom: 50px;width: 150px;border-radius: 2px;background: rgba(28, 28, 28, 0.9);padding: 7px 0px;transition: all 0.3s ease-in-out 0s;overflow: hidden;z-index: 2;"><div class="dplayer-skipposition-item" style="padding: 5px 10px;box-sizing: border-box;cursor: pointer;position: relative;"><span class="dplayer-skipposition-label" title="双击设置当前时间为跳过片头时间" style="color: #eee;font-size: 13px;display: inline-block;vertical-align: middle;white-space: nowrap;">片头时间:</span><input type="number" style="width: 55px;height: 15px;top: 3px;font-size: 13px;border: 1px solid #fff;border-radius: 3px;text-align: center;background-color: #fff;" step="1" min="0" value="60"></div><div class="dplayer-skipposition-item" style="padding: 5px 10px;box-sizing: border-box;cursor: pointer;position: relative;"><span class="dplayer-skipposition-label" title="双击设置剩余时间为跳过片尾时间" style="color: #eee;font-size: 13px;display: inline-block;vertical-align: middle;white-space: nowrap;">片尾时间:</span><input type="number" style="width: 55px;height: 15px;top: 3px;font-size: 13px;border: 1px solid #fff;border-radius: 3px;text-align: center;background-color: #fff;" step="1" min="0" value="120"></div></div>'
  805. )),
  806. (this.player.template.skipPositionItems = t.queryAll(
  807. ".dplayer-skipposition-item",
  808. this.player.template.skipPositionBox
  809. )),
  810. (this.player.template.jumpStartSpan = t.query(
  811. "span",
  812. this.player.template.skipPositionItems[0]
  813. )),
  814. (this.player.template.jumpStartInput = t.query(
  815. "input",
  816. this.player.template.skipPositionItems[0]
  817. )),
  818. (this.player.template.jumpEndSpan = t.query(
  819. "span",
  820. this.player.template.skipPositionItems[1]
  821. )),
  822. (this.player.template.jumpEndInput = t.query(
  823. "input",
  824. this.player.template.skipPositionItems[1]
  825. )),
  826. (this.player.template.jumpStartInput.value = this.skipstarttime),
  827. (this.player.template.jumpEndInput.value = this.skipendtime),
  828. this.player.template.jumpStartSpan.addEventListener(
  829. "dblclick",
  830. (e) => {
  831. (this.player.template.jumpStartInput.value =
  832. this.player.video.currentTime),
  833. (this.skipstarttime = this.player.video.currentTime);
  834. }
  835. ),
  836. this.player.template.jumpStartInput.addEventListener("input", (e) => {
  837. (this.skipstarttime = 1 * e.target.value),
  838. this.player.user.set("skipstarttime", this.skipstarttime);
  839. }),
  840. this.player.template.jumpEndSpan.addEventListener("dblclick", (e) => {
  841. (this.skipendtime =
  842. this.player.video.duration - this.player.video.currentTime),
  843. (this.player.template.jumpEndInput.value = this.skipendtime);
  844. }),
  845. this.player.template.jumpEndInput.addEventListener("input", (e) => {
  846. (this.skipendtime = 1 * e.target.value),
  847. this.player.user.set("skipendtime", this.skipendtime);
  848. }),
  849. this.player.template.skipPosition.addEventListener("click", () => {
  850. (this.skipposition =
  851. this.player.template.skipPositionToggle.checked =
  852. !this.player.template.skipPositionToggle.checked),
  853. this.player.user.set("skipposition", Number(this.skipposition)),
  854. this.skipposition ? this.show() : this.hide(),
  855. this.player.notice(
  856. "跳过片头片尾: " + (this.skipposition ? "开启" : "关闭")
  857. );
  858. }),
  859. this.player.template.skipPosition.addEventListener(
  860. "mouseenter",
  861. () => {
  862. this.skipposition && this.show();
  863. }
  864. ),
  865. this.player.template.mask.addEventListener("click", () => {
  866. this.hide();
  867. }),
  868. this.player.on("quality_end", () => {
  869. this.file_id !== this.player.options?.file?.file_id &&
  870. ((this.file_id = this.player.options?.file?.file_id),
  871. this.jumpStart(),
  872. this.jumpEnd());
  873. }),
  874. this.skipposition && (this.jumpStart(), this.jumpEnd());
  875. }
  876. jumpStart() {
  877. this.skipposition &&
  878. this.skipstarttime > this.player.video.currentTime &&
  879. (this.player.video.currentTime = this.skipstarttime);
  880. }
  881. jumpEnd() {
  882. this.timer ||
  883. (this.timer = setInterval(() => {
  884. this.skipposition &&
  885. this.skipendtime >=
  886. this.player.video.duration - this.player.video.currentTime &&
  887. ((this.player.video.currentTime = this.player.video.duration),
  888. clearInterval(this.timer),
  889. (this.timer = null));
  890. }, 3e3));
  891. }
  892. show() {
  893. this.player.template.skipPositionBox.style.display = "block";
  894. }
  895. hide() {
  896. this.player.template.skipPositionBox.style.display = "none";
  897. }
  898. },
  899. class Subtitle {
  900. constructor(e, t) {
  901. if (
  902. ((this.player = e),
  903. (this.offset = 0),
  904. (this.offsetStep = 1),
  905. (this.color = this.get("color") || "#fff"),
  906. (this.bottom = this.get("bottom") || "40px"),
  907. (this.fontSize = this.get("fontSize") || "20px"),
  908. Object.assign(this.player.user.storageName, {
  909. specialsubtitle: "dplayer-specialsubtitle",
  910. }),
  911. Object.assign(this.player.user.default, { specialsubtitle: 0 }),
  912. this.player.user.init(),
  913. (this.specialsubtitle = this.player.user.get("specialsubtitle")),
  914. this.specialsubtitle)
  915. )
  916. return;
  917. (this.player.template.subtitleSpecial = t.append(
  918. t.query(
  919. ".dplayer-setting-origin-panel",
  920. this.player.template.settingBox
  921. ),
  922. '<div class="dplayer-setting-item dplayer-setting-specialsubtitle"><span class="dplayer-label">特效字幕</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  923. )),
  924. (this.player.template.subtitleSpecialToggle = t.query(
  925. "input",
  926. this.player.template.subtitleSpecial
  927. )),
  928. (this.player.template.subtitleSpecialToggle.checked =
  929. this.specialsubtitle),
  930. this.player.template.subtitleSpecial.addEventListener("click", () => {
  931. (this.specialsubtitle =
  932. this.player.template.subtitleSpecialToggle.checked =
  933. !this.player.template.subtitleSpecialToggle.checked),
  934. this.player.user.set(
  935. "specialsubtitle",
  936. Number(this.specialsubtitle)
  937. ),
  938. this.player.notice(
  939. "特效字幕: " + (this.specialsubtitle ? "开启" : "关闭")
  940. ),
  941. this.specialsubtitle && location.reload();
  942. }),
  943. e.events.type("subtitle_end") ||
  944. e.events.playerEvents.push("subtitle_end"),
  945. e.on("subtitle_end", () => {
  946. this.add(this.player.options.subtitles);
  947. }),
  948. this.player.events.trigger("subtitle_start"),
  949. this.player.on("quality_end", () => {
  950. (this.player.template.subtitle.innerHTML = "<p></p>"),
  951. this.player.options.subtitle.url.length &&
  952. this.player.options.subtitles.length
  953. ? this.switch(
  954. this.player.options.subtitles[
  955. this.player.options.subtitle.index
  956. ]
  957. )
  958. : this.player.events.trigger("subtitle_start");
  959. }),
  960. this.player.on("episode_end", () => {
  961. this.clear(),
  962. this.style({
  963. color: this.color,
  964. bottom: this.bottom,
  965. fontSize: this.fontSize,
  966. });
  967. }),
  968. this.player.on("video_end", () => {
  969. this.style({
  970. color: this.color,
  971. bottom: this.bottom,
  972. fontSize: this.fontSize,
  973. });
  974. }),
  975. (this.player.template.subtitleSettingBox = t.append(
  976. this.player.template.controller,
  977. '<div class="dplayer-icons dplayer-comment-box subtitle-setting-box" style="bottom: 10px;left: auto;right: 400px !important;display: block;"><div class="dplayer-comment-setting-box"><div class="dplayer-comment-setting-color"><div class="dplayer-comment-setting-title">字幕颜色<button type="text" class="color-custom" style="line-height: 16px;font-size: 12px;top: 12px;right: 12px;color: #fff;background: rgba(28, 28, 28, 0.9);position: absolute;">自定义</button></div><label><input type="radio" name="dplayer-danmaku-color-1" value="#fff" checked=""><span style="background: #fff;"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#e54256"><span style="background: #e54256"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#ffe133"><span style="background: #ffe133"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#64DD17"><span style="background: #64DD17"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#39ccff"><span style="background: #39ccff"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#D500F9"><span style="background: #D500F9"></span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕位置</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>上移</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0" checked=""><span>默认</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>下移</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕大小</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>加大</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0"><span>默认</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>减小</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕偏移<div style="margin-top: -30px;right: 14px;position: absolute;">偏移量<input type="number" class="subtitle-offset-step" style="height: 14px;width: 50px;margin-left: 4px;border: 1px solid #fff;border-radius: 3px;color: #fff;background: rgba(28, 28, 28, 0.9);text-align: center;" value="1" step="1" min="1"></div></div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>前移</span></label><label><span><input type="text" class="subtitle-offset" style="width: 94%;height: 14px;background: rgba(28, 28, 28, 0.9);border: 0px solid #fff;text-align: center;" value="0" title="双击恢复默认"></span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>后移</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">更多字幕功能</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>本地字幕</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0"><span>待定</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>待定</span></label></div></div></div>'
  978. )),
  979. (this.player.template.subtitleCommentSettingBox = t.query(
  980. ".dplayer-comment-setting-box",
  981. this.player.template.subtitleSettingBox
  982. )),
  983. (this.player.template.subtitleSetting = t.append(
  984. t.query(
  985. ".dplayer-setting-origin-panel",
  986. this.player.template.settingBox
  987. ),
  988. '<div class="dplayer-setting-item dplayer-setting-subtitle"><span class="dplayer-label">字幕设置</span><div class="dplayer-toggle"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M22 16l-10.105-10.6-1.895 1.987 8.211 8.613-8.211 8.612 1.895 1.988 8.211-8.613z"></path></svg></div></div>'
  989. )),
  990. this.player.template.mask.addEventListener("click", () => {
  991. this.hide();
  992. }),
  993. this.player.template.subtitleSetting.addEventListener("click", () => {
  994. this.toggle();
  995. }),
  996. (this.player.template.subtitleColorPicker = t.append(
  997. this.player.template.container,
  998. '<input type="color" id="colorPicker">'
  999. )),
  1000. (this.player.template.subtitleColorCustom = t.query(
  1001. ".color-custom",
  1002. this.player.template.subtitleCommentSettingBox
  1003. )),
  1004. this.player.template.subtitleColorCustom.addEventListener(
  1005. "click",
  1006. () => {
  1007. this.player.template.subtitleColorPicker.click();
  1008. }
  1009. ),
  1010. this.player.template.subtitleColorPicker.addEventListener(
  1011. "input",
  1012. (e) => {
  1013. (this.color = e.target.value),
  1014. this.set("color", this.color),
  1015. this.style({ color: this.color });
  1016. }
  1017. ),
  1018. (this.player.template.subtitleSettingColor = t.query(
  1019. ".dplayer-comment-setting-color",
  1020. this.player.template.subtitleCommentSettingBox
  1021. )),
  1022. this.player.template.subtitleSettingColor.addEventListener(
  1023. "click",
  1024. (e) => {
  1025. "INPUT" === e.target.nodeName &&
  1026. ((this.color = e.target.value),
  1027. this.set("color", this.color),
  1028. this.style({ color: this.color }));
  1029. }
  1030. ),
  1031. (this.player.template.subtitleSettingItem = t.queryAll(
  1032. ".dplayer-comment-setting-type",
  1033. this.player.template.subtitleCommentSettingBox
  1034. )),
  1035. this.player.template.subtitleSettingItem[0].addEventListener(
  1036. "click",
  1037. (e) => {
  1038. "INPUT" === e.target.nodeName &&
  1039. ("1" == e.target.value
  1040. ? (this.bottom =
  1041. parseFloat(this.bottom) +
  1042. 1 +
  1043. this.bottom.replace(/[\d\.]+/, ""))
  1044. : "2" == e.target.value
  1045. ? (this.bottom =
  1046. parseFloat(this.bottom) -
  1047. 1 +
  1048. this.bottom.replace(/[\d\.]+/, ""))
  1049. : (this.bottom = "20px"),
  1050. this.set("bottom", this.bottom),
  1051. this.style({ bottom: this.bottom }));
  1052. }
  1053. ),
  1054. this.player.template.subtitleSettingItem[1].addEventListener(
  1055. "click",
  1056. (e) => {
  1057. "INPUT" === e.target.nodeName &&
  1058. ("1" == e.target.value
  1059. ? (this.fontSize =
  1060. parseFloat(this.fontSize) +
  1061. 1 +
  1062. this.fontSize.replace(/[\d\.]+/, ""))
  1063. : "2" == e.target.value
  1064. ? (this.fontSize =
  1065. parseFloat(this.fontSize) -
  1066. 1 +
  1067. this.fontSize.replace(/[\d\.]+/, ""))
  1068. : (this.fontSize = "40px"),
  1069. this.set("fontSize", this.fontSize),
  1070. this.style({ fontSize: this.fontSize }));
  1071. }
  1072. ),
  1073. (this.player.template.subtitleOffsetStep = t.query(
  1074. ".subtitle-offset-step",
  1075. this.player.template.subtitleSettingItem[2]
  1076. )),
  1077. this.player.template.subtitleOffsetStep.addEventListener(
  1078. "input",
  1079. (e) => {
  1080. this.offsetStep = 1 * e.target.value;
  1081. }
  1082. ),
  1083. (this.player.template.subtitleOffset = t.query(
  1084. ".subtitle-offset",
  1085. this.player.template.subtitleSettingItem[2]
  1086. )),
  1087. this.player.template.subtitleOffset.addEventListener("input", (e) => {
  1088. (this.offset = 1 * e.target.value), this.subtitleOffset();
  1089. }),
  1090. this.player.template.subtitleOffset.addEventListener(
  1091. "dblclick",
  1092. (e) => {
  1093. 0 != this.offset &&
  1094. ((this.offset = 0),
  1095. (e.target.value = 0),
  1096. this.subtitleOffset());
  1097. }
  1098. ),
  1099. this.player.template.subtitleSettingItem[2].addEventListener(
  1100. "click",
  1101. (e) => {
  1102. if ("INPUT" === e.target.nodeName && "radio" === e.target.type) {
  1103. let t = (this.player.template.subtitleOffset.value *= 1);
  1104. "1" == e.target.value
  1105. ? (t += this.offsetStep || 1)
  1106. : "2" == e.target.value
  1107. ? (t -= this.offsetStep || 1)
  1108. : (t = 0),
  1109. (this.offset = t),
  1110. (this.player.template.subtitleOffset.value = t),
  1111. this.subtitleOffset();
  1112. }
  1113. }
  1114. ),
  1115. (this.player.template.subtitleLocalFile = t.append(
  1116. this.player.template.container,
  1117. '<input class="subtitleLocalFile" type="file" accept="webvtt,.vtt,.srt,.ssa,.ass" style="display: none;">'
  1118. )),
  1119. this.player.template.subtitleSettingItem[3].addEventListener(
  1120. "click",
  1121. (e) => {
  1122. "INPUT" === e.target.nodeName &&
  1123. "1" == e.target.value &&
  1124. (this.player.template.subtitleLocalFile.click(), this.hide());
  1125. }
  1126. ),
  1127. this.player.template.subtitleLocalFile.addEventListener(
  1128. "change",
  1129. (e) => {
  1130. if (e.target.files.length) {
  1131. const t = e.target.files[0],
  1132. s = t.name.split(".").pop().toLowerCase();
  1133. this.blobToText(t).then((e) => {
  1134. let t = { url: "" };
  1135. (t.sarr = this.subParser(e, s)),
  1136. (t.lang = this.getlangBySarr(t.sarr)),
  1137. (t.name = t.name || this.langToLabel(t.lang)),
  1138. this.add([t]),
  1139. this.switch(t);
  1140. });
  1141. }
  1142. e.target.value = "";
  1143. }
  1144. );
  1145. const s = this.player.template.subtitlesItem.length - 1;
  1146. this.player.template.subtitlesItem[s].addEventListener("click", () => {
  1147. (this.player.options.subtitle.index = s),
  1148. (this.player.template.subtitle.innerHTML = "<p></p>"),
  1149. this.player.subtitles.subContainerHide();
  1150. }),
  1151. this.style({
  1152. color: this.color,
  1153. bottom: this.bottom,
  1154. fontSize: this.fontSize,
  1155. });
  1156. }
  1157. add(e) {
  1158. if (!Array.isArray(e) || !e.length) return;
  1159. if (
  1160. !this.player.template.subtitlesBox ||
  1161. !this.player.template.subtitlesItem.length
  1162. )
  1163. return;
  1164. const t = this.player.template.subtitlesItem.length - 1;
  1165. e.forEach((e, s) => {
  1166. const i = t + s;
  1167. this.player.options.subtitle.url.splice(i, 0, e);
  1168. let a = document.createElement("div");
  1169. a.setAttribute("class", "dplayer-subtitles-item"),
  1170. (a.innerHTML =
  1171. '<span class="dplayer-label">' +
  1172. e.name +
  1173. " " +
  1174. (e.language || e.lang || "") +
  1175. "</span>"),
  1176. this.player.template.subtitlesBox.insertBefore(
  1177. a,
  1178. this.player.template.subtitlesBox.childNodes[i]
  1179. ),
  1180. a.addEventListener("click", (t) => {
  1181. this.player.subtitles.hide(),
  1182. this.player.options.subtitle.index !== i + 1 &&
  1183. ((this.player.options.subtitle.index = i + 1),
  1184. (this.player.template.subtitle.innerHTML = "<p></p>"),
  1185. this.switch(e),
  1186. this.player.template.subtitle.classList.contains(
  1187. "dplayer-subtitle-hide"
  1188. ) && this.player.subtitles.subContainerShow());
  1189. });
  1190. }),
  1191. (this.player.template.subtitlesItem =
  1192. this.player.template.subtitlesBox.querySelectorAll(
  1193. ".dplayer-subtitles-item"
  1194. )),
  1195. (this.player.video.textTracks.length &&
  1196. this.player.video.textTracks[0]?.cues &&
  1197. this.player.video.textTracks[0].cues.length) ||
  1198. ((this.player.options.subtitle.index =
  1199. this.player.options.subtitles.findIndex((e) =>
  1200. ["cho", "chi"].includes(e.language)
  1201. )),
  1202. this.player.options.subtitle.index < 0 &&
  1203. (this.player.options.subtitle.index = 0),
  1204. this.switch(
  1205. this.player.options.subtitle.url[
  1206. this.player.options.subtitle.index
  1207. ]
  1208. ));
  1209. }
  1210. switch(e = {}) {
  1211. return this.initCues(e).then((t) => {
  1212. e.name;
  1213. });
  1214. }
  1215. restart() {
  1216. this.clear(), this.add(this.player.options.subtitles);
  1217. }
  1218. clear() {
  1219. (this.player.template.subtitle.innerHTML = "<p></p>"),
  1220. (this.player.options.subtitles = []),
  1221. (this.player.options.subtitle.url = []);
  1222. for (let e = this.player.template.subtitlesItem.length - 2; e >= 0; e--)
  1223. this.player.template.subtitlesBoxPanel.removeChild(
  1224. this.player.template.subtitlesItem[e]
  1225. );
  1226. this.player.template.subtitlesItem =
  1227. this.player.template.subtitlesBoxPanel.querySelectorAll(
  1228. ".dplayer-subtitles-item"
  1229. );
  1230. }
  1231. initCues(e) {
  1232. return this.urlToArray(e).then((e) => this.createTrack(e));
  1233. }
  1234. urlToArray(e) {
  1235. if (Array.isArray(e?.sarr) && e.sarr.length) return Promise.resolve(e);
  1236. {
  1237. const t = e?.url || e?.download_url || e?.uri || e?.surl,
  1238. s = e.sext || e.file_extension;
  1239. return t
  1240. ? this.requestFile(t).then(
  1241. (t) => (
  1242. (e.sarr = this.subParser(t, s, e.delay || 0)),
  1243. (e.lang = e.lang || this.getlangBySarr(e.sarr)),
  1244. (e.name = e.name || this.langToLabel(e.lang)),
  1245. e
  1246. )
  1247. )
  1248. : Promise.reject();
  1249. }
  1250. }
  1251. createTrack(e) {
  1252. const { video: t } = this.player,
  1253. s = t.textTracks[0];
  1254. if (
  1255. ("hidden" === s.mode || (s.mode = "hidden"), s.cues && s.cues.length)
  1256. )
  1257. for (let e = s.cues.length - 1; e >= 0; e--) s.removeCue(s.cues[e]);
  1258. e.sarr.forEach(function (e, t) {
  1259. const i = new VTTCue(e.startTime, e.endTime, e.text);
  1260. (i.id = e.index), s.addCue(i);
  1261. });
  1262. }
  1263. requestFile(e) {
  1264. return fetch(e, {
  1265. referrer: "https://www.aliyundrive.com/",
  1266. referrerPolicy: "origin",
  1267. body: null,
  1268. method: "GET",
  1269. mode: "cors",
  1270. credentials: "omit",
  1271. })
  1272. .then((e) => e.blob())
  1273. .then((e) => this.blobToText(e));
  1274. }
  1275. blobToText(e) {
  1276. return new Promise(function (t, s) {
  1277. var i = new FileReader();
  1278. i.readAsText(e, "UTF-8"),
  1279. (i.onload = function (s) {
  1280. var a = i.result;
  1281. return a.indexOf("�") > -1 && !i.markGBK
  1282. ? ((i.markGBK = !0), i.readAsText(e, "GBK"))
  1283. : a.indexOf("") > -1 && !i.markBIG5
  1284. ? ((i.markBIG5 = !0), i.readAsText(e, "BIG5"))
  1285. : void t(a);
  1286. }),
  1287. (i.onerror = function (e) {
  1288. s(e);
  1289. });
  1290. });
  1291. }
  1292. subParser(e, t, s = 0) {
  1293. t ||
  1294. (t = /\d\s?-?->\s?\d/.test(e)
  1295. ? "srt"
  1296. : /^\s*\[Script Info\]\r?\n/.test(e) && /\s*\[Events\]\r?\n/.test(e)
  1297. ? "ass"
  1298. : "");
  1299. var i,
  1300. a = [],
  1301. l = [];
  1302. switch (t) {
  1303. case "webvtt":
  1304. case "vtt":
  1305. case "srt":
  1306. (i =
  1307. /(\d+)?\n?(\d{0,2}:?\d{2}:\d{2}.\d{3})\s?-?->\s?(\d{0,2}:?\d{2}:\d{2}.\d{3})/g),
  1308. (a = (e = e.replace(/\r/g, "")).split(i)).shift();
  1309. for (let e = 0; e < a.length; e += 4)
  1310. l.push({
  1311. index: l.length,
  1312. startTime: r(a[e + 1]) + +s,
  1313. endTime: r(a[e + 2]) + +s,
  1314. text: a[e + 3]
  1315. .trim()
  1316. .replace(/(\\N|\\n)/g, "\n")
  1317. .replace(/{.*?}/g, "")
  1318. .replace(/[a-z]+\:.*\d+\.\d+\%\s/, ""),
  1319. });
  1320. return l;
  1321. case "ssa":
  1322. case "ass":
  1323. (i =
  1324. /Dialogue: .*?\d+,(\d+:\d{2}:\d{2}\.\d{2}),(\d+:\d{2}:\d{2}\.\d{2}),.*?,\d+,\d+,\d+,.*?,/g),
  1325. (a = (e = e.replace(/\r\n/g, "")).split(i)).shift();
  1326. for (let e = 0; e < a.length; e += 3)
  1327. l.push({
  1328. index: l.length,
  1329. startTime: r(a[e]) + +s,
  1330. endTime: r(a[e + 1]) + +s,
  1331. text: a[e + 2]
  1332. .trim()
  1333. .replace(/(\\N|\\n)/g, "\n")
  1334. .replace(/{.*?}/g, ""),
  1335. });
  1336. return l;
  1337. default:
  1338. return console.error("未知字幕格式,无法解析", e), l;
  1339. }
  1340. function r(e) {
  1341. var t = e.split(":"),
  1342. s =
  1343. parseFloat(
  1344. t.length > 0 ? t.pop().replace(/,/g, ".") : "00.000"
  1345. ) || 0,
  1346. i = parseFloat(t.length > 0 ? t.pop() : "00") || 0;
  1347. return (
  1348. 3600 * (parseFloat(t.length > 0 ? t.pop() : "00") || 0) + 60 * i + s
  1349. );
  1350. }
  1351. }
  1352. getlangBySarr(e) {
  1353. var t = [
  1354. e[parseInt(e.length / 3)].text,
  1355. e[parseInt(e.length / 2)].text,
  1356. e[parseInt((e.length / 3) * 2)].text,
  1357. ]
  1358. .join("")
  1359. .replace(/[<bi\/>\r?\n]*/g, ""),
  1360. s = "eng",
  1361. i = (t.match(/[\u4e00-\u9fa5]/g) || []).length / t.length;
  1362. return (
  1363. (
  1364. t.match(
  1365. /[\u3020-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u31F0-\u31FF]/g
  1366. ) || []
  1367. ).length /
  1368. t.length >
  1369. 0.03
  1370. ? (s = "jpn")
  1371. : i > 0.1 && (s = "zho"),
  1372. s
  1373. );
  1374. }
  1375. langToLabel(e) {
  1376. return (
  1377. {
  1378. chi: "中文字幕",
  1379. zho: "中文字幕",
  1380. eng: "英文字幕",
  1381. en: "英文字幕",
  1382. jpn: "日文字幕",
  1383. "zh-CN": "简体中文",
  1384. "zh-TW": "繁体中文",
  1385. }[e] || "未知语言"
  1386. );
  1387. }
  1388. subtitleOffset() {
  1389. const { video: e, subtitle: t, events: s } = this.player,
  1390. i = e.textTracks[0];
  1391. if (i && i.cues) {
  1392. const e = Array.from(i.cues),
  1393. t = this.player.options.subtitle.url.find(
  1394. (t) =>
  1395. t.sarr &&
  1396. t.sarr[parseInt(t.sarr.length / 2)].text ===
  1397. e[parseInt(e.length / 2)].text
  1398. )?.sarr;
  1399. if (!t) return;
  1400. for (let s = 0; s < e.length; s++) {
  1401. const i = e[s];
  1402. (i.startTime = t[s].startTime + this.offset),
  1403. (i.endTime = t[s].endTime + this.offset);
  1404. }
  1405. s.trigger("subtitle_change"),
  1406. this.player.notice(`字幕偏移: ${this.offset} 秒`);
  1407. } else this.offset = 0;
  1408. }
  1409. toggle() {
  1410. this.player.template.subtitleCommentSettingBox.classList.contains(
  1411. "dplayer-comment-setting-open"
  1412. )
  1413. ? this.hide()
  1414. : this.show();
  1415. }
  1416. show() {
  1417. this.player.template.subtitleCommentSettingBox.classList.add(
  1418. "dplayer-comment-setting-open"
  1419. ),
  1420. this.player.template.mask.classList.add("dplayer-mask-show");
  1421. }
  1422. hide() {
  1423. this.player.template.subtitleCommentSettingBox.classList.remove(
  1424. "dplayer-comment-setting-open"
  1425. ),
  1426. this.player.template.settingBox.classList.remove(
  1427. "dplayer-setting-box-open"
  1428. ),
  1429. this.player.template.mask.classList.remove("dplayer-mask-show");
  1430. }
  1431. get(e) {
  1432. return localStorage.getItem("dplayer-subtitle-" + e);
  1433. }
  1434. set(e, t) {
  1435. e && t && localStorage.setItem("dplayer-subtitle-" + e, t);
  1436. }
  1437. style(e, t) {
  1438. const { subtitle: s } = this.player.template;
  1439. if ("object" == typeof e) {
  1440. for (const t in e) s.style[t] = e[t];
  1441. return s;
  1442. }
  1443. return (s.style[e] = t), s;
  1444. }
  1445. },
  1446. class Libass {
  1447. constructor(e, t) {
  1448. (this.player = e),
  1449. (this.loadJs = t.loadJs),
  1450. (this.libass = null),
  1451. (this.fontData = null),
  1452. (this.hasSubtitleTrack = !1),
  1453. (this.hasSubtitleDisplay = !1),
  1454. (this.offset = 0),
  1455. (this.offsetStep = 1),
  1456. (this.color = -256),
  1457. (this.fontSize = 20),
  1458. (this.bottom = 10),
  1459. Object.assign(this.player.user.storageName, {
  1460. specialsubtitle: "dplayer-specialsubtitle",
  1461. }),
  1462. Object.assign(this.player.user.default, { specialsubtitle: 0 }),
  1463. this.player.user.init(),
  1464. (this.specialsubtitle = this.player.user.get("specialsubtitle")),
  1465. this.specialsubtitle &&
  1466. ((this.player.template.subtitleSpecial = t.append(
  1467. t.query(
  1468. ".dplayer-setting-origin-panel",
  1469. this.player.template.settingBox
  1470. ),
  1471. '<div class="dplayer-setting-item dplayer-setting-specialsubtitle"><span class="dplayer-label">特效字幕</span><div class="dplayer-toggle"><input class="dplayer-toggle-setting-input" type="checkbox" name="dplayer-toggle"><label for="dplayer-toggle"></label></div></div>'
  1472. )),
  1473. (this.player.template.subtitleSpecialToggle = t.query(
  1474. "input",
  1475. this.player.template.subtitleSpecial
  1476. )),
  1477. (this.player.template.subtitleSpecialToggle.checked =
  1478. this.specialsubtitle),
  1479. this.player.template.subtitleSpecial.addEventListener(
  1480. "click",
  1481. () => {
  1482. (this.specialsubtitle =
  1483. this.player.template.subtitleSpecialToggle.checked =
  1484. !this.player.template.subtitleSpecialToggle.checked),
  1485. this.player.user.set(
  1486. "specialsubtitle",
  1487. Number(this.specialsubtitle)
  1488. ),
  1489. this.player.notice(
  1490. "特效字幕: " + (this.specialsubtitle ? "开启" : "关闭")
  1491. ),
  1492. this.specialsubtitle || location.reload();
  1493. }
  1494. ),
  1495. this.player.events.type("subtitle_end") ||
  1496. e.events.playerEvents.push("subtitle_end"),
  1497. this.player.on("subtitle_end", () => {
  1498. this.add(this.player.options.subtitles);
  1499. }),
  1500. this.player.on("quality_end", () => {
  1501. this.setVideo(),
  1502. this.player.options.subtitle.url.length &&
  1503. this.player.options.subtitles.length
  1504. ? this.switch(
  1505. this.player.options.subtitles[
  1506. this.player.options.subtitle.index
  1507. ]
  1508. )
  1509. : this.hasSubtitleDisplay ||
  1510. ((this.hasSubtitleDisplay = !0),
  1511. this.player.events.trigger("subtitle_start"));
  1512. }),
  1513. this.player.on("episode_end", () => {
  1514. (this.hasSubtitleTrack = !1),
  1515. (this.hasSubtitleDisplay = !1),
  1516. this.clear();
  1517. }),
  1518. this.player.template.mask.addEventListener("click", () => {
  1519. this.hide();
  1520. }),
  1521. (this.player.template.subtitleSettingBox = t.append(
  1522. this.player.template.controller,
  1523. '<div class="dplayer-icons dplayer-comment-box subtitle-setting-box" style="bottom: 10px;left: auto;right: 400px !important;display: block;"><div class="dplayer-comment-setting-box"><div class="dplayer-comment-setting-color"><div class="dplayer-comment-setting-title">字幕颜色<button type="text" class="color-custom" style="line-height: 16px;font-size: 12px;top: 12px;right: 12px;color: #fff;background: rgba(28, 28, 28, 0.9);position: absolute;">自定义</button></div><label><input type="radio" name="dplayer-danmaku-color-1" value="#fff"><span style="background: #fff;"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#e54256"><span style="background: #e54256"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#ffe133"><span style="background: #ffe133"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#64DD17"><span style="background: #64DD17"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#39ccff"><span style="background: #39ccff"></span></label><label><input type="radio" name="dplayer-danmaku-color-1" value="#D500F9"><span style="background: #D500F9"></span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕位置</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>上移</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0"><span>默认</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>下移</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕大小</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>加大</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0"><span>默认</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>减小</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">字幕偏移<div style="margin-top: -30px;right: 14px;position: absolute;">偏移量<input type="number" class="subtitle-offset-step" style="height: 14px;width: 50px;margin-left: 4px;border: 1px solid #fff;border-radius: 3px;color: #fff;background: rgba(28, 28, 28, 0.9);text-align: center;" value="1" step="1" min="1"></div></div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>前移</span></label><label><span><input type="text" class="subtitle-offset" style="width: 94%;height: 14px;background: rgba(28, 28, 28, 0.9);border: 0px solid #fff;text-align: center;" value="0" title="双击恢复默认"></span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>后移</span></label></div><div class="dplayer-comment-setting-type"><div class="dplayer-comment-setting-title">更多字幕功能</div><label><input type="radio" name="dplayer-danmaku-type-1" value="1"><span>本地字幕</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="0"><span>待定</span></label><label><input type="radio" name="dplayer-danmaku-type-1" value="2"><span>待定</span></label></div></div></div>'
  1524. )),
  1525. (this.player.template.subtitleCommentSettingBox = t.query(
  1526. ".dplayer-comment-setting-box",
  1527. this.player.template.subtitleSettingBox
  1528. )),
  1529. (this.player.template.subtitleSetting = t.append(
  1530. t.query(
  1531. ".dplayer-setting-origin-panel",
  1532. this.player.template.settingBox
  1533. ),
  1534. '<div class="dplayer-setting-item dplayer-setting-subtitle"><span class="dplayer-label">字幕设置</span><div class="dplayer-toggle"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><path d="M22 16l-10.105-10.6-1.895 1.987 8.211 8.613-8.211 8.612 1.895 1.988 8.211-8.613z"></path></svg></div></div>'
  1535. )),
  1536. this.player.template.subtitleSetting.addEventListener(
  1537. "click",
  1538. () => {
  1539. this.toggle();
  1540. }
  1541. ),
  1542. (this.player.template.subtitleColorPicker = t.append(
  1543. this.player.template.container,
  1544. '<input type="color" id="colorPicker">'
  1545. )),
  1546. (this.player.template.subtitleColorCustom = t.query(
  1547. ".color-custom",
  1548. this.player.template.subtitleCommentSettingBox
  1549. )),
  1550. this.player.template.subtitleColorCustom.addEventListener(
  1551. "click",
  1552. () => {
  1553. (this.player.template.subtitleColorPicker.value = this.color),
  1554. this.player.template.subtitleColorPicker.click();
  1555. }
  1556. ),
  1557. this.player.template.subtitleColorPicker.addEventListener(
  1558. "input",
  1559. (e) => {
  1560. const t = e.target.value;
  1561. (this.color = this.fromQColor(t)),
  1562. this.player.notice(`设置字幕颜色: ${this.color}`),
  1563. this.setStyle({ PrimaryColour: this.color });
  1564. }
  1565. ),
  1566. (this.player.template.subtitleSettingColor = t.query(
  1567. ".dplayer-comment-setting-color",
  1568. this.player.template.subtitleCommentSettingBox
  1569. )),
  1570. this.player.template.subtitleSettingColor.addEventListener(
  1571. "click",
  1572. (e) => {
  1573. if ("INPUT" === e.target.nodeName) {
  1574. const t = e.target.value;
  1575. (this.color = this.fromQColor(t)),
  1576. this.player.notice(`设置字幕颜色: ${this.color}`),
  1577. this.setStyle({ PrimaryColour: this.color });
  1578. }
  1579. }
  1580. ),
  1581. (this.player.template.subtitleSettingItem = t.queryAll(
  1582. ".dplayer-comment-setting-type",
  1583. this.player.template.subtitleCommentSettingBox
  1584. )),
  1585. this.player.template.subtitleSettingItem[0].addEventListener(
  1586. "click",
  1587. (e) => {
  1588. "INPUT" === e.target.nodeName &&
  1589. ("1" == e.target.value
  1590. ? (this.bottom += 1)
  1591. : "2" == e.target.value
  1592. ? (this.bottom -= 1)
  1593. : (this.bottom = 10),
  1594. this.player.notice(`设置字幕位置: ${this.bottom}`),
  1595. this.setStyle({ MarginV: this.bottom }));
  1596. }
  1597. ),
  1598. this.player.template.subtitleSettingItem[1].addEventListener(
  1599. "click",
  1600. (e) => {
  1601. "INPUT" === e.target.nodeName &&
  1602. ("1" == e.target.value
  1603. ? (this.fontSize += 1)
  1604. : "2" == e.target.value
  1605. ? (this.fontSize -= 1)
  1606. : (this.fontSize = 20),
  1607. this.player.notice(`设置字幕大小: ${this.fontSize}`),
  1608. this.setStyle({ FontSize: this.fontSize }));
  1609. }
  1610. ),
  1611. (this.player.template.subtitleOffsetStep = t.query(
  1612. ".subtitle-offset-step",
  1613. this.player.template.subtitleSettingItem[2]
  1614. )),
  1615. this.player.template.subtitleOffsetStep.addEventListener(
  1616. "input",
  1617. (e) => {
  1618. this.offsetStep = 1 * e.target.value;
  1619. }
  1620. ),
  1621. (this.player.template.subtitleOffset = t.query(
  1622. ".subtitle-offset",
  1623. this.player.template.subtitleSettingItem[2]
  1624. )),
  1625. this.player.template.subtitleOffset.addEventListener(
  1626. "input",
  1627. (e) => {
  1628. (this.offset = 1 * e.target.value), this.subtitleOffset();
  1629. }
  1630. ),
  1631. this.player.template.subtitleOffset.addEventListener(
  1632. "dblclick",
  1633. (e) => {
  1634. 0 != this.offset &&
  1635. ((this.offset = 0),
  1636. (e.target.value = 0),
  1637. this.player.notice(`设置字幕偏移: ${this.offset}`),
  1638. this.timeOffset());
  1639. }
  1640. ),
  1641. this.player.template.subtitleSettingItem[2].addEventListener(
  1642. "click",
  1643. (e) => {
  1644. if (
  1645. "INPUT" === e.target.nodeName &&
  1646. "radio" === e.target.type
  1647. ) {
  1648. let t = (this.player.template.subtitleOffset.value *= 1);
  1649. "1" == e.target.value
  1650. ? (t += this.offsetStep || 1)
  1651. : "2" == e.target.value
  1652. ? (t -= this.offsetStep || 1)
  1653. : (t = 0),
  1654. (this.offset = t),
  1655. (this.player.template.subtitleOffset.value = t),
  1656. this.player.notice(`设置字幕偏移: ${this.offset}`),
  1657. this.timeOffset();
  1658. }
  1659. }
  1660. ),
  1661. (this.player.template.subtitleLocalFile = t.append(
  1662. this.player.template.container,
  1663. '<input class="subtitleLocalFile" type="file" accept="webvtt,.vtt,.srt,.ssa,.ass" style="display: none;">'
  1664. )),
  1665. this.player.template.subtitleSettingItem[3].addEventListener(
  1666. "click",
  1667. (e) => {
  1668. "INPUT" === e.target.nodeName &&
  1669. "1" == e.target.value &&
  1670. (this.player.template.subtitleLocalFile.click(), this.hide());
  1671. }
  1672. ),
  1673. this.player.template.subtitleLocalFile.addEventListener(
  1674. "change",
  1675. (e) => {
  1676. if (e.target.files.length) {
  1677. const t = e.target.files[0],
  1678. s = t.name.split(".").pop().toLowerCase();
  1679. this.blobToText(t).then((e) => {
  1680. let t = { stext: e, sext: s, name: "本地字幕" };
  1681. this.add([t]), this.switch(t);
  1682. });
  1683. }
  1684. e.target.value = "";
  1685. }
  1686. ),
  1687. this.player.events.trigger("subtitle_start"),
  1688. this.player.on("destroy", () => {
  1689. this.destroy();
  1690. }));
  1691. }
  1692. add(e) {
  1693. if (!Array.isArray(e) || !e.length) return;
  1694. if (
  1695. !this.player.template.subtitlesBox ||
  1696. !this.player.template.subtitlesItem.length
  1697. )
  1698. return;
  1699. this.player.template.subtitlesBoxPanel ||
  1700. (this.player.template.subtitlesBoxPanel =
  1701. this.player.template.subtitlesBox.querySelector(
  1702. ".dplayer-subtitles-panel"
  1703. ));
  1704. const t = this.player.template.subtitlesItem.length - 1;
  1705. if (
  1706. (e.forEach((e, s) => {
  1707. const i = t + s;
  1708. this.player.options.subtitle.url.splice(i, 0, e);
  1709. let a = document.createElement("div");
  1710. a.setAttribute("class", "dplayer-subtitles-item"),
  1711. (a.innerHTML =
  1712. '<span class="dplayer-label">' +
  1713. e.name +
  1714. " " +
  1715. (e.language || e.lang || "") +
  1716. "</span>"),
  1717. this.player.template.subtitlesBoxPanel.insertBefore(
  1718. a,
  1719. this.player.template.subtitlesBoxPanel.childNodes[i]
  1720. ),
  1721. a.addEventListener("click", (t) => {
  1722. this.player.subtitles.hide(),
  1723. this.player.options.subtitle.index !== i + 1 &&
  1724. ((this.player.options.subtitle.index = i + 1),
  1725. this.switch(e));
  1726. });
  1727. }),
  1728. (this.player.template.subtitlesItem =
  1729. this.player.template.subtitlesBoxPanel.querySelectorAll(
  1730. ".dplayer-subtitles-item"
  1731. )),
  1732. !this.hasSubtitleTrack)
  1733. ) {
  1734. (this.hasSubtitleTrack = !0),
  1735. this.player.template.subtitlesItem[
  1736. this.player.template.subtitlesItem.length - 1
  1737. ].addEventListener("click", (e) => {
  1738. this.subContainerHide();
  1739. });
  1740. let e = this.player.options.subtitles.findIndex((e) =>
  1741. ["cho", "zhi"].includes(e.language)
  1742. );
  1743. e < 0 && (e = 0),
  1744. this.init(this.player.options.subtitle.url[e]),
  1745. (this.player.options.subtitle.index = e + 1);
  1746. }
  1747. }
  1748. init(e) {
  1749. return this.initLibass()
  1750. .then(() =>
  1751. this.urlToText(e).then(
  1752. (e) => (
  1753. ["ass", "ssa"].includes(e.sext) ||
  1754. Object.assign(e, {
  1755. stext: this.toAss(e.stext, e.sext),
  1756. sext: "ass",
  1757. }),
  1758. this.switchContent(e.stext),
  1759. this.subContainerShow(),
  1760. e
  1761. )
  1762. )
  1763. )
  1764. .catch((e) => {
  1765. console.error("加载特效字幕组件 错误!", e);
  1766. });
  1767. }
  1768. switch(e = {}) {
  1769. return this.init(e).then(() => {
  1770. e.name && this.player.notice(`切换字幕: ${e.name}`);
  1771. });
  1772. }
  1773. clear() {
  1774. (this.player.options.subtitles = []),
  1775. (this.player.options.subtitle.url = []);
  1776. for (let e = this.player.template.subtitlesItem.length - 2; e >= 0; e--)
  1777. this.player.template.subtitlesBoxPanel.removeChild(
  1778. this.player.template.subtitlesItem[e]
  1779. );
  1780. (this.player.template.subtitlesItem =
  1781. this.player.template.subtitlesBoxPanel.querySelectorAll(
  1782. ".dplayer-subtitles-item"
  1783. )),
  1784. this.destroy();
  1785. }
  1786. toggle() {
  1787. this.player.template.subtitleCommentSettingBox.classList.contains(
  1788. "dplayer-comment-setting-open"
  1789. )
  1790. ? this.hide()
  1791. : this.show();
  1792. }
  1793. show() {
  1794. this.player.template.subtitleCommentSettingBox.classList.add(
  1795. "dplayer-comment-setting-open"
  1796. ),
  1797. this.player.template.mask.classList.add("dplayer-mask-show");
  1798. }
  1799. hide() {
  1800. this.player.template.subtitleCommentSettingBox.classList.remove(
  1801. "dplayer-comment-setting-open"
  1802. ),
  1803. this.player.template.settingBox.classList.remove(
  1804. "dplayer-setting-box-open"
  1805. ),
  1806. this.player.template.mask.classList.remove("dplayer-mask-show");
  1807. }
  1808. initLibass() {
  1809. if (this.libass) return Promise.resolve(this.libass);
  1810. const e = {
  1811. video: this.player.template.video,
  1812. subContent: "[Script Info]\nScriptType: v4.00+",
  1813. subUrl: "",
  1814. availableFonts: {
  1815. "思源黑体 cn bold":
  1816. "https://cdn.jsdelivr.net/gh/tampermonkeyStorage/Self-use@main/Fonts/SourceHanSansCN-Bold.woff2",
  1817. },
  1818. };
  1819. return this.getLocalFonts().then(
  1820. (t) => {
  1821. const s = t.filter((e) => e.fullName.match(/[\u4e00-\u9fa5]/)),
  1822. i =
  1823. s.find((e) => ["微软雅黑"].some((t) => e?.fullName === t))
  1824. ?.fullName || s.sort(() => 0.5 - Math.random())[0]?.fullName;
  1825. return (
  1826. Object.assign(e, { useLocalFonts: !0, fallbackFont: i }),
  1827. this.loadLibass(e)
  1828. );
  1829. },
  1830. () =>
  1831. this.getDbFonts().then((t) => {
  1832. (t || []).forEach(({ fullName: t, font: s }) => {
  1833. e.availableFonts[t] = s;
  1834. });
  1835. const s =
  1836. Object.keys(e.availableFonts).find((e) =>
  1837. ["思源黑体 cn bold"].some((t) => t === e)
  1838. ) ||
  1839. Object.keys(e.availableFonts)
  1840. .filter((e) => e.match(/[\u4e00-\u9fa5]/))
  1841. .filter(Boolean)
  1842. .sort(() => 0.5 - Math.random())[0];
  1843. return Object.assign(e, { fallbackFont: s }), this.loadLibass(e);
  1844. })
  1845. );
  1846. }
  1847. loadLibass(e) {
  1848. let t =
  1849. "https://registry.npmmirror.com/jassub/1.7.15/files/dist/jassub.umd.js";
  1850. return this.loadJs(t).then(
  1851. () => (
  1852. Object.assign(e, {
  1853. workerUrl: new URL("jassub-worker.js", t).href,
  1854. wasmUrl: new URL("jassub-worker.wasm", t).href,
  1855. legacyWorkerUrl: new URL("jassub-worker.wasm.js", t).href,
  1856. modernWasmUrl: new URL("jassub-worker-modern.wasm", t).href,
  1857. }),
  1858. this.loadWorker(e).then(
  1859. (t) => (
  1860. (e.workerUrl = t),
  1861. (this.libass = new unsafeWindow.JASSUB(e)),
  1862. this.libass
  1863. )
  1864. )
  1865. )
  1866. );
  1867. }
  1868. loadWorker({ workerUrl: e }) {
  1869. return fetch(e)
  1870. .then((e) => e.text())
  1871. .then((e) => {
  1872. const t = new Blob([e], { type: "text/javascript" }),
  1873. s = URL.createObjectURL(t);
  1874. return (
  1875. setTimeout(() => {
  1876. URL.revokeObjectURL(s);
  1877. }),
  1878. s
  1879. );
  1880. });
  1881. }
  1882. setVideo(e) {
  1883. this.libass && this.libass.setVideo(e || this.player.template.video);
  1884. }
  1885. switchContent(e) {
  1886. this.libass && e && (this.libass.freeTrack(), this.libass.setTrack(e));
  1887. }
  1888. subContainerShow() {
  1889. this.libass &&
  1890. (((
  1891. this.libass.canvasParent || this.libass._canvasParent
  1892. ).style.display = "block"),
  1893. this.libass.resize());
  1894. }
  1895. subContainerHide() {
  1896. this.libass &&
  1897. ((
  1898. this.libass.canvasParent || this.libass._canvasParent
  1899. ).style.display = "none");
  1900. }
  1901. timeOffset(e) {
  1902. this.libass && (this.libass.timeOffset = e || this.offset);
  1903. }
  1904. getStyles(e) {
  1905. this.libass
  1906. ? this.libass.getStyles((t, s) => {
  1907. e && e(s || t);
  1908. })
  1909. : e && e("");
  1910. }
  1911. setStyle(e, t = 1) {
  1912. this.libass && this.libass.setStyle(e, t);
  1913. }
  1914. destroy() {
  1915. this.libass &&
  1916. (this.libass.destroy && this.libass.destroy(),
  1917. this.libass.dispose && this.libass.dispose(),
  1918. (this.libass = null));
  1919. }
  1920. getLocalFonts(e) {
  1921. if (unsafeWindow.queryLocalFonts) {
  1922. const t = {};
  1923. return (
  1924. e && (t.postscriptNames = Array.isArray(e) ? e : [e]),
  1925. unsafeWindow
  1926. .queryLocalFonts(t)
  1927. .then((e) => (e && e.length ? e : Promise.reject()))
  1928. );
  1929. }
  1930. return console.warn("Not Local fonts API"), Promise.reject();
  1931. }
  1932. getDbFonts(e) {
  1933. const t = window.localforage || unsafeWindow.localforage;
  1934. return t.getItem("local-fonts").then((s) => {
  1935. if (Array.isArray(s) && s.length)
  1936. return Array.isArray(e)
  1937. ? s.filter(({ fullName: t }) => e.some((e) => e === t))
  1938. : s;
  1939. let i = [
  1940. {
  1941. fullName: "思源黑体 cn bold",
  1942. url: "https://cdn.jsdelivr.net/gh/tampermonkeyStorage/Self-use@main/Fonts/SourceHanSansCN-Bold.woff2",
  1943. },
  1944. ];
  1945. Array.isArray(e) &&
  1946. (i = i.filter(({ fullName: t }) => e.some((e) => e === t)));
  1947. const a = [];
  1948. return (
  1949. i.forEach(({ url: e }) => {
  1950. e &&
  1951. a.push(
  1952. fetch(e).then((e) =>
  1953. e.ok ? e.arrayBuffer() : Promise.reject()
  1954. )
  1955. );
  1956. }),
  1957. Promise.allSettled(a).then(
  1958. (e) => (
  1959. e.forEach(({ status: e, value: t }, s) => {
  1960. "fulfilled" == e &&
  1961. t?.byteLength &&
  1962. Object.assign(i[s], { font: new Uint8Array(t) });
  1963. }),
  1964. t.setItem(
  1965. "local-fonts",
  1966. (s || []).concat(i.filter(({ font: e }) => e))
  1967. )
  1968. )
  1969. )
  1970. );
  1971. });
  1972. }
  1973. toAss(e, t) {
  1974. const s = "ass" === t || "ssa" === t ? e : "";
  1975. if (s) return s;
  1976. const i =
  1977. /(?:\d+\n)?(\d{0,2}:?\d{2}:\d{2}.\d{3})\s?-?->\s?(\d{0,2}:?\d{2}:\d{2}.\d{3})(.*)\n([\s\S]*)$/i,
  1978. a = (e) => {
  1979. const t = [],
  1980. s = e.replace(/\r/g, ""),
  1981. a = /(\d{0,2})?:?(\d{2}):(\d{2}.\d{3})/;
  1982. for (const e of s.split("\n\n")) {
  1983. const s = e.match(i);
  1984. if (s) {
  1985. (s[1] = s[1].replace(
  1986. a,
  1987. (e, t, s, i) =>
  1988. (t || "0") +
  1989. ":" +
  1990. s +
  1991. ":" +
  1992. i.match(/\d{2}.\d{2}/)[0].replace(",", ".")
  1993. )),
  1994. (s[2] = s[2].replace(
  1995. a,
  1996. (e, t, s, i) =>
  1997. (t || "0") +
  1998. ":" +
  1999. s +
  2000. ":" +
  2001. i.match(/\d{2}.\d{2}/)[0].replace(",", ".")
  2002. ));
  2003. const e = s[4].match(/<[^>]+>/g);
  2004. e &&
  2005. e.forEach((e) => {
  2006. /<\//.test(e)
  2007. ? (s[4] = s[4].replace(
  2008. e,
  2009. e.replace("</", "{\\").replace(">", "0}")
  2010. ))
  2011. : (s[4] = s[4].replace(
  2012. e,
  2013. e.replace("<", "{\\").replace(">", "1}")
  2014. ));
  2015. }),
  2016. t.push(
  2017. "Dialogue: 0," +
  2018. s[1] +
  2019. "," +
  2020. s[2] +
  2021. ",Default,,0,0,0,," +
  2022. s[4].replace(/\n/g, "\\N")
  2023. );
  2024. }
  2025. }
  2026. return t.join("\n");
  2027. },
  2028. l = {
  2029. scriptInfo: {
  2030. Title: "untitled",
  2031. ScriptType: "v4.00+",
  2032. Collisions: "Normal",
  2033. PlayDepth: 0,
  2034. Timer: "100,0000",
  2035. PlayResX: "",
  2036. PlayResY: "",
  2037. WrapStyle: 0,
  2038. ScaledBorderAndShadow: "no",
  2039. },
  2040. v4Styles: [
  2041. {
  2042. Name: "Default",
  2043. Fontname: "Default",
  2044. Fontsize: 20,
  2045. PrimaryColour: "&H00FFFFFF",
  2046. SecondaryColour: "&H00FFFFFF",
  2047. OutlineColour: "&H00000000",
  2048. BackColour: "&H00000000",
  2049. Bold: -1,
  2050. Italic: 0,
  2051. Underline: 0,
  2052. StrikeOut: 0,
  2053. ScaleX: 100,
  2054. ScaleY: 100,
  2055. Spacing: 0,
  2056. Angle: 0,
  2057. BorderStyle: 1,
  2058. Outline: 1,
  2059. Shadow: 0,
  2060. Alignment: 2,
  2061. MarginL: 10,
  2062. MarginR: 10,
  2063. MarginV: 10,
  2064. Encoding: 1,
  2065. },
  2066. ],
  2067. },
  2068. r = ["[Script Info]"];
  2069. for (let [e, t] of Object.entries(l.scriptInfo)) r.push(e + ": " + t);
  2070. r.push(""),
  2071. r.push("[V4+ Styles]"),
  2072. r.push(
  2073. "Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding"
  2074. ),
  2075. l.v4Styles.forEach((e) => {
  2076. "object" == typeof e
  2077. ? r.push("Style: " + Object.values(e).join(","))
  2078. : "string" == typeof e && r.push(e);
  2079. }),
  2080. r.push(""),
  2081. r.push("[Events]"),
  2082. r.push(
  2083. "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
  2084. ),
  2085. r.push("");
  2086. const n = r.join("\n");
  2087. switch (t) {
  2088. case "vtt":
  2089. case "srt":
  2090. return n + a(e);
  2091. case "ssa":
  2092. case "ass":
  2093. return s;
  2094. default:
  2095. return i.test(e) ? n + a(e) : "";
  2096. }
  2097. }
  2098. urlToText(e) {
  2099. if (e.stext) return Promise.resolve(e);
  2100. {
  2101. e.sext || (e.sext = e.file_extension);
  2102. const t = e.url || e.download_url || e.uri || e.surl;
  2103. return this.requestFile(t).then((t) => ((e.stext = t), e));
  2104. }
  2105. }
  2106. requestFile(e) {
  2107. return fetch(e, {
  2108. referrer: location.protocol + "//" + location.host + "/",
  2109. referrerPolicy: "origin",
  2110. body: null,
  2111. method: "GET",
  2112. mode: "cors",
  2113. credentials: "omit",
  2114. })
  2115. .then((e) => e.blob())
  2116. .then((e) => this.blobToText(e));
  2117. }
  2118. blobToText(e) {
  2119. return new Promise(function (t, s) {
  2120. var i = new FileReader();
  2121. i.readAsText(e, "UTF-8"),
  2122. (i.onload = function (s) {
  2123. var a = i.result;
  2124. return a.indexOf("�") > -1 && !i.markGBK
  2125. ? ((i.markGBK = !0), i.readAsText(e, "GBK"))
  2126. : a.indexOf("") > -1 && !i.markBIG5
  2127. ? ((i.markBIG5 = !0), i.readAsText(e, "BIG5"))
  2128. : void t(a);
  2129. }),
  2130. (i.onerror = function (e) {
  2131. s(e);
  2132. });
  2133. });
  2134. }
  2135. fromQColor(e, t = !1) {
  2136. e = e.replace(
  2137. /^#?([a-f\d])([a-f\d])([a-f\d])$/i,
  2138. (e, t, s, i) => t + t + s + s + i + i
  2139. );
  2140. const [s, i, a, l] = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
  2141. e
  2142. );
  2143. return t
  2144. ? (((-1 + i) & 255) << 24) |
  2145. (((-1 + a) & 255) << 16) |
  2146. (((-1 + l) & 255) << 8) |
  2147. 0
  2148. : (("0x" + i) << 24) | (("0x" + a) << 16) | (("0x" + l) << 8) | 0;
  2149. }
  2150. },
  2151. class Appreciation {
  2152. constructor(e, t) {
  2153. (this.player = e),
  2154. (this.now = Date.now()),
  2155. (this.localforage = window.localforage || unsafeWindow.localforage);
  2156. const {
  2157. contextmenu: s,
  2158. container: { offsetWidth: i, offsetHeight: a },
  2159. } = this.player;
  2160. this.player.template.menuItem[0].addEventListener("click", () => {
  2161. this.showDialog();
  2162. }),
  2163. this.player.on("timeupdate", () => {
  2164. Date.now() - 24e4 >= this.now &&
  2165. ((this.now = Date.now()),
  2166. this.isAppreciation()
  2167. .then((e) => {
  2168. this.player.plugins.hls.data = !!e;
  2169. })
  2170. .catch((e) => {
  2171. this.player.pause(),
  2172. s.show(i / 2.5, a / 3),
  2173. (s.shown = !0),
  2174. !this.player.plugins.hls.data &&
  2175. confirm("请赞赏后继续观赏") &&
  2176. ((this.player.plugins.hls.data = !0), this.showDialog()),
  2177. (this.player.plugins.hls.error = !!e);
  2178. }));
  2179. }),
  2180. this.player.template.settingBox.addEventListener("click", (e) => {
  2181. this.isAppreciation().catch((t) => {
  2182. let s =
  2183. e.target.querySelector("input") ||
  2184. e.target.parentNode.querySelector("input");
  2185. s && s.checked && e.target.click(),
  2186. this.player.template.mask.click(),
  2187. e.isTrusted && this.showDialog();
  2188. });
  2189. });
  2190. }
  2191. isAppreciation() {
  2192. return (
  2193. (this.player.template.menuItem =
  2194. this.player.container.querySelectorAll(".dplayer-menu-item")),
  2195. this.player.template.menu.innerHTML.includes(5254001) ||
  2196. 4 === this.player.template.menuItem.length ||
  2197. this.player.destroy(),
  2198. this.localforage || this.player.destroy(),
  2199. GM_getValue || GM_setValue || GM_deleteValue || this.player.destroy(),
  2200. this.localforage
  2201. .getItem("users")
  2202. .then((e) =>
  2203. e?.expire_time
  2204. ? this.localforage
  2205. .getItem("users_sign")
  2206. .then((t) =>
  2207. Math.max(Date.parse(e.expire_time) - Date.now(), 0) &&
  2208. t === btoa(encodeURIComponent(JSON.stringify(e))) &&
  2209. GM_getValue("users_sign") ===
  2210. btoa(encodeURIComponent(JSON.stringify(e)))
  2211. ? e
  2212. : this.usersPost().then((e) =>
  2213. Math.max(Date.parse(e?.expire_time) - Date.now(), 0)
  2214. ? this.localforage
  2215. .setItem("users", e)
  2216. .then(
  2217. (e) => (
  2218. this.localforage.setItem(
  2219. "users_sign",
  2220. btoa(
  2221. encodeURIComponent(JSON.stringify(e))
  2222. )
  2223. ),
  2224. GM_setValue(
  2225. "users_sign",
  2226. btoa(
  2227. encodeURIComponent(JSON.stringify(e))
  2228. )
  2229. ),
  2230. e
  2231. )
  2232. )
  2233. : (this.localforage.removeItem("users"),
  2234. this.localforage.removeItem("users_sign"),
  2235. GM_deleteValue("users_sign"),
  2236. Promise.reject())
  2237. )
  2238. )
  2239. : GM_getValue("users_sign")
  2240. ? this.localforage
  2241. .setItem("users", { expire_time: new Date().toISOString() })
  2242. .then(() => this.isAppreciation())
  2243. : (GM_setValue("users_sign", 0), Promise.reject())
  2244. )
  2245. );
  2246. }
  2247. showDialog() {
  2248. let e = document.createElement("div");
  2249. (e.innerHTML =
  2250. '<div class="ant-modal-mask"></div><div tabindex="-1" class="ant-modal-wrap" role="dialog" aria-labelledby="rcDialogTitle1" style=""><div role="document" class="ant-modal modal-wrapper--5SA7y" style="width: 340px;"><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden; outline: none;"></div><div class="ant-modal-content"><div class="ant-modal-header"><div class="ant-modal-title" id="rcDialogTitle1">请少量赞助以支持我更好的创作</div></div><div class="ant-modal-body"><div class="content-wrapper--S6SNu"><div>爱发电订单号:</div><span class="ant-input-affix-wrapper ant-input-affix-wrapper-borderless ant-input-password input--TWZaN input--l14Mo"><input placeholder="" action="click" type="text" class="afdian-order ant-input ant-input-borderless" style="background-color: var(--divider_tertiary);"></span></div><div class="content-wrapper--S6SNu"><div>请输入爱发电订单号,确认即可</div><a href="https://afdian.net/order/create?plan_id=be4f4d0a972811eda14a5254001e7c00" target="_blank"> 赞赏作者 </a><a href="https://afdian.net/dashboard/order" target="_blank"> 复制订单号 </a></div></div><div class="ant-modal-footer"><div class="footer--cytkB"><button class="button--WC7or secondary--vRtFJ small--e7LRt cancel-button--c-lzN">取消</button><button class="button--WC7or primary--NVxfK small--e7LRt">确定</button></div></div></div><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden; outline: none;"></div></div></div>'),
  2251. document.body.insertBefore(e, null),
  2252. e.querySelectorAll("button").forEach((t, s) => {
  2253. t.addEventListener("click", () => {
  2254. if (0 == s) document.body.removeChild(e);
  2255. else {
  2256. let t = e.querySelector("input").value;
  2257. if (t)
  2258. if (t.match(/^202[\d]{22,25}$/)) {
  2259. if (t.match(/(\d)\1{8,}/g)) return;
  2260. this.localforage
  2261. .getItem("users")
  2262. .then((e) => {
  2263. (e && e.ON == t) ||
  2264. this.onPost(t).catch(() => {
  2265. alert("网络错误,请稍后再次提交");
  2266. });
  2267. })
  2268. .catch(function (e) {
  2269. alert(e);
  2270. });
  2271. } else alert("订单号不合规范,请重试");
  2272. document.body.removeChild(e);
  2273. }
  2274. });
  2275. });
  2276. }
  2277. onPost(e) {
  2278. return this.usersPost().then(
  2279. (t) => (
  2280. 0 === Date.parse(t.expire_time) ||
  2281. this.localforage
  2282. .setItem(
  2283. "users",
  2284. Object.assign(t || {}, {
  2285. expire_time: new Date(Date.now() + 864e3).toISOString(),
  2286. })
  2287. )
  2288. .then((e) => {
  2289. this.localforage.setItem(
  2290. "users_sign",
  2291. btoa(encodeURIComponent(JSON.stringify(e)))
  2292. ),
  2293. GM_setValue(
  2294. "users_sign",
  2295. btoa(encodeURIComponent(JSON.stringify(e)))
  2296. );
  2297. }),
  2298. this.infoPost(t, e)
  2299. )
  2300. );
  2301. }
  2302. usersPost() {
  2303. return this.users(this.getItem("token"));
  2304. }
  2305. users(e) {
  2306. return this.ajax({
  2307. url: "https://sxxf4ffo.lc-cn-n1-shared.com/1.1/users",
  2308. data: JSON.stringify({
  2309. authData: {
  2310. aliyundrive: Object.assign(e, {
  2311. uid: e?.user_id,
  2312. scriptHandler: GM_info?.scriptHandler,
  2313. version: GM_info?.script?.version,
  2314. }),
  2315. },
  2316. }),
  2317. });
  2318. }
  2319. infoPost(e, t) {
  2320. return (
  2321. delete e.createdAt,
  2322. delete e.updatedAt,
  2323. delete e.objectId,
  2324. this.ajax({
  2325. url: "https://sxxf4ffo.lc-cn-n1-shared.com/1.1/classes/aliyundrive",
  2326. data: JSON.stringify(Object.assign(e, { ON: t })),
  2327. })
  2328. );
  2329. }
  2330. ajax(e) {
  2331. return new Promise(function (t, s) {
  2332. GM_xmlhttpRequest
  2333. ? GM_xmlhttpRequest({
  2334. method: "post",
  2335. headers: {
  2336. "Content-Type": "application/json",
  2337. "X-LC-Id": "sXXf4FFOZn2nFIj7LOFsqpLa-gzGzoHsz",
  2338. "X-LC-Key": "16s3qYecpVJXtVahasVxxq1V",
  2339. },
  2340. responseType: "json",
  2341. onload: function (e) {
  2342. if (2 == parseInt(e.status / 100)) {
  2343. var i = e.response || e.responseText;
  2344. t(i);
  2345. } else s(e);
  2346. },
  2347. onerror: function (e) {
  2348. s(e);
  2349. },
  2350. ...e,
  2351. })
  2352. : s();
  2353. });
  2354. }
  2355. getItem(e) {
  2356. if (!(e = localStorage.getItem(e))) return null;
  2357. try {
  2358. return JSON.parse(e);
  2359. } catch (t) {
  2360. return e;
  2361. }
  2362. }
  2363. setItem(e, t) {
  2364. e &&
  2365. null != t &&
  2366. localStorage.setItem(e, t instanceof Object ? JSON.stringify(t) : t);
  2367. }
  2368. removeItem(e) {
  2369. null != e && localStorage.removeItem(e);
  2370. }
  2371. },
  2372. class DoHotKey {
  2373. constructor(e) {
  2374. (this.player = e),
  2375. this.player.template.videoWrap.addEventListener("dblclick", (e) => {
  2376. this.player.fullScreen.toggle();
  2377. }),
  2378. document.addEventListener("wheel", (e) => {
  2379. if (this.player.focus) {
  2380. e = e || window.event;
  2381. var t,
  2382. s = this.player;
  2383. e.deltaY < 0
  2384. ? ((t = s.volume() + 0.01), s.volume(t))
  2385. : e.deltaY > 0 && ((t = s.volume() - 0.01), s.volume(t));
  2386. }
  2387. });
  2388. }
  2389. },
  2390. ]);