Play-With-MPV

使用 MPV 播放网页上的视频

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

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