Play-With-MPV

使用 MPV 播放网页上的视频

当前为 2022-11-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Play-With-MPV
  3. // @name:zh 使用 MPV 播放
  4. // @namespace https://github.com/LuckyPuppy514
  5. // @version 2.2.2
  6. // @author LuckyPuppy514
  7. // @copyright 2022, Grant LuckyPuppy514 (https://github.com/LuckyPuppy514)
  8. // @license MIT
  9. // @description 使用 MPV 播放网页上的视频
  10. // @homepage https://github.com/LuckyPuppy514/Play-With-MPV
  11. // @icon https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/mpv.png
  12. // @match *://www.youtube.com/*
  13. // @include https://www.youtube.com/watch/*
  14. // @include https://www.bilibili.com/bangumi/play/*
  15. // @include https://www.bilibili.com/video/*
  16. // @include https://live.bilibili.com/*
  17. // @connect api.bilibili.com
  18. // @connect api.live.bilibili.com
  19. // @include https://ddys.tv/*
  20. // @include https://ddys2.me/*
  21. // @include https://www.996dm.com/play/*
  22. // @include http://www.996dm.com/play/*
  23. // @include http://www.dmlaa.com/play/*
  24. // @include https://danmu.yhdmjx.com/*
  25. // @include https://www.dm233.me/play/*
  26. // @include http://www.dmh8.com/player/*
  27. // @include https://www.yhdmp.net/vp/*
  28. // @include https://ani.gamer.com.tw/animeVideo.php?*
  29. // @include http*://*.mp4
  30. // @include http*://*.mkv
  31. // @include http*://*.avi
  32. // @include http*://*.rmvb
  33. // @include http*://alist.*
  34. // @include http*://*:5244*
  35. // @include https://hdzyk.com/?m=*
  36. // @include https://1080zyk*.com/?m=*
  37. // @include https://vip.zykbf.com/?url=*
  38. // @include https://www.kk151.com/play/*
  39. // @include https://jx.m3u8.tv/jiexi/?url=*
  40. // @include https://jx.wolongzywcdn.com:65/m3u8.php?url=*
  41. // @include https://www.m3u8.tv.cdn.8old.cn/jx.php?url=*
  42. // @include https://jx.wujinkk.com/dplayer/?url=*
  43. // @include https://www.ikdmjx.com/?url=*
  44. // @include https://hls.kuaibofang.com/?url=*
  45. // @include https://jx.jxbdzyw.com/m3u8/?url=*
  46. // @include https://libvio.fun/play/*
  47. // @include https://www.libvio.me/play/*
  48. // @include https://sh-data-s02.chinaeast2.cloudapp.chinacloudapi.cn/ai.php?url=*
  49. // @include https://sh-data-s02.chinaeast2.cloudapp.chinacloudapi.cn/lb.php?url=*
  50. // @include https://www.bdys01.com/play/*
  51. // @run-at document-end
  52. // @require https://unpkg.com/jquery@3.2.1/dist/jquery.min.js
  53. // @grant GM_setValue
  54. // @grant GM_getValue
  55. // ==/UserScript==
  56.  
  57. 'use strict';
  58. // 注册表版本
  59. const REG_VERSION = "20220907";
  60. // 不输出控制台信息
  61. const NO_TERMINAL = true;
  62.  
  63. // const IS_DEBUG = true;
  64. // function debug(data) {
  65. // if (IS_DEBUG) {
  66. // console.log(data);
  67. // }
  68. // }
  69.  
  70. const DIV =
  71. `
  72. <div id="pwmpv-button-div">
  73. <button id="pwmpv-about-button"></button>
  74. <button id="pwmpv-play-button"></button>
  75. <button id="pwmpv-setting-button"></button>
  76. </div>
  77.  
  78. <div id="pwmpv-about-div">
  79. <span class="pwmpv-title-span">✨ 关于 Play-With-MPV <button class="pwmpv-close-button">❌</button></span>
  80. <table id="pwmpv-about-table">
  81. <tr>
  82. <td colspan="6" class="pwmpv-title-td">使用 MPV 播放网页中的视频(解码 ⬆️ 补帧 着色器 更多💡)</td>
  83. </tr>
  84. <tr>
  85. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV#-%E7%AE%80%E4%BB%8B" target="_blank">支持网站</a></td>
  86. <td colspan="4">
  87. <a href="https://www.bilibili.com/" target="_blank"><img class="pwmpv-support-url-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/bilibili.ico"/></a>
  88. <a href="https://ddys2.me/" target="_blank"><img class="pwmpv-support-url-icon-small" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/ddrk.webp"/></a>
  89. <a href="https://www.youtube.com/" target="_blank"><img class="pwmpv-support-url-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/youtube.png"/></a>
  90. <a href="https://ani.gamer.com.tw/" target="_blank"><img class="pwmpv-support-url-icon" style="width: 57px;" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/bahaLOGO_1200x630.jpg"\></a>
  91. <a href="https://www.996dm.com/" target="_blank"><img class="pwmpv-support-url-icon" style="width: 95px;" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/logo_f.png"/></a>
  92. <a href="http://www.dmlaa.com/" target="_blank"><img class="pwmpv-support-url-icon-small" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/fengchedongman.jpg"/></a>
  93. <a href="https://github.com/LuckyPuppy514/Play-With-MPV#-%E7%AE%80%E4%BB%8B" target="_blank" style="margin-left: 6px;">. . . . . .</a>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td colspan="2"><a href="https://www.lckp.top/archives/mpvnetcm">支持软件</a></td>
  98. <td colspan="2">
  99. <a href="https://www.lckp.top/archives/mpvnetcm" target="_blank"><img class="pwmpv-support-url-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/mpvnet.png" /></a>
  100. </td>
  101. <td colspan="2">
  102. <a href="https://www.lckp.top/archives/mpv-lazy" target="_blank"><img class="pwmpv-support-url-icon-large" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/mpv.png" /></a>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV" target="_blank">脚本相关</a></td>
  107. <td colspan="2"><a href="https://greasyfork.org/zh-CN/scripts/444056-play-with-mpv" target="_blank">🆕 版本更新 🆕</a></td>
  108. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV/issues/new" target="_blank">👻 问题反馈 👻</a></td>
  109. </tr>
  110. </table>
  111. <span class="pwmpv-footer-span">
  112. <a href="https://greasyfork.org/zh-CN/scripts/444056-play-with-mpv" target="_blank"><img class="pwmpv-footer-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/tampermonkey.png"/></a>
  113. <a href="https://www.lckp.top" target="_blank">2022 © LuckyPuppy514</a>
  114. <a href="https://github.com/LuckyPuppy514/Play-With-MPV" target="_blank"><img class="pwmpv-footer-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/github.png"/></a>
  115. </span>
  116. </div>
  117.  
  118. <div id="pwmpv-setting-div">
  119. <span class="pwmpv-title-span">🌟 Play-With-MPV 设置 🌟 <button class="pwmpv-close-button">❌</button></span>
  120. <table id="pwmpv-setting-table">
  121. <tr>
  122. <td class="pwmpv-title-td">软件路径</td>
  123. <td colspan="3"><input id="pwmpv-mpv-path-input" type=text placeholder="请输入你的 mpv.com 路径,例如:D://daily//mpvnet//mpvnet.com"></td>
  124. </tr>
  125. <tr>
  126. <td class="pwmpv-title-td">代理设置</td>
  127. <td colspan="3"><input id="pwmpv-proxy-input" type=text placeholder="请输入你的 http 或 socks 代理,例如:http://127.0.0.1:10809"></td>
  128. </tr>
  129. <tr>
  130. <td class="pwmpv-title-td">最高画质</td>
  131. <td>
  132. <select id="pwmpv-best-quality-select">
  133. <option value="unlimited" selected>无限制</option>
  134. <option value="2160p">2160p</option>
  135. <option value="1440p">1440p</option>
  136. <option value="1080p">1080p</option>
  137. <option value="720p">720p</option>
  138. <option value="480p">480p</option>
  139. </select>
  140. <span class="tip-span">限B站和油管</span>
  141. </td>
  142. <td class="pwmpv-title-td">视频编码</td>
  143. <td>
  144. <select id="pwmpv-bilibili-codecs-select">
  145. <option value="12" selected>HEVC</option>
  146. <option value="13">AV1</option>
  147. <option value="7">AVC</option>
  148. </select>
  149. <span class="tip-span">限B站</span>
  150. </td>
  151. </tr>
  152. <tr>
  153. <td colspan="4">
  154. <button id="pwmpv-save-button">保存设置</button>
  155. <button id="pwmpv-download-button" data-tip="请先输入 MPV 路径,并保存设置">下载注册表</button>
  156. </td>
  157. </tr>
  158. </table>
  159. <span class="pwmpv-footer-span">
  160. <a href="https://greasyfork.org/zh-CN/scripts/444056-play-with-mpv" target="_blank"><img class="pwmpv-footer-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/tampermonkey.png"/></a>
  161. <a href="https://www.lckp.top" target="_blank">2022 © LuckyPuppy514</a>
  162. <a href="https://github.com/LuckyPuppy514/Play-With-MPV" target="_blank"><img class="pwmpv-footer-icon" src="https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/github.png"/></a>
  163. </span>
  164. </div>
  165.  
  166. <iframe id="firefox-iframe" src="about:blank" style="display:none;"></iframe>
  167. `
  168. const CSS =
  169. `
  170. .pwmpv-close-button {
  171. position: absolute;
  172. top: 3px;
  173. right: 3px;
  174. height: 25px;
  175. width: 40px;
  176. border: none;
  177. font-size: 18px;
  178. background-color: rgba(0, 0, 0, 0);
  179. line-height: 0px;
  180. }
  181. .pwmpv-close-button:hover {
  182. background-color: rgba(0, 0, 0, 0.3);
  183. cursor: pointer;
  184. }
  185. #pwmpv-button-div {
  186. display: none;
  187. }
  188. .pwmpv-title-span {
  189. padding-top: 15px;
  190. font-size: 15px;
  191. }
  192. #pwmpv-about-button {
  193. position: fixed;
  194. bottom: 58px;
  195. left: 8px;
  196. z-index: 999998;
  197.  
  198. width: 25px;
  199. height: 25px;
  200. border: none;
  201. border-radius: 50%;
  202. background-size: cover;
  203. background-color: rgba(255, 255, 255, 0);
  204. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/about-pink.png);
  205. }
  206. #pwmpv-about-button:hover {
  207. bottom: 56px;
  208. left: 6px;
  209. z-index: 999999;
  210.  
  211. width: 27px;
  212. height: 27px;
  213. cursor: pointer;
  214. }
  215. #pwmpv-about-div {
  216. position: fixed;
  217. top: 40%;
  218. left: 50%;
  219. transform: translate(-50%, -50%);
  220. z-index: 999999;
  221.  
  222. width: 600px;
  223. height: 320px;
  224. border: 6px solid rgba(255, 255, 255, 0.5);
  225. background-color: rgba(234, 122, 153, 1);
  226. display: none;
  227. flex-direction: column;
  228. border-radius: 6px;
  229. align-items: center;
  230. color: rgba(255, 255, 255, 1);
  231. }
  232. #pwmpv-about-table {
  233. margin-top: 10px;
  234. width: 570px;
  235. height: 240px;
  236. border-radius: 5px !important;
  237. border: 3px solid rgba(255, 255, 255, 1) !important;
  238. text-align: center;
  239. }
  240. #pwmpv-about-table td {
  241. border: 2px solid rgba(255, 255, 255, 0.5);
  242. padding: 0px 15px 0px 15px;
  243. }
  244. #pwmpv-about-div a {
  245. color: rgba(255, 255, 255, 1);
  246. text-decoration: none;
  247. font-size: 14px;
  248. display: inline-block;
  249. }
  250.  
  251. #pwmpv-play-button {
  252. position: fixed;
  253. bottom: 16px;
  254. left: 20px;
  255. z-index: 999999;
  256.  
  257. width: 50px;
  258. height: 50px;
  259. border: none;
  260. border-radius: 50%;
  261. background-size: cover;
  262. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/mpvnet.png);
  263. cursor: pointer;
  264. }
  265. #pwmpv-play-button:hover {
  266. bottom: 14px;
  267. left: 18px;
  268.  
  269. width: 54px;
  270. height: 54px;
  271. cursor: pointer;
  272. }
  273.  
  274. #pwmpv-setting-button {
  275. position: fixed;
  276. bottom: 56px;
  277. left: 58px;
  278. z-index: 999998;
  279.  
  280. width: 28px;
  281. height: 28px;
  282. border: none;
  283. border-radius: 50%;
  284. background-size: cover;
  285. background-color: rgba(255, 255, 255, 0);
  286. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/lx-setting.png);
  287. }
  288. #pwmpv-setting-button:hover {
  289. bottom: 54px;
  290. left: 56px;
  291. z-index: 999999;
  292.  
  293. width: 32px;
  294. height: 32px;
  295. cursor: pointer;
  296. }
  297. #pwmpv-setting-div {
  298. position: fixed;
  299. top: 40%;
  300. left: 50%;
  301. transform: translate(-50%, -50%);
  302. z-index: 999999;
  303.  
  304. width: 600px;
  305. height: 320px;
  306. border: 6px solid rgba(255, 255, 255, 0.5);
  307. background-color: rgba(65, 146, 247, 1);
  308. display: none;
  309. flex-direction: column;
  310. border-radius: 6px;
  311. align-items: center;
  312. color: rgba(255, 255, 255, 1);
  313. }
  314. #pwmpv-setting-table {
  315. margin-top: 10px;
  316. width: 570px;
  317. height: 240px;
  318. border-radius: 5px !important;
  319. border: 3px solid rgba(255, 255, 255, 1) !important;
  320. text-align: left;
  321. }
  322. #pwmpv-setting-table td {
  323. font-size: 14px;
  324. border: 0px solid rgba(255, 255, 255, 0.5);
  325. padding-top: 18px;
  326. }
  327. .tip-span {
  328. font-size: xx-small;
  329. color: yellow;
  330. position: fixed;
  331. padding-left: 5px;
  332. padding-top: 9px;
  333. }
  334. .pwmpv-title-td {
  335. width: 90px;
  336. height: 30px;
  337. border: none;
  338. font-size: 14px;
  339. padding-left: 12px;
  340. text-align: center;
  341. }
  342. #pwmpv-setting-table input {
  343. font-size: 14px;
  344. width: 430px;
  345. height: 26px;
  346. border: none;
  347. outline: none;
  348. padding-left: 6px;
  349. border-radius: 2px;
  350. color: rgba(0, 0, 0, 1);
  351. background-color: rgba(255, 255, 255, 0.9);
  352. }
  353. #pwmpv-bilibili-codecs-select,
  354. #pwmpv-best-quality-select {
  355. width: 90px;
  356. height: 25px;
  357. border: none;
  358. outline: none;
  359. padding-left: 6px;
  360. border-radius: 2px;
  361. color: rgba(0, 0, 0, 1);
  362. background-color: rgba(255, 255, 255, 0.9);
  363. }
  364. #pwmpv-save-button {
  365. font-size: 14px;
  366. margin-left: 105px;
  367. width: 300px;
  368. height: 30px;
  369. border: none;
  370. border-radius: 3px;
  371. color: rgba(255, 255, 255, 1);
  372. background-color: rgba(0, 255, 50, 0.6);
  373. }
  374. #pwmpv-save-button:hover {
  375. background-color: rgba(0, 255, 0, 0.8);
  376. cursor: pointer;
  377. }
  378. .pwmpv-download-enable:hover {
  379. background-color: rgba(0, 255, 0, 0.8);
  380. cursor: pointer;
  381. }
  382. .pwmpv-download-disable:hover {
  383. cursor: pointer;
  384. }
  385. .pwmpv-download-enable {
  386. font-size: x-small;
  387. margin-left: 10px;
  388. width: 80px;
  389. height: 30px;
  390. border: none;
  391. border-radius: 3px;
  392. color: rgba(255, 255, 255, 1);
  393. background-color: rgba(0, 255, 50, 0.6);
  394.  
  395. }
  396. .pwmpv-download-disable {
  397. font-size: x-small;
  398. margin-left: 10px;
  399. width: 80px;
  400. height: 30px;
  401. border: none;
  402. border-radius: 3px;
  403. color: rgba(255, 255, 255, 1);
  404. background-color: rgba(0, 0, 0, 0.5);
  405. }
  406. .pwmpv-tips-td {
  407. color: rgba(255, 255, 255, 1);
  408. font-size: 12px;
  409. }
  410. .pwmpv-footer-span {
  411. margin-top: 10px;
  412. margin-bottom: 10px;
  413. color: rgba(255, 255, 255, 1);
  414. }
  415. .pwmpv-footer-span a {
  416. color: rgba(255, 255, 255, 1);
  417. text-decoration: none;
  418. font-size: 14px;
  419. margin-bottom: 1px;
  420. display: inline-block;
  421. }
  422. .pwmpv-footer-icon {
  423. width: 18px;
  424. height: 18px;
  425. margin-left: 5px;
  426. margin-right: 5px;
  427. margin-bottom: -2px;
  428. }
  429. .pwmpv-support-url-icon {
  430. width: 30px;
  431. height: 30px;
  432. margin-left: 8px;
  433. margin-right: 8px;
  434. }
  435. .pwmpv-support-url-icon-small {
  436. width: 25px;
  437. height: 25px;
  438. margin-left: 8px;
  439. margin-right: 8px;
  440. margin-bottom: 2px;
  441. }
  442. .pwmpv-support-url-icon-large {
  443. width: 37px;
  444. height: 37px;
  445. margin-left: 8px;
  446. margin-right: 8px;
  447. margin-bottom: -4px;
  448. }
  449. `
  450.  
  451. const REG =
  452. `Windows Registry Editor Version 5.00
  453. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Google\\Chrome]
  454. "ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
  455.  
  456. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Edge]
  457. "ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
  458.  
  459. [HKEY_CLASSES_ROOT\\mpv]
  460. @="mpv Protocol"
  461. "URL Protocol"=""
  462.  
  463. [HKEY_CLASSES_ROOT\\mpv\\DefaultIcon]
  464. @=""
  465.  
  466. [HKEY_CLASSES_ROOT\\mpv\\shell]
  467. @=""
  468.  
  469. [HKEY_CLASSES_ROOT\\mpv\\shell\\open]
  470. @=""
  471.  
  472. [HKEY_CLASSES_ROOT\\mpv\\shell\\open\\command]
  473. @="cmd /V:ON /C \\"FOR /F \\"tokens=* USEBACKQ\\" %%F IN (\`C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -command \\"Add-Type -AssemblyName System.Web;[System.Web.HTTPUtility]::UrlDecode('%1')\\"\`) DO (SET param=%%F) & SET param=!param:mpv://=! & start /min MPV_PATH !param!\\""
  474. `
  475.  
  476. // element id
  477. const BUTTON_DIV = "pwmpv-button-div";
  478. const ABOUT_BUTTON_ID = "pwmpv-about-button";
  479. const ABOUT_DIV_ID = "pwmpv-about-div";
  480. const PLAY_BUTTON_ID = "pwmpv-play-button";
  481. const SETTING_BUTTON_ID = "pwmpv-setting-button";
  482. const SETTING_DIV_ID = "pwmpv-setting-div";
  483. const MPV_PATH_INPUT_ID = "pwmpv-mpv-path-input";
  484. const PROXY_INPUT_ID = "pwmpv-proxy-input";
  485. const BILIBILI_CODECS_SELECT_ID = "pwmpv-bilibili-codecs-select";
  486. const BEST_QUALITY_SELECT_ID = "pwmpv-best-quality-select";
  487. const SAVE_BUTTON_ID = "pwmpv-save-button";
  488. const DOWNLOAD_BUTTON_ID = "pwmpv-download-button";
  489. // display
  490. const DISPLAY_NONE = "none";
  491. const DISPLAY_FLEX = "flex";
  492. // GM value key
  493. const KEY_MPV_PATH = "MPV_PATH";
  494. const KEY_PROXY = "PROXY";
  495. const KEY_REG_VERSION = "REG_VERSION";
  496. const KEY_BILIBILI_CODECS = "BILIBILI_CODECS";
  497. const BILIBILI_CODECS_HEVC = "12";
  498. const KEY_BEST_QUALITY = "BEST_QUALITY";
  499. const BEST_QUALITY_UNLIMITED = "unlimited";
  500.  
  501. function appendHTML() {
  502. var div = document.createElement("div");
  503. div.innerHTML = DIV.trim();
  504. document.body.appendChild(div);
  505. }
  506. function appendCSS() {
  507. var css = document.createElement("style");
  508. css.innerHTML = CSS.trim();
  509. document.head.appendChild(css);
  510. }
  511. var bilibiliCodecs;
  512. var bestQuality;
  513. var isFullScreen = false;
  514. function addListener() {
  515. // 关于
  516. var aboutButton = document.getElementById(ABOUT_BUTTON_ID);
  517. var aboutDiv = document.getElementById(ABOUT_DIV_ID);
  518. aboutButton.onclick = function () {
  519. if (aboutDiv.style.display != DISPLAY_FLEX) {
  520. aboutDiv.style.display = DISPLAY_FLEX;
  521. settingDiv.style.display = DISPLAY_NONE;
  522. } else {
  523. aboutDiv.style.display = DISPLAY_NONE;
  524. }
  525. };
  526.  
  527. // 播放
  528. var playButton = document.getElementById(PLAY_BUTTON_ID);
  529. playButton.onclick = function () {
  530. let regVersion = GM_getValue(KEY_REG_VERSION);
  531. if (!regVersion || regVersion != REG_VERSION) {
  532. showSettingDiv();
  533. Toast("🆕 注册表配置有更新,请重新下载并添加注册表信息 🆕");
  534. return;
  535. }
  536. handler.playCurrentVideoWithMPV();
  537. }
  538.  
  539. // 设置
  540. var settingButton = document.getElementById(SETTING_BUTTON_ID);
  541. var bilibiliCodecsSelect = document.getElementById(BILIBILI_CODECS_SELECT_ID);
  542. var bestQualitySelect = document.getElementById(BEST_QUALITY_SELECT_ID);
  543. var saveButton = document.getElementById(SAVE_BUTTON_ID);
  544. var downloadButton = document.getElementById(DOWNLOAD_BUTTON_ID);
  545. var settingDiv = document.getElementById(SETTING_DIV_ID);
  546. var mpvPathInput = document.getElementById(MPV_PATH_INPUT_ID);
  547. var proxyInput = document.getElementById(PROXY_INPUT_ID);
  548. settingButton.onclick = function () {
  549. if (settingDiv.style.display != DISPLAY_FLEX) {
  550. showSettingDiv();
  551. aboutDiv.style.display = DISPLAY_NONE;
  552. } else {
  553. settingDiv.style.display = DISPLAY_NONE;
  554. }
  555. };
  556. bilibiliCodecs = GM_getValue(KEY_BILIBILI_CODECS);
  557. if (!bilibiliCodecs) {
  558. bilibiliCodecs = BILIBILI_CODECS_HEVC;
  559. GM_setValue(KEY_BILIBILI_CODECS, bilibiliCodecs);
  560. }
  561. bilibiliCodecsSelect.onchange = function () {
  562. bilibiliCodecs = this.value;
  563. };
  564. bestQuality = GM_getValue(KEY_BEST_QUALITY);
  565. if (!bestQuality) {
  566. bestQuality = BEST_QUALITY_UNLIMITED;
  567. GM_setValue(KEY_BEST_QUALITY, bestQuality);
  568. }
  569. bestQualitySelect.onchange = function () {
  570. bestQuality = this.value;
  571. };
  572. saveButton.onclick = function () {
  573. let oldMpvPath = GM_getValue(KEY_MPV_PATH);
  574. let mpvPath = mpvPathInput.value;
  575. let proxy = proxyInput.value;
  576. if (!mpvPath) {
  577. downloadButton.className = "pwmpv-download-disable";
  578. Toast("⚠️ 软件路径不能为空 ⚠️", 2000);
  579. return;
  580. }
  581. if (/.*[\u4e00-\u9fa5]+.*$/.test(mpvPath)) {
  582. downloadButton.className = "pwmpv-download-disable";
  583. Toast("⚠️ 软件路径不能包含中文 ⚠️", 2000);
  584. return;
  585. }
  586. mpvPath = mpvPath.replace(/[\\|/]+/g, "//");
  587. if (!mpvPath.endsWith(".com")) {
  588. if (!mpvPath.endsWith("//")) {
  589. mpvPath = mpvPath + "//";
  590. }
  591. if (mpvPath.endsWith("mpvnet//")) {
  592. mpvPath = mpvPath + "mpvnet.com";
  593. } else if (mpvPath.endsWith("mpv//") || mpvPath.endsWith("mpv-lazy//")) {
  594. mpvPath = mpvPath + "mpv.com";
  595. } else {
  596. Toast("⚠️ 软件路径错误,正确示例:D:/daily/mpvnet/mpvnet.com ⚠️", 3000)
  597. return;
  598. }
  599. }
  600. mpvPathInput.value = mpvPath;
  601. GM_setValue(KEY_MPV_PATH, mpvPath);
  602. GM_setValue(KEY_PROXY, proxy);
  603. if (bilibiliCodecs != GM_getValue(KEY_BILIBILI_CODECS) || bestQuality != GM_getValue(KEY_BEST_QUALITY)) {
  604. GM_setValue(KEY_BILIBILI_CODECS, bilibiliCodecs);
  605. GM_setValue(KEY_BEST_QUALITY, bestQuality);
  606. // 重新获取视频链接
  607. initCurrentPageInfo();
  608. refreshCurrentVideoUrl();
  609. }
  610. // debug(proxy);
  611. downloadButton.className = "pwmpv-download-enable";
  612. if (oldMpvPath != mpvPath) {
  613. Toast("🔥 请重新添加注册表信息 🔥", 3000);
  614. downloadButton.click();
  615. } else {
  616. Toast("✅ 保存成功 ✅", 2000);
  617. }
  618. };
  619. downloadButton.onclick = function () {
  620. // 生成注册表信息
  621. var a = document.createElement('a');
  622. var blob = new Blob([REG.replace(KEY_MPV_PATH, GM_getValue(KEY_MPV_PATH))], { 'type': 'application/octet-stream' });
  623. a.href = window.URL.createObjectURL(blob);
  624. a.download = "mpv.reg";
  625. a.click();
  626. GM_setValue(KEY_REG_VERSION, REG_VERSION);
  627. }
  628. var closeButtons = document.getElementsByClassName("pwmpv-close-button");
  629. for (let closeButton of closeButtons) {
  630. closeButton.onclick = function () {
  631. aboutDiv.style.display = DISPLAY_NONE;
  632. settingDiv.style.display = DISPLAY_NONE;
  633. }
  634. }
  635. // 全屏
  636. document.addEventListener("fullscreenchange", () => {
  637. if (document.fullscreenElement) {
  638. isFullScreen = true;
  639. document.getElementById(BUTTON_DIV).style.display = DISPLAY_NONE;
  640. } else {
  641. isFullScreen = false;
  642. handler.checkCurrentVideoUrl();
  643. }
  644. });
  645. }
  646. // 显示设置窗口
  647. function showSettingDiv() {
  648. var downloadButton = document.getElementById(DOWNLOAD_BUTTON_ID);
  649. var settingDiv = document.getElementById(SETTING_DIV_ID);
  650. var bilibiliCodecsSelect = document.getElementById(BILIBILI_CODECS_SELECT_ID);
  651. var bestQualitySelect = document.getElementById(BEST_QUALITY_SELECT_ID);
  652. var mpvPathInput = document.getElementById(MPV_PATH_INPUT_ID);
  653. var proxyInput = document.getElementById(PROXY_INPUT_ID);
  654. let mpvPath = GM_getValue(KEY_MPV_PATH);
  655. let proxy = GM_getValue(KEY_PROXY);
  656. bilibiliCodecs = GM_getValue(KEY_BILIBILI_CODECS);
  657. bestQuality = GM_getValue(KEY_BEST_QUALITY);
  658. if (mpvPath) {
  659. mpvPathInput.value = mpvPath;
  660. downloadButton.className = "pwmpv-download-enable";
  661. } else {
  662. downloadButton.className = "pwmpv-download-disable";
  663. }
  664. if (proxy) {
  665. proxyInput.value = proxy;
  666. }
  667. bilibiliCodecsSelect.value = bilibiliCodecs;
  668. bestQualitySelect.value = bestQuality;
  669. settingDiv.style.display = DISPLAY_FLEX;
  670. }
  671. // 显示消息
  672. function Toast(msg, duration) {
  673. duration = isNaN(duration) ? 3000 : duration;
  674. var m = document.createElement('div');
  675. m.innerHTML = msg;
  676. m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 15%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0, 0.9);font-size: 14px;";
  677. document.body.appendChild(m);
  678. setTimeout(function () {
  679. var d = 0.5;
  680. m.style.opacity = '0';
  681. setTimeout(function () { document.body.removeChild(m) }, d * 1000);
  682. }, duration);
  683. }
  684.  
  685. // mpv urlprotocol
  686. const MPV_URLPROTOCOL = "mpv://";
  687. // mpv urlprotocol link
  688. class UrlProtocol {
  689. constructor() {
  690. this.link = MPV_URLPROTOCOL + '"' + currentVideoUrl + '"';
  691. this.appendNoTerminal();
  692. this.needAppendTitle = false;
  693. }
  694. // 添加参数
  695. append(param) {
  696. this.link = this.link + ' ' + param;
  697. }
  698. // 禁止命令行输出及控制
  699. appendNoTerminal() {
  700. if (NO_TERMINAL) {
  701. this.append('--no-terminal');
  702. }
  703. }
  704. // 开始时间(如果 mpv 开启了退出时记住播放状态,则记住状态优先级更高)
  705. appendStartTime() {
  706. let startTime = handler.getStartTime();
  707. if (startTime) {
  708. this.append('--ss="' + startTime + '"');
  709. }
  710. }
  711. // 标题
  712. appendTitle() {
  713. this.needAppendTitle = true;
  714. }
  715. // 代理
  716. appendProxy() {
  717. let proxy = GM_getValue(KEY_PROXY);
  718. if (proxy) {
  719. this.append('--http-proxy=' + proxy + ' --ytdl-raw-options=proxy=[' + proxy + ']');
  720. }
  721. }
  722. // 最终链接
  723. getLink() {
  724. if (this.needAppendTitle) {
  725. // 限制标题长度(url 有长度限制)
  726. let maxLength = 1900 - this.link.length;
  727. let title = encodeURIComponent(document.title);
  728. if (title.length > maxLength) {
  729. title = title.substring(0, maxLength) + '...';
  730. }
  731. this.append('--force-media-title="' + title + '"');
  732. }
  733. return this.link;
  734. }
  735. }
  736.  
  737. // 网页处理器
  738. var handler;
  739. class Handler {
  740. // 获取当前视频链接
  741. getCurrentVideoUrl() { }
  742. // 获取开始时间
  743. getStartTime() { return null; }
  744. // 暂停网页视频
  745. pauseCurrentVideo() { document.getElementsByTagName("video")[0].pause(); }
  746. // 获取调用 mpv 链接
  747. getUrlProtocolLink() {
  748. let urlProtocol = new UrlProtocol;
  749. urlProtocol.appendStartTime();
  750. urlProtocol.appendTitle();
  751. return urlProtocol.getLink();
  752. }
  753. // 校验视频链接是否有效
  754. checkCurrentVideoUrl() {
  755. if (this.baseCheckCurrentVideoUrl()) {
  756. if (!isFullScreen) {
  757. document.getElementById(BUTTON_DIV).style.display = DISPLAY_FLEX;
  758. }
  759. return true;
  760. }
  761. return false;
  762. }
  763.  
  764. // 调用 mpv 播放
  765. playCurrentVideoWithMPV() {
  766. window.open(this.getUrlProtocolLink(), "_self");
  767. let i = 0;
  768. while (i < 3) {
  769. i++;
  770. setTimeout(function () {
  771. handler.pauseCurrentVideo();
  772. }, 2000 * i);
  773. }
  774. }
  775. // 根据 class name 获取播放时间
  776. getStartTimeByClassName(className) {
  777. let startTimeElements = document.getElementsByClassName(className);
  778. let length = startTimeElements.length;
  779. if (length > 0) {
  780. return startTimeElements[length - 1].innerHTML;
  781. }
  782. return null;
  783. }
  784. // 视频链接基础校验
  785. baseCheckCurrentVideoUrl() {
  786. // debug("current video url: " + currentVideoUrl);
  787. if (!currentVideoUrl || !currentVideoUrl.startsWith("http")
  788. || currentVideoUrl.indexOf("yun.66dm.net") != -1
  789. || currentVideoUrl.indexOf("www.xmfans.me") != -1
  790. || currentVideoUrl.indexOf("sod.bunediy.com") != -1) {
  791. return false;
  792. }
  793. return true;
  794. }
  795. }
  796.  
  797. // 油管
  798. const YOUTUBE = "www.youtube.com";
  799. const YOUTUBE_QN = {
  800. "unlimited": "",
  801. "2160p": "--ytdl-format=bestvideo[height<=?2160]%2Bbestaudio/best",
  802. "1440p": "--ytdl-format=bestvideo[height<=?1440]%2Bbestaudio/best",
  803. "1080p": "--ytdl-format=bestvideo[height<=?1080]%2Bbestaudio/best",
  804. "720p": "--ytdl-format=bestvideo[height<=?720]%2Bbestaudio/best",
  805. "480p": "--ytdl-format=bestvideo[height<=?480]%2Bbestaudio/best",
  806. };
  807. class YoutubeHandler extends Handler {
  808. getCurrentVideoUrl() {
  809. currentVideoUrl = currentUrl;
  810. this.checkCurrentVideoUrl();
  811. }
  812. getStartTime() {
  813. return this.getStartTimeByClassName("ytp-time-current");
  814. }
  815. getUrlProtocolLink() {
  816. let urlProtocol = new UrlProtocol;
  817. urlProtocol.appendStartTime();
  818. urlProtocol.appendProxy();
  819. if (bestQuality) {
  820. urlProtocol.append(YOUTUBE_QN[bestQuality]);
  821. }
  822. return urlProtocol.getLink();
  823. }
  824. checkCurrentVideoUrl() {
  825. if (currentUrl.indexOf("/watch") == -1 && currentUrl.indexOf("/playlist") == -1) {
  826. return false;
  827. }
  828. return super.checkCurrentVideoUrl();
  829. }
  830. }
  831.  
  832. // B站
  833. const BILIBILI = "www.bilibili.com";
  834. // B站 API
  835. const BILIBILI_API = 'https://api.bilibili.com';
  836. // cid 用于传递给 mpv 获取弹幕
  837. var bilibiliCid;
  838. const BILIBILI_QN = {
  839. "unlimited": 127,
  840. "2160p": 126,
  841. "1440p": 116,
  842. "1080p": 116,
  843. "720p": 74,
  844. "480p": 32,
  845. };
  846. class BilibiliHandler extends Handler {
  847. getCurrentVideoUrl() {
  848. let index = currentUrl.indexOf('/video/');
  849. if (index != -1) {
  850. // 投稿视频
  851. let param = "";
  852. let videoId = currentUrl.substring(index + 7);
  853. if (videoId.startsWith("BV")) {
  854. param = "bvid=" + videoId.substring(2, 12);
  855. } else if (videoId.startsWith("av")) {
  856. param = "aid=" + videoId.substring(2, 10);
  857. } else {
  858. // debug("bilibili video id invalid: " + videoId);
  859. return;
  860. }
  861. // debug("bilibili video id: " + param);
  862. getBilibiliVideoUrl(param);
  863.  
  864. } else {
  865. // 番剧
  866. let aElement = document.getElementsByClassName('ep-item cursor visited')[0];
  867. if (!aElement) {
  868. aElement = document.getElementsByClassName('ep-item cursor')[0];
  869. }
  870. let epid = aElement.getElementsByTagName('a')[0].href;
  871. epid = epid.substring(epid.indexOf('/ep') + 3);
  872. epid = epid.substring(0, epid.indexOf('/'));
  873. // debug('epid: ' + epid);
  874.  
  875. let eno = document.getElementsByClassName("ep-list-progress")[0];
  876. if (eno) {
  877. eno = eno.innerHTML;
  878. eno = eno.substring(0, eno.indexOf('/'));
  879. } else {
  880. eno = "1";
  881. }
  882.  
  883. // debug('eno: ' + eno);
  884. getBilibiliBangumiUrl(epid, eno);
  885. }
  886. }
  887. getStartTime() {
  888. let startTime = this.getStartTimeByClassName("bpx-player-ctrl-time-current");
  889. if (!startTime) {
  890. startTime = this.getStartTimeByClassName("squirtle-video-time-now");
  891. }
  892. return startTime;
  893. }
  894. getUrlProtocolLink() {
  895. let urlProtocol = new UrlProtocol;
  896. urlProtocol.appendStartTime();
  897. urlProtocol.appendTitle();
  898. urlProtocol.append('--audio-file="' + currentAudioUrl + '"');
  899. urlProtocol.append('--http-header-fields="referer: https://www.bilibili.com, user-agent: ' + navigator.userAgent + '"');
  900. urlProtocol.append('--script-opts="cid=' + bilibiliCid + '"');
  901. return urlProtocol.getLink();
  902. }
  903. }
  904. // 获取B站投稿视频链接
  905. function getBilibiliVideoUrl(param) {
  906. $.ajax({
  907. type: "GET",
  908. url: BILIBILI_API + "/x/web-interface/view?" + param,
  909. xhrFields: {
  910. withCredentials: true
  911. },
  912. success: function (res) {
  913. // debug("get acid and cid by avid/bvid result: ");
  914. // debug(res);
  915. let avid = res.data.aid;
  916. let cid = res.data.cid;
  917. let index = currentUrl.indexOf("?p=");
  918. if (index != -1 && res.data.pages.length > 1) {
  919. let p = currentUrl.substring(index + 3);
  920. let endIndex = p.indexOf("&");
  921. if (endIndex != -1) {
  922. p = p.substring(0, endIndex);
  923. }
  924. cid = res.data.pages[p - 1].cid;
  925. }
  926. getBilibiliPlayUrl(avid, cid);
  927. }
  928. })
  929. }
  930. // 获取B站番剧视频链接
  931. function getBilibiliBangumiUrl(epid, eno) {
  932. if (!epid || !eno) {
  933. return;
  934. }
  935. $.ajax({
  936. type: "GET",
  937. url: BILIBILI_API + "/pgc/view/web/season?ep_id=" + epid,
  938. xhrFields: {
  939. withCredentials: true
  940. },
  941. success: function (res) {
  942. // debug("get acid and cid by epid result: ");
  943. // debug(res);
  944. let episodes = res.result.episodes;
  945. if (eno.indexOf('PV') != -1 || eno.indexOf('OP') != -1 || eno.indexOf('ED') != -1) {
  946. return;
  947. }
  948. let episode = episodes[eno - 1];
  949. getBilibiliPlayUrl(episode.aid, episode.cid);
  950. }
  951. })
  952. }
  953. // 获取B站视频播放链接
  954. function getBilibiliPlayUrl(avid, cid) {
  955. // debug("avid: " + avid);
  956. // debug("cid: " + cid);
  957. bilibiliCid = cid;
  958.  
  959. let queryBilibiliVideoUrl = "/x/player/playurl?"
  960. + "qn=&otype=json&fourk=1&fnver=0&fnval=4048"
  961. + "&avid=" + avid
  962. + "&cid=" + cid;
  963. $.ajax({
  964. type: "GET",
  965. url: BILIBILI_API + queryBilibiliVideoUrl,
  966. xhrFields: {
  967. withCredentials: true
  968. },
  969. success: function (res) {
  970. // debug(res);
  971. let dash = res.data.dash;
  972. let hiRes = dash.flac;
  973. let dolby = dash.dolby;
  974. if (hiRes && hiRes.audio) {
  975. // debug("hi-res: on");
  976. currentAudioUrl = hiRes.audio.baseUrl;
  977. } else if (dolby && dolby.audio) {
  978. // debug("dolby: on");
  979. currentAudioUrl = dolby.audio[0].base_url;
  980. } else {
  981. // debug(dash.audio[0].id);
  982. currentAudioUrl = dash.audio[0].baseUrl;
  983. }
  984. let i = 0;
  985. // 限制画质
  986. let qn = BILIBILI_QN[bestQuality];
  987. while (i < dash.video.length && dash.video[i].id > qn) {
  988. i++;
  989. }
  990. let baseUrl = dash.video[i].baseUrl;
  991. let id = dash.video[i].id;
  992. while (i < dash.video.length) {
  993. if (dash.video[i].id != id) {
  994. break;
  995. }
  996. if (dash.video[i].codecid == bilibiliCodecs) {
  997. baseUrl = dash.video[i].baseUrl;
  998. break;
  999. }
  1000. i++;
  1001. }
  1002. currentVideoUrl = baseUrl;
  1003. handler.checkCurrentVideoUrl();
  1004. }
  1005. });
  1006. }
  1007.  
  1008. // B站直播
  1009. const BILIBILI_LIVE = "live.bilibili.com";
  1010. // B站直播 API
  1011. const BILIBILI_LIVE_API = 'https://api.live.bilibili.com';
  1012.  
  1013. const BILIBILI_LIVE_QN = {
  1014. "unlimited": 4,
  1015. "2160p": 4,
  1016. "1440p": 4,
  1017. "1080p": 4,
  1018. "720p": 3,
  1019. "480p": 2,
  1020. };
  1021. class BilibiliLiveHandler extends Handler {
  1022. getCurrentVideoUrl() {
  1023. let url = document.getElementsByTagName("iframe")[0].src;
  1024. let index = url.indexOf("roomid=");
  1025. if (index == -1) {
  1026. return;
  1027. }
  1028. let roomid = url.substring(index + 7);
  1029. roomid = roomid.substring(0, roomid.indexOf("&"));
  1030. let queryBilibiliLiveVideoUrl = "/room/v1/Room/playUrl?"
  1031. + "quality=" + BILIBILI_LIVE_QN[bestQuality]
  1032. + "&cid=" + roomid;
  1033. $.ajax({
  1034. type: "GET",
  1035. url: BILIBILI_LIVE_API + queryBilibiliLiveVideoUrl,
  1036. xhrFields: {
  1037. withCredentials: true
  1038. },
  1039. success: function (res) {
  1040. currentVideoUrl = res.data.durl[0].url;
  1041. handler.checkCurrentVideoUrl();
  1042. }
  1043. });
  1044. }
  1045. getUrlProtocolLink() {
  1046. let urlProtocol = new UrlProtocol;
  1047. urlProtocol.appendTitle();
  1048. urlProtocol.append('--http-header-fields="referer: https://live.bilibili.com, user-agent: ' + navigator.userAgent + '"');
  1049. return urlProtocol.getLink();
  1050. }
  1051. }
  1052.  
  1053. // 低端影视
  1054. const DDRK = "ddys.tv, ddys2.me";
  1055. // 低端影视播放状态
  1056. var ddrkPlayStatus;
  1057.  
  1058. class DdrkHandler extends Handler {
  1059. getCurrentVideoUrl() {
  1060. // 点击播放按钮加载 video 元素
  1061. if (!ddrkPlayStatus) {
  1062. let ddrkPlayButton = document.getElementsByClassName('vjs-big-play-button')[0];
  1063. if (!ddrkPlayButton) {
  1064. // debug("ddrk get play button fail");
  1065. return;
  1066. }
  1067. ddrkPlayButton.click();
  1068. ddrkPlayStatus = true;
  1069. }
  1070. currentVideoUrl = document.getElementById('vjsp_html5_api').src;
  1071. this.checkCurrentVideoUrl();
  1072. }
  1073. getStartTime() {
  1074. return this.getStartTimeByClassName("vjs-time-tooltip");
  1075. }
  1076. }
  1077.  
  1078. // 樱花动漫网
  1079. const DM6CC = "www.6dm.cc, www.996dm.com";
  1080.  
  1081. class Dm6ccHandler extends Handler {
  1082. constructor() {
  1083. super();
  1084. window.addEventListener('message', function (event) {
  1085. currentVideoUrl = event.data;
  1086. this.checkCurrentVideoUrl();
  1087. window.removeEventListener("message", () => { });
  1088. }, false);
  1089. }
  1090. pauseCurrentVideo() {
  1091. document.getElementsByTagName("iframe")[2].contentWindow.postMessage("pause", "https://" + YHDMJX);
  1092. }
  1093. }
  1094.  
  1095. // 风车动漫
  1096. const DMLACC = "www.dmlaa.com";
  1097.  
  1098. class DmlaccHandler extends Handler {
  1099. constructor() {
  1100. super();
  1101. window.addEventListener('message', function (event) {
  1102. currentVideoUrl = event.data;
  1103. this.checkCurrentVideoUrl();
  1104. window.removeEventListener("message", () => { });
  1105. }, false);
  1106. }
  1107. pauseCurrentVideo() {
  1108. document.getElementsByTagName("iframe")[2].contentWindow.postMessage("pause", "https://" + YHDMJX);
  1109. }
  1110. }
  1111.  
  1112. // 樱花动漫网和风车动漫实际播放地址
  1113. const YHDMJX = "danmu.yhdmjx.com";
  1114.  
  1115. class YhdmjxHandler extends Handler {
  1116. constructor() {
  1117. super();
  1118. window.addEventListener("message", function (event) {
  1119. if (event.data == "pause") {
  1120. document.getElementsByTagName('video')[0].pause();
  1121. }
  1122. }, false);
  1123. }
  1124. getCurrentVideoUrl() {
  1125. currentVideoUrl = document.getElementsByTagName('video')[0].src;
  1126. if (this.checkCurrentVideoUrl()) {
  1127. window.parent.postMessage(currentVideoUrl, "*");
  1128. }
  1129. }
  1130. checkCurrentVideoUrl() {
  1131. return this.baseCheckCurrentVideoUrl();
  1132. }
  1133. }
  1134.  
  1135. // 233动漫网
  1136. const DM233 = "www.dm233.me";
  1137.  
  1138. class Dm233Handler extends Handler {
  1139. constructor() {
  1140. super();
  1141. this.videoElement = null;
  1142. }
  1143. getCurrentVideoUrl() {
  1144. let iframe = document.getElementById('id_main_playiframe');
  1145. this.videoElement = iframe.contentWindow.document.getElementsByTagName("video")[0];
  1146. let videoUrl = this.videoElement.src;
  1147. if (videoUrl.startsWith("blob:")) {
  1148. videoUrl = iframe.src;
  1149. let startIndex = videoUrl.indexOf('url=http') + 4;
  1150. let endIndex = videoUrl.indexOf('&getplay_url=');
  1151. videoUrl = decodeURIComponent(videoUrl.substring(startIndex, endIndex));
  1152. }
  1153. currentVideoUrl = videoUrl;
  1154. this.checkCurrentVideoUrl();
  1155. }
  1156. getStartTime() {
  1157. return this.getStartTimeByClassName("dplayer-ptime");
  1158. }
  1159. pauseCurrentVideo() {
  1160. this.videoElement.pause();
  1161. }
  1162. }
  1163.  
  1164. // 樱花动漫
  1165. const DMH8 = "www.dmh8.com";
  1166.  
  1167. class Dmh8Handler extends Handler {
  1168. getCurrentVideoUrl() {
  1169. let iframe = document.getElementsByTagName('iframe')[2];
  1170. let videoUrl = iframe.src;
  1171. let startIndex = videoUrl.indexOf('url=http') + 4;
  1172. let endIndex = videoUrl.indexOf('m3u8') + 4;
  1173. currentVideoUrl = decodeURIComponent(videoUrl.substring(startIndex, endIndex));
  1174. this.checkCurrentVideoUrl();
  1175. }
  1176. getStartTime() {
  1177. return this.getStartTimeByClassName("dplayer-ptime");
  1178. }
  1179. }
  1180.  
  1181. // 樱花动漫
  1182. const YHDMP = "www.yhdmp.net";
  1183.  
  1184. class YhdmpHandler extends Handler {
  1185. constructor() {
  1186. super();
  1187. this.videoElement = null;
  1188. }
  1189. getCurrentVideoUrl() {
  1190. let iframe = document.getElementById('yh_playfram');
  1191. if (!iframe) {
  1192. return;
  1193. }
  1194. this.videoElement = iframe.contentWindow.document.getElementsByTagName("video")[0];
  1195. let videoUrl = iframe.src;
  1196. let startIndex = videoUrl.indexOf('url=http') + 4;
  1197. let endIndex = videoUrl.indexOf('&getplay_url=');
  1198. currentVideoUrl = decodeURIComponent(videoUrl.substring(startIndex, endIndex));
  1199. this.checkCurrentVideoUrl();
  1200. }
  1201. getStartTime() {
  1202. return this.getStartTimeByClassName("dplayer-ptime");
  1203. }
  1204. pauseCurrentVideo() {
  1205. this.videoElement.pause();
  1206. }
  1207. }
  1208.  
  1209. // 巴哈姆特
  1210. const GAMER = "ani.gamer.com.tw";
  1211. // 巴哈姆特 API
  1212. const GAMER_API = "https://ani.gamer.com.tw/ajax/m3u8.php";
  1213.  
  1214. class GamerHandler extends Handler {
  1215. getCurrentVideoUrl() {
  1216. let index = currentUrl.indexOf("sn=") + 3;
  1217. if (index == -1) {
  1218. return;
  1219. }
  1220. let sn = currentUrl.substring(index);
  1221. index = sn.indexOf("&");
  1222. if (index != -1) {
  1223. sn = sn.substring(0, index);
  1224. }
  1225. let device = localStorage.ANIME_deviceid;
  1226. // debug("sn: " + sn + ", device: " + device);
  1227. $.ajax({
  1228. type: "GET",
  1229. url: GAMER_API + "?sn=" + sn + "&device=" + device,
  1230. xhrFields: {
  1231. withCredentials: true
  1232. },
  1233. success: function (res) {
  1234. // debug(res);
  1235. currentVideoUrl = JSON.parse(res).src;
  1236. handler.checkCurrentVideoUrl();
  1237. }
  1238. })
  1239. }
  1240. getStartTime() {
  1241. return this.getStartTimeByClassName("vjs-current-time-display");
  1242. }
  1243. getUrlProtocolLink() {
  1244. let urlProtocol = new UrlProtocol;
  1245. urlProtocol.appendStartTime();
  1246. urlProtocol.appendTitle();
  1247. urlProtocol.appendProxy();
  1248. urlProtocol.append('--http-header-fields="origin: https://ani.gamer.com.tw"');
  1249. return urlProtocol.getLink();
  1250. }
  1251. }
  1252.  
  1253. // alist
  1254. const ALIST = "alist";
  1255.  
  1256. class AlistHandler extends Handler {
  1257. getCurrentVideoUrl() {
  1258. let videoElement = document.getElementsByTagName("video")[0];
  1259. if (!videoElement) {
  1260. return;
  1261. }
  1262. let src = videoElement.src;
  1263. let index = src.indexOf("?");
  1264. if (index != -1) {
  1265. currentVideoUrl = src.substring(0, index + 1) + encodeURIComponent(src.substring(index + 1));
  1266. } else {
  1267. currentVideoUrl = src;
  1268. }
  1269. handler.checkCurrentVideoUrl();
  1270. }
  1271. }
  1272.  
  1273. // 优质资源库
  1274. const HDZYK = "hdzyk.com, 1080zyk1.com, 1080zyk1.com, 1080zyk1.com, 1080zyk1.com, 1080zyk1.com";
  1275.  
  1276. class HdzykHandler extends Handler {
  1277. constructor() {
  1278. super();
  1279. window.addEventListener('message', function (event) {
  1280. currentVideoUrl = event.data;
  1281. this.checkCurrentVideoUrl();
  1282. window.removeEventListener("message", () => { });
  1283. }, false);
  1284. }
  1285. pauseCurrentVideo() {
  1286. document.getElementsByTagName("iframe")[1].contentWindow.postMessage("pause", "https://" + ZYKBF);
  1287. }
  1288. }
  1289.  
  1290. // 优质资源库实际播放地址
  1291. const ZYKBF = "vip.zykbf.com";
  1292.  
  1293. class ZykbfHandler extends Handler {
  1294. constructor() {
  1295. super();
  1296. // 监听父页面暂停指令
  1297. window.addEventListener("message", function (event) {
  1298. if (event.data == "pause") {
  1299. document.getElementsByTagName('video')[0].pause();
  1300. }
  1301. }, false);
  1302. }
  1303. getCurrentVideoUrl() {
  1304. let startIndex = currentUrl.indexOf('url=http') + 4;
  1305. let endIndex = currentUrl.indexOf('m3u8') + 4;
  1306. currentVideoUrl = decodeURIComponent(currentUrl.substring(startIndex, endIndex));
  1307. if (this.checkCurrentVideoUrl()) {
  1308. window.parent.postMessage(currentVideoUrl, "*");
  1309. }
  1310. }
  1311. checkCurrentVideoUrl() {
  1312. return this.baseCheckCurrentVideoUrl();
  1313. }
  1314. }
  1315.  
  1316. // 动漫之家
  1317. const KK151 = "www.kk151.com";
  1318.  
  1319. class Kk151Handler extends Handler {
  1320. constructor() {
  1321. super();
  1322. window.addEventListener('message', function (event) {
  1323. currentVideoUrl = event.data;
  1324. handler.checkCurrentVideoUrl();
  1325. window.removeEventListener("message", () => { });
  1326. }, false);
  1327. }
  1328. }
  1329.  
  1330. // 动漫之家实际播放地址
  1331. const JXM3U8TV = "jx.m3u8.tv, jx.wolongzywcdn.com:65, www.m3u8.tv.cdn.8old.cn, jx.wujinkk.com, www.ikdmjx.com, hls.kuaibofang.com, jx.jxbdzyw.com";
  1332.  
  1333. class Jxm3u8tvHandler extends Handler {
  1334. getCurrentVideoUrl() {
  1335. let startIndex = currentUrl.indexOf('url=http') + 4;
  1336. if (startIndex == 3) {
  1337. startIndex = currentUrl.indexOf('url=%20http') + 7;
  1338. }
  1339. let endIndex = currentUrl.lastIndexOf('m3u8') + 4;
  1340. currentVideoUrl = decodeURIComponent(currentUrl.substring(startIndex, endIndex));
  1341. if (this.checkCurrentVideoUrl()) {
  1342. window.top.postMessage(currentVideoUrl, "*");
  1343. }
  1344. }
  1345. checkCurrentVideoUrl() {
  1346. return this.baseCheckCurrentVideoUrl();
  1347. }
  1348. }
  1349.  
  1350. // LIBVIO
  1351. const LIBVIO = "libvio.fun, www.libvio.me";
  1352.  
  1353. class LibvioHandler extends Handler {
  1354. constructor() {
  1355. super();
  1356. window.addEventListener('message', function (event) {
  1357. currentVideoUrl = event.data;
  1358. handler.checkCurrentVideoUrl();
  1359. window.removeEventListener("message", () => { });
  1360. }, false);
  1361. }
  1362. pauseCurrentVideo() {
  1363. document.getElementsByTagName("iframe")[2].contentWindow.postMessage("pause", "https://" + LIBVIO_PLAYER);
  1364. }
  1365. }
  1366.  
  1367. // LIBVIO 实际播放地址
  1368. const LIBVIO_PLAYER = "sh-data-s02.chinaeast2.cloudapp.chinacloudapi.cn";
  1369.  
  1370. class LibvioPlayerHandler extends Handler {
  1371. constructor() {
  1372. super();
  1373. // 监听父页面暂停指令
  1374. window.addEventListener("message", function (event) {
  1375. if (event.data == "pause") {
  1376. document.getElementsByTagName('video')[0].pause();
  1377. }
  1378. }, false);
  1379. }
  1380. getCurrentVideoUrl() {
  1381. currentVideoUrl = urls;
  1382. if (this.checkCurrentVideoUrl()) {
  1383. window.top.postMessage(currentVideoUrl, "*");
  1384. }
  1385. }
  1386. checkCurrentVideoUrl() {
  1387. return this.baseCheckCurrentVideoUrl();
  1388. }
  1389. }
  1390.  
  1391. // 哔嘀影视
  1392. const BDYS01 = "www.bdys01.com";
  1393.  
  1394. class Bdys01Handler extends Handler {
  1395. getCurrentVideoUrl() {
  1396. currentVideoUrl = document.getElementsByTagName("video")[0].src;
  1397. this.checkCurrentVideoUrl();
  1398. }
  1399. getStartTime() {
  1400. return this.getStartTimeByClassName("dplayer-ptime");
  1401. }
  1402. }
  1403.  
  1404. // 最大尝试次数
  1405. const MAX_TRY_TIME = 8;
  1406. // 定时器
  1407. var timers;
  1408. // 当前页面链接
  1409. var currentUrl;
  1410. // 当前页面域名
  1411. var currentDomain;
  1412. // 当前页面视频链接
  1413. var currentVideoUrl;
  1414. // 当前页面音频链接
  1415. var currentAudioUrl;
  1416. // 巴哈姆特视频时长
  1417. var gamerDurationTime;
  1418.  
  1419. // 初始化当前页信息
  1420. function initCurrentPageInfo() {
  1421. // debug("init current page info ......");
  1422. document.getElementById(BUTTON_DIV).style.display = DISPLAY_NONE;
  1423. if (timers) {
  1424. for (let timer of timers) {
  1425. // debug("clear timer");
  1426. clearTimeout(timer);
  1427. }
  1428. }
  1429. currentUrl = window.location.href;
  1430. currentDomain = window.location.host;
  1431. currentVideoUrl = "";
  1432. ddrkPlayStatus = false;
  1433. }
  1434. // 创建处理器
  1435. function createHandler() {
  1436. // debug("start create handler: " + currentDomain);
  1437. if (BILIBILI.indexOf(currentDomain) != -1) {
  1438. handler = new BilibiliHandler();
  1439. } else if (BILIBILI_LIVE.indexOf(currentDomain) != -1) {
  1440. handler = new BilibiliLiveHandler();
  1441. } else if (DDRK.indexOf(currentDomain) != -1) {
  1442. handler = new DdrkHandler();
  1443. } else if (YOUTUBE.indexOf(currentDomain) != -1) {
  1444. handler = new YoutubeHandler();
  1445. } else if (DM6CC.indexOf(currentDomain) != -1) {
  1446. handler = new Dm6ccHandler();
  1447. } else if (DMLACC.indexOf(currentDomain) != -1) {
  1448. handler = new DmlaccHandler();
  1449. } else if (YHDMJX.indexOf(currentDomain) != -1) {
  1450. handler = new YhdmjxHandler();
  1451. } else if (DM233.indexOf(currentDomain) != -1) {
  1452. handler = new Dm233Handler();
  1453. } else if (DMH8.indexOf(currentDomain) != -1) {
  1454. handler = new Dmh8Handler();
  1455. } else if (YHDMP.indexOf(currentDomain) != -1) {
  1456. handler = new YhdmpHandler();
  1457. } else if (GAMER.indexOf(currentDomain) != -1) {
  1458. handler = new GamerHandler();
  1459. } else if (HDZYK.indexOf(currentDomain) != -1) {
  1460. handler = new HdzykHandler();
  1461. } else if (ZYKBF.indexOf(currentDomain) != -1) {
  1462. handler = new ZykbfHandler();
  1463. } else if (KK151.indexOf(currentDomain) != -1) {
  1464. handler = new Kk151Handler();
  1465. } else if (JXM3U8TV.indexOf(currentDomain) != -1) {
  1466. handler = new Jxm3u8tvHandler();
  1467. } else if (LIBVIO.indexOf(currentDomain) != -1) {
  1468. handler = new LibvioHandler();
  1469. } else if (LIBVIO_PLAYER.indexOf(currentDomain) != -1) {
  1470. handler = new LibvioPlayerHandler();
  1471. } else if (BDYS01.indexOf(currentDomain) != -1) {
  1472. handler = new Bdys01Handler();
  1473. } else {
  1474. if (document.title.toLowerCase().indexOf(ALIST) != -1) {
  1475. handler = new AlistHandler();
  1476. }
  1477. }
  1478. }
  1479. // 刷新视频链接
  1480. function refreshCurrentVideoUrl() {
  1481. // debug("refresh current video url: " + currentVideoUrl);
  1482. // debug("current url: " + currentUrl);
  1483. timers = new Array();
  1484. let tryTime = 0;
  1485. while (tryTime < MAX_TRY_TIME) {
  1486. timers[tryTime] = setTimeout(function () {
  1487. if (!handler.checkCurrentVideoUrl()) {
  1488. handler.getCurrentVideoUrl();
  1489. }
  1490. // debug("timer done");
  1491. }, tryTime * 2000 + 700);
  1492. tryTime = tryTime + 1;
  1493. }
  1494. }
  1495. // 页面变更监听器
  1496. function pageChangeListener() {
  1497. // debug("page change listener");
  1498. let needRefresh = false;
  1499. let newCurrentUrl = window.location.href;
  1500. if (currentUrl != newCurrentUrl) {
  1501. needRefresh = true;
  1502. }
  1503. // 巴哈姆特
  1504. if (!needRefresh && GAMER.indexOf(currentDomain) != -1) {
  1505. let oldGamerDurationTime = gamerDurationTime;
  1506. let durationDiv = document.getElementsByClassName("vjs-duration-display")[0];
  1507. if (durationDiv) {
  1508. gamerDurationTime = durationDiv.innerHTML;
  1509. if (oldGamerDurationTime && oldGamerDurationTime != gamerDurationTime) {
  1510. needRefresh = true;
  1511. }
  1512. }
  1513. }
  1514. if (needRefresh) {
  1515. // debug("page change");
  1516. initCurrentPageInfo();
  1517. refreshCurrentVideoUrl();
  1518. }
  1519. }
  1520. // 初始化
  1521. function init() {
  1522. console.log("Play-With-MPV ......");
  1523. currentUrl = window.location.href;
  1524. currentDomain = window.location.host;
  1525. if (currentUrl.startsWith("https://live.bilibili.com/p/html/live-web-mng/index.html")) {
  1526. console.log("排除页面:" + currentUrl);
  1527. } else {
  1528. // 创建处理器
  1529. createHandler();
  1530. if (handler) {
  1531. // 添加组件和监听器
  1532. appendHTML();
  1533. appendCSS();
  1534. addListener();
  1535.  
  1536. // 初始化页面信息
  1537. initCurrentPageInfo();
  1538. // 刷新视频链接
  1539. refreshCurrentVideoUrl();
  1540. // 定时监听页面变化
  1541. setInterval(pageChangeListener, 700);
  1542. } else {
  1543. console.log("create handler fail");
  1544. }
  1545. }
  1546. }
  1547. init();