Play-With-MPV

使用 MPV 播放网页上的视频

目前為 2022-12-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Play-With-MPV
  3. // @name:zh 使用 MPV 播放
  4. // @namespace https://github.com/LuckyPuppy514
  5. // @version 2.3.5
  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://libvio.me/play/*
  48. // @include https://www.libvio.me/play/*
  49. // @include https://sh-data-s02.chinaeast2.cloudapp.chinacloudapi.cn/*.php?url=*
  50. // @include https://p.cfnode1.xyz/*.php?url=*
  51. // @include https://www.bdys01.com/*play/*
  52. // @include https://www.btnull.org/py/*
  53. // @include https://www.pkmp4.com/py/*
  54. // @include https://dick.xfani.com/watch/*
  55. // @include https://m3.moedot.net/muiplayer/?url=*
  56. // @include https://www.mgnacg.com/bangumi/*
  57. // @include https://play.mknacg.top:8585/?url=*
  58. // @include https://spdcat.net/vodplay/*
  59. // @run-at document-end
  60. // @require https://unpkg.com/jquery@3.2.1/dist/jquery.min.js
  61. // @grant GM_setValue
  62. // @grant GM_getValue
  63. // ==/UserScript==
  64.  
  65. 'use strict';
  66. // 注册表版本
  67. const REG_VERSION = "20220907";
  68. // 不输出控制台信息
  69. const NO_TERMINAL = true;
  70.  
  71. // const IS_DEBUG = true;
  72. // function debug(data) {
  73. // if (IS_DEBUG) {
  74. // console.log(data);
  75. // }
  76. // }
  77.  
  78. const DIV =
  79. `
  80. <div id="pwmpv-button-div">
  81. <button id="pwmpv-about-button"></button>
  82. <button id="pwmpv-play-button"></button>
  83. <button id="pwmpv-setting-button"></button>
  84. </div>
  85.  
  86. <div id="pwmpv-about-div">
  87. <span class="pwmpv-title-span">✨ 关于 Play-With-MPV <button class="pwmpv-close-button">❌</button></span>
  88. <table id="pwmpv-about-table">
  89. <tr>
  90. <td colspan="6" class="pwmpv-title-td">使用 MPV 播放网页中的视频(解码 ⬆️ 补帧 着色器 更多💡)</td>
  91. </tr>
  92. <tr>
  93. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV#-%E7%AE%80%E4%BB%8B" target="_blank">支持网站</a></td>
  94. <td colspan="4">
  95. <a href="https://www.lckp.top/play-with-mpv/index.html" target="_blank">👆 请前往导航页查看 👆</a>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td colspan="2"><a href="https://www.lckp.top/archives/mpvnetcm">支持软件</a></td>
  100. <td colspan="2">
  101. <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>
  102. </td>
  103. <td colspan="2">
  104. <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>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV" target="_blank">脚本相关</a></td>
  109. <td colspan="2"><a href="https://greasyfork.org/zh-CN/scripts/444056-play-with-mpv" target="_blank">🆕 版本更新 🆕</a></td>
  110. <td colspan="2"><a href="https://github.com/LuckyPuppy514/Play-With-MPV/issues/new" target="_blank">👻 问题反馈 👻</a></td>
  111. </tr>
  112. </table>
  113. <span class="pwmpv-footer-span">
  114. <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>
  115. <a href="https://www.lckp.top" target="_blank">2022 © LuckyPuppy514</a>
  116. <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>
  117. </span>
  118. </div>
  119.  
  120. <div id="pwmpv-setting-div">
  121. <span class="pwmpv-title-span">🌟 Play-With-MPV 设置 🌟 <button class="pwmpv-close-button">❌</button></span>
  122. <table id="pwmpv-setting-table">
  123. <tr>
  124. <td class="pwmpv-title-td">软件路径</td>
  125. <td colspan="3"><input id="pwmpv-mpv-path-input" type=text placeholder="请输入你的 mpv.com 路径,例如:D://daily//mpvnet//mpvnet.com"></td>
  126. </tr>
  127. <tr>
  128. <td class="pwmpv-title-td">代理设置</td>
  129. <td colspan="3"><input id="pwmpv-proxy-input" type=text placeholder="请输入你的 http 或 socks 代理,例如:http://127.0.0.1:10809"></td>
  130. </tr>
  131. <tr>
  132. <td class="pwmpv-title-td">最高画质</td>
  133. <td>
  134. <select id="pwmpv-best-quality-select">
  135. <option value="unlimited" selected>无限制</option>
  136. <option value="2160p">2160p</option>
  137. <option value="1440p">1440p</option>
  138. <option value="1080p">1080p</option>
  139. <option value="720p">720p</option>
  140. <option value="480p">480p</option>
  141. </select>
  142. <span class="tip-span">限B站和油管</span>
  143. </td>
  144. <td class="pwmpv-title-td">视频编码</td>
  145. <td>
  146. <select id="pwmpv-bilibili-codecs-select">
  147. <option value="12" selected>HEVC</option>
  148. <option value="13">AV1</option>
  149. <option value="7">AVC</option>
  150. </select>
  151. <span class="tip-span">限B站</span>
  152. </td>
  153. </tr>
  154. <tr>
  155. <td colspan="4">
  156. <button id="pwmpv-save-button">保存设置</button>
  157. <button id="pwmpv-download-button" data-tip="请先输入 MPV 路径,并保存设置">下载注册表</button>
  158. </td>
  159. </tr>
  160. </table>
  161. <span class="pwmpv-footer-span">
  162. <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>
  163. <a href="https://www.lckp.top" target="_blank">2022 © LuckyPuppy514</a>
  164. <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>
  165. </span>
  166. </div>
  167.  
  168. <iframe id="firefox-iframe" src="about:blank" style="display:none;"></iframe>
  169. `
  170. const CSS =
  171. `
  172. .pwmpv-close-button {
  173. position: absolute;
  174. top: 3px;
  175. right: 3px;
  176. height: 25px;
  177. width: 40px;
  178. border: none;
  179. font-size: 18px;
  180. background-color: rgba(0, 0, 0, 0);
  181. line-height: 0px;
  182. }
  183. .pwmpv-close-button:hover {
  184. background-color: rgba(0, 0, 0, 0.3);
  185. cursor: pointer;
  186. }
  187. #pwmpv-button-div {
  188. display: none;
  189. }
  190. .pwmpv-title-span {
  191. padding-top: 15px;
  192. font-size: 15px;
  193. }
  194. #pwmpv-about-button {
  195. position: fixed;
  196. bottom: 58px;
  197. left: 8px;
  198. z-index: 999998;
  199.  
  200. width: 25px;
  201. height: 25px;
  202. border: none;
  203. border-radius: 50%;
  204. background-size: cover;
  205. background-color: rgba(255, 255, 255, 0);
  206. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/about-pink.png);
  207. }
  208. #pwmpv-about-button:hover {
  209. bottom: 56px;
  210. left: 6px;
  211. z-index: 999999;
  212.  
  213. width: 27px;
  214. height: 27px;
  215. cursor: pointer;
  216. }
  217. #pwmpv-about-div {
  218. position: fixed;
  219. top: 40%;
  220. left: 50%;
  221. transform: translate(-50%, -50%);
  222. z-index: 999999;
  223.  
  224. width: 600px;
  225. height: 320px;
  226. border: 6px solid rgba(255, 255, 255, 0.5);
  227. background-color: rgba(234, 122, 153, 1);
  228. display: none;
  229. flex-direction: column;
  230. border-radius: 6px;
  231. align-items: center;
  232. color: rgba(255, 255, 255, 1);
  233. }
  234. #pwmpv-about-table {
  235. margin-top: 10px;
  236. width: 570px;
  237. height: 240px;
  238. border-radius: 5px !important;
  239. border: 3px solid rgba(255, 255, 255, 1) !important;
  240. text-align: center;
  241. }
  242. #pwmpv-about-table td {
  243. border: 2px solid rgba(255, 255, 255, 0.5);
  244. padding: 0px 15px 0px 15px;
  245. }
  246. #pwmpv-about-div a {
  247. color: rgba(255, 255, 255, 1);
  248. text-decoration: none;
  249. font-size: 14px;
  250. display: inline-block;
  251. }
  252.  
  253. #pwmpv-play-button {
  254. position: fixed;
  255. bottom: 16px;
  256. left: 20px;
  257. z-index: 999999;
  258.  
  259. width: 50px;
  260. height: 50px;
  261. border: none;
  262. border-radius: 50%;
  263. background-size: cover;
  264. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/mpvnet.png);
  265. cursor: pointer;
  266. }
  267. #pwmpv-play-button:hover {
  268. bottom: 14px;
  269. left: 18px;
  270.  
  271. width: 54px;
  272. height: 54px;
  273. cursor: pointer;
  274. }
  275.  
  276. #pwmpv-setting-button {
  277. position: fixed;
  278. bottom: 56px;
  279. left: 58px;
  280. z-index: 999998;
  281.  
  282. width: 28px;
  283. height: 28px;
  284. border: none;
  285. border-radius: 50%;
  286. background-size: cover;
  287. background-color: rgba(255, 255, 255, 0);
  288. background-image: url(https://www.lckp.top/gh/LuckyPuppy514/pic-bed/common/lx-setting.png);
  289. }
  290. #pwmpv-setting-button:hover {
  291. bottom: 54px;
  292. left: 56px;
  293. z-index: 999999;
  294.  
  295. width: 32px;
  296. height: 32px;
  297. cursor: pointer;
  298. }
  299. #pwmpv-setting-div {
  300. position: fixed;
  301. top: 40%;
  302. left: 50%;
  303. transform: translate(-50%, -50%);
  304. z-index: 999999;
  305.  
  306. width: 600px;
  307. height: 320px;
  308. border: 6px solid rgba(255, 255, 255, 0.5);
  309. background-color: rgba(65, 146, 247, 1);
  310. display: none;
  311. flex-direction: column;
  312. border-radius: 6px;
  313. align-items: center;
  314. color: rgba(255, 255, 255, 1);
  315. }
  316. #pwmpv-setting-table {
  317. margin-top: 10px;
  318. width: 570px;
  319. height: 240px;
  320. border-radius: 5px !important;
  321. border: 3px solid rgba(255, 255, 255, 1) !important;
  322. text-align: left;
  323. }
  324. #pwmpv-setting-table td {
  325. font-size: 14px;
  326. border: 0px solid rgba(255, 255, 255, 0.5);
  327. padding-top: 18px;
  328. }
  329. .tip-span {
  330. font-size: xx-small;
  331. color: yellow;
  332. position: fixed;
  333. padding-left: 5px;
  334. padding-top: 9px;
  335. }
  336. .pwmpv-title-td {
  337. width: 90px;
  338. height: 30px;
  339. border: none;
  340. font-size: 14px;
  341. padding-left: 12px;
  342. text-align: center;
  343. }
  344. #pwmpv-setting-table input {
  345. font-size: 14px;
  346. width: 430px;
  347. height: 26px;
  348. border: none;
  349. outline: none;
  350. padding-left: 6px;
  351. border-radius: 2px;
  352. color: rgba(0, 0, 0, 1);
  353. background-color: rgba(255, 255, 255, 0.9);
  354. }
  355. #pwmpv-bilibili-codecs-select,
  356. #pwmpv-best-quality-select {
  357. width: 90px;
  358. height: 25px;
  359. border: none;
  360. outline: none;
  361. padding-left: 6px;
  362. border-radius: 2px;
  363. color: rgba(0, 0, 0, 1);
  364. background-color: rgba(255, 255, 255, 0.9);
  365. }
  366. #pwmpv-save-button {
  367. font-size: 14px;
  368. margin-left: 105px;
  369. width: 300px;
  370. height: 30px;
  371. border: none;
  372. border-radius: 3px;
  373. color: rgba(255, 255, 255, 1);
  374. background-color: rgba(0, 255, 50, 0.6);
  375. }
  376. #pwmpv-save-button:hover {
  377. background-color: rgba(0, 255, 0, 0.8);
  378. cursor: pointer;
  379. }
  380. .pwmpv-download-enable:hover {
  381. background-color: rgba(0, 255, 0, 0.8);
  382. cursor: pointer;
  383. }
  384. .pwmpv-download-disable:hover {
  385. cursor: pointer;
  386. }
  387. .pwmpv-download-enable {
  388. font-size: x-small;
  389. margin-left: 10px;
  390. width: 80px;
  391. height: 30px;
  392. border: none;
  393. border-radius: 3px;
  394. color: rgba(255, 255, 255, 1);
  395. background-color: rgba(0, 255, 50, 0.6);
  396.  
  397. }
  398. .pwmpv-download-disable {
  399. font-size: x-small;
  400. margin-left: 10px;
  401. width: 80px;
  402. height: 30px;
  403. border: none;
  404. border-radius: 3px;
  405. color: rgba(255, 255, 255, 1);
  406. background-color: rgba(0, 0, 0, 0.5);
  407. }
  408. .pwmpv-tips-td {
  409. color: rgba(255, 255, 255, 1);
  410. font-size: 12px;
  411. }
  412. .pwmpv-footer-span {
  413. margin-top: 10px;
  414. margin-bottom: 10px;
  415. color: rgba(255, 255, 255, 1);
  416. }
  417. .pwmpv-footer-span a {
  418. color: rgba(255, 255, 255, 1);
  419. text-decoration: none;
  420. font-size: 14px;
  421. margin-bottom: 1px;
  422. display: inline-block;
  423. }
  424. .pwmpv-footer-icon {
  425. width: 18px;
  426. height: 18px;
  427. margin-left: 5px;
  428. margin-right: 5px;
  429. margin-bottom: -2px;
  430. }
  431. .pwmpv-support-url-icon {
  432. width: 30px;
  433. height: 30px;
  434. margin-left: 8px;
  435. margin-right: 8px;
  436. }
  437. .pwmpv-support-url-icon-small {
  438. width: 25px;
  439. height: 25px;
  440. margin-left: 8px;
  441. margin-right: 8px;
  442. margin-bottom: 2px;
  443. }
  444. .pwmpv-support-url-icon-large {
  445. width: 37px;
  446. height: 37px;
  447. margin-left: 8px;
  448. margin-right: 8px;
  449. margin-bottom: -4px;
  450. }
  451. `
  452.  
  453. const REG =
  454. `Windows Registry Editor Version 5.00
  455. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Google\\Chrome]
  456. "ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
  457.  
  458. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Edge]
  459. "ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
  460.  
  461. [HKEY_CLASSES_ROOT\\mpv]
  462. @="mpv Protocol"
  463. "URL Protocol"=""
  464.  
  465. [HKEY_CLASSES_ROOT\\mpv\\DefaultIcon]
  466. @=""
  467.  
  468. [HKEY_CLASSES_ROOT\\mpv\\shell]
  469. @=""
  470.  
  471. [HKEY_CLASSES_ROOT\\mpv\\shell\\open]
  472. @=""
  473.  
  474. [HKEY_CLASSES_ROOT\\mpv\\shell\\open\\command]
  475. @="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!\\""
  476. `
  477.  
  478. // element id
  479. const BUTTON_DIV = "pwmpv-button-div";
  480. const ABOUT_BUTTON_ID = "pwmpv-about-button";
  481. const ABOUT_DIV_ID = "pwmpv-about-div";
  482. const PLAY_BUTTON_ID = "pwmpv-play-button";
  483. const SETTING_BUTTON_ID = "pwmpv-setting-button";
  484. const SETTING_DIV_ID = "pwmpv-setting-div";
  485. const MPV_PATH_INPUT_ID = "pwmpv-mpv-path-input";
  486. const PROXY_INPUT_ID = "pwmpv-proxy-input";
  487. const BILIBILI_CODECS_SELECT_ID = "pwmpv-bilibili-codecs-select";
  488. const BEST_QUALITY_SELECT_ID = "pwmpv-best-quality-select";
  489. const SAVE_BUTTON_ID = "pwmpv-save-button";
  490. const DOWNLOAD_BUTTON_ID = "pwmpv-download-button";
  491. // display
  492. const DISPLAY_NONE = "none";
  493. const DISPLAY_FLEX = "flex";
  494. // GM value key
  495. const KEY_MPV_PATH = "MPV_PATH";
  496. const KEY_PROXY = "PROXY";
  497. const KEY_REG_VERSION = "REG_VERSION";
  498. const KEY_BILIBILI_CODECS = "BILIBILI_CODECS";
  499. const BILIBILI_CODECS_HEVC = "12";
  500. const KEY_BEST_QUALITY = "BEST_QUALITY";
  501. const BEST_QUALITY_UNLIMITED = "unlimited";
  502.  
  503. function appendHTML() {
  504. var div = document.createElement("div");
  505. div.innerHTML = DIV.trim();
  506. document.body.appendChild(div);
  507. }
  508. function appendCSS() {
  509. var css = document.createElement("style");
  510. css.innerHTML = CSS.trim();
  511. document.head.appendChild(css);
  512. }
  513. var bilibiliCodecs;
  514. var bestQuality;
  515. var isFullScreen = false;
  516. function addListener() {
  517. // 关于
  518. var aboutButton = document.getElementById(ABOUT_BUTTON_ID);
  519. var aboutDiv = document.getElementById(ABOUT_DIV_ID);
  520. aboutButton.onclick = function () {
  521. if (aboutDiv.style.display != DISPLAY_FLEX) {
  522. aboutDiv.style.display = DISPLAY_FLEX;
  523. settingDiv.style.display = DISPLAY_NONE;
  524. } else {
  525. aboutDiv.style.display = DISPLAY_NONE;
  526. }
  527. };
  528.  
  529. // 播放
  530. var playButton = document.getElementById(PLAY_BUTTON_ID);
  531. playButton.onclick = function () {
  532. let regVersion = GM_getValue(KEY_REG_VERSION);
  533. if (!regVersion || regVersion != REG_VERSION) {
  534. showSettingDiv();
  535. Toast("🆕 注册表配置有更新,请重新下载并添加注册表信息 🆕");
  536. return;
  537. }
  538. handler.playCurrentVideoWithMPV();
  539. }
  540.  
  541. // 设置
  542. var settingButton = document.getElementById(SETTING_BUTTON_ID);
  543. var bilibiliCodecsSelect = document.getElementById(BILIBILI_CODECS_SELECT_ID);
  544. var bestQualitySelect = document.getElementById(BEST_QUALITY_SELECT_ID);
  545. var saveButton = document.getElementById(SAVE_BUTTON_ID);
  546. var downloadButton = document.getElementById(DOWNLOAD_BUTTON_ID);
  547. var settingDiv = document.getElementById(SETTING_DIV_ID);
  548. var mpvPathInput = document.getElementById(MPV_PATH_INPUT_ID);
  549. var proxyInput = document.getElementById(PROXY_INPUT_ID);
  550. settingButton.onclick = function () {
  551. if (settingDiv.style.display != DISPLAY_FLEX) {
  552. showSettingDiv();
  553. aboutDiv.style.display = DISPLAY_NONE;
  554. } else {
  555. settingDiv.style.display = DISPLAY_NONE;
  556. }
  557. };
  558. bilibiliCodecs = GM_getValue(KEY_BILIBILI_CODECS);
  559. if (!bilibiliCodecs) {
  560. bilibiliCodecs = BILIBILI_CODECS_HEVC;
  561. GM_setValue(KEY_BILIBILI_CODECS, bilibiliCodecs);
  562. }
  563. bilibiliCodecsSelect.onchange = function () {
  564. bilibiliCodecs = this.value;
  565. };
  566. bestQuality = GM_getValue(KEY_BEST_QUALITY);
  567. if (!bestQuality) {
  568. bestQuality = BEST_QUALITY_UNLIMITED;
  569. GM_setValue(KEY_BEST_QUALITY, bestQuality);
  570. }
  571. bestQualitySelect.onchange = function () {
  572. bestQuality = this.value;
  573. };
  574. saveButton.onclick = function () {
  575. let oldMpvPath = GM_getValue(KEY_MPV_PATH);
  576. let mpvPath = mpvPathInput.value;
  577. let proxy = proxyInput.value;
  578. if (!mpvPath) {
  579. downloadButton.className = "pwmpv-download-disable";
  580. Toast("⚠️ 软件路径不能为空 ⚠️", 2000);
  581. return;
  582. }
  583. if (/.*[\u4e00-\u9fa5]+.*$/.test(mpvPath)) {
  584. downloadButton.className = "pwmpv-download-disable";
  585. Toast("⚠️ 软件路径不能包含中文 ⚠️", 2000);
  586. return;
  587. }
  588. mpvPath = mpvPath.replace(/[\\|/]+/g, "//");
  589. if (!mpvPath.endsWith(".com")) {
  590. if (!mpvPath.endsWith("//")) {
  591. mpvPath = mpvPath + "//";
  592. }
  593. if (mpvPath.endsWith("mpvnet//")) {
  594. mpvPath = mpvPath + "mpvnet.com";
  595. } else if (mpvPath.endsWith("mpv//") || mpvPath.endsWith("mpv-lazy//")) {
  596. mpvPath = mpvPath + "mpv.com";
  597. } else {
  598. Toast("⚠️ 软件路径错误,正确示例:D:/daily/mpvnet/mpvnet.com ⚠️", 3000)
  599. return;
  600. }
  601. }
  602. mpvPathInput.value = mpvPath;
  603. GM_setValue(KEY_MPV_PATH, mpvPath);
  604. GM_setValue(KEY_PROXY, proxy);
  605. if (bilibiliCodecs != GM_getValue(KEY_BILIBILI_CODECS) || bestQuality != GM_getValue(KEY_BEST_QUALITY)) {
  606. GM_setValue(KEY_BILIBILI_CODECS, bilibiliCodecs);
  607. GM_setValue(KEY_BEST_QUALITY, bestQuality);
  608. // 重新获取视频链接
  609. initCurrentPageInfo();
  610. refreshCurrentVideoUrl();
  611. }
  612. // debug(proxy);
  613. downloadButton.className = "pwmpv-download-enable";
  614. if (oldMpvPath != mpvPath) {
  615. Toast("🔥 请重新添加注册表信息 🔥", 3000);
  616. downloadButton.click();
  617. } else {
  618. Toast("✅ 保存成功 ✅", 2000);
  619. }
  620. };
  621. downloadButton.onclick = function () {
  622. // 生成注册表信息
  623. var a = document.createElement('a');
  624. var blob = new Blob([REG.replace(KEY_MPV_PATH, GM_getValue(KEY_MPV_PATH))], { 'type': 'application/octet-stream' });
  625. a.href = window.URL.createObjectURL(blob);
  626. a.download = "mpv.reg";
  627. a.click();
  628. GM_setValue(KEY_REG_VERSION, REG_VERSION);
  629. }
  630. var closeButtons = document.getElementsByClassName("pwmpv-close-button");
  631. for (let closeButton of closeButtons) {
  632. closeButton.onclick = function () {
  633. aboutDiv.style.display = DISPLAY_NONE;
  634. settingDiv.style.display = DISPLAY_NONE;
  635. }
  636. }
  637. // 全屏
  638. document.addEventListener("fullscreenchange", () => {
  639. if (document.fullscreenElement) {
  640. isFullScreen = true;
  641. document.getElementById(BUTTON_DIV).style.display = DISPLAY_NONE;
  642. } else {
  643. isFullScreen = false;
  644. handler.checkCurrentVideoUrl();
  645. }
  646. });
  647. }
  648. // 显示设置窗口
  649. function showSettingDiv() {
  650. var downloadButton = document.getElementById(DOWNLOAD_BUTTON_ID);
  651. var settingDiv = document.getElementById(SETTING_DIV_ID);
  652. var bilibiliCodecsSelect = document.getElementById(BILIBILI_CODECS_SELECT_ID);
  653. var bestQualitySelect = document.getElementById(BEST_QUALITY_SELECT_ID);
  654. var mpvPathInput = document.getElementById(MPV_PATH_INPUT_ID);
  655. var proxyInput = document.getElementById(PROXY_INPUT_ID);
  656. let mpvPath = GM_getValue(KEY_MPV_PATH);
  657. let proxy = GM_getValue(KEY_PROXY);
  658. bilibiliCodecs = GM_getValue(KEY_BILIBILI_CODECS);
  659. bestQuality = GM_getValue(KEY_BEST_QUALITY);
  660. if (mpvPath) {
  661. mpvPathInput.value = mpvPath;
  662. downloadButton.className = "pwmpv-download-enable";
  663. } else {
  664. downloadButton.className = "pwmpv-download-disable";
  665. }
  666. if (proxy) {
  667. proxyInput.value = proxy;
  668. }
  669. bilibiliCodecsSelect.value = bilibiliCodecs;
  670. bestQualitySelect.value = bestQuality;
  671. settingDiv.style.display = DISPLAY_FLEX;
  672. }
  673. // 显示消息
  674. function Toast(msg, duration) {
  675. duration = isNaN(duration) ? 3000 : duration;
  676. var m = document.createElement('div');
  677. m.innerHTML = msg;
  678. 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;";
  679. document.body.appendChild(m);
  680. setTimeout(function () {
  681. var d = 0.5;
  682. m.style.opacity = '0';
  683. setTimeout(function () { document.body.removeChild(m) }, d * 1000);
  684. }, duration);
  685. }
  686.  
  687. // mpv urlprotocol
  688. const MPV_URLPROTOCOL = "mpv://";
  689. // mpv urlprotocol link
  690. class UrlProtocol {
  691. constructor() {
  692. this.link = MPV_URLPROTOCOL + '"' + currentVideoUrl + '"';
  693. this.appendNoTerminal();
  694. this.needAppendTitle = false;
  695. }
  696. // 添加参数
  697. append(param) {
  698. this.link = this.link + ' ' + param;
  699. }
  700. // 禁止命令行输出及控制
  701. appendNoTerminal() {
  702. if (NO_TERMINAL) {
  703. this.append('--no-terminal');
  704. }
  705. }
  706. // 开始时间(如果 mpv 开启了退出时记住播放状态,则记住状态优先级更高)
  707. appendStartTime() {
  708. let startTime = handler.getStartTime();
  709. if (startTime) {
  710. this.append('--ss="' + startTime + '"');
  711. }
  712. }
  713. // 标题
  714. appendTitle() {
  715. this.needAppendTitle = true;
  716. }
  717. // 代理
  718. appendProxy() {
  719. let proxy = GM_getValue(KEY_PROXY);
  720. if (proxy) {
  721. this.append('--http-proxy=' + proxy + ' --ytdl-raw-options=proxy=[' + proxy + ']');
  722. }
  723. }
  724. // 最终链接
  725. getLink() {
  726. if (this.needAppendTitle) {
  727. // 限制标题长度(url 有长度限制)
  728. let maxLength = 1900 - this.link.length;
  729. let title = encodeURIComponent(document.title);
  730. if (title.length > maxLength) {
  731. title = title.substring(0, maxLength) + '...';
  732. }
  733. this.append('--force-media-title="' + title + '"');
  734. }
  735. return this.link;
  736. }
  737. }
  738.  
  739. // 网页处理器
  740. var handler;
  741. class Handler {
  742. // 获取当前视频链接
  743. getCurrentVideoUrl() { }
  744. // 获取开始时间
  745. getStartTime() { return null; }
  746. // 暂停网页视频
  747. pauseCurrentVideo() { document.getElementsByTagName("video")[0].pause(); }
  748. // 获取调用 mpv 链接
  749. getUrlProtocolLink() {
  750. let urlProtocol = new UrlProtocol;
  751. urlProtocol.appendStartTime();
  752. urlProtocol.appendTitle();
  753. return urlProtocol.getLink();
  754. }
  755. // 校验视频链接是否有效
  756. checkCurrentVideoUrl() {
  757. if (this.baseCheckCurrentVideoUrl()) {
  758. if (!isFullScreen) {
  759. document.getElementById(BUTTON_DIV).style.display = DISPLAY_FLEX;
  760. }
  761. return true;
  762. }
  763. return false;
  764. }
  765.  
  766. // 调用 mpv 播放
  767. playCurrentVideoWithMPV() {
  768. window.open(this.getUrlProtocolLink(), "_self");
  769. let i = 0;
  770. while (i < 3) {
  771. i++;
  772. setTimeout(function () {
  773. handler.pauseCurrentVideo();
  774. }, 2000 * i);
  775. }
  776. }
  777. // 根据 class name 获取播放时间
  778. getStartTimeByClassName(className) {
  779. let startTimeElements = document.getElementsByClassName(className);
  780. let length = startTimeElements.length;
  781. if (length > 0) {
  782. return startTimeElements[length - 1].innerHTML;
  783. }
  784. return null;
  785. }
  786. // 视频链接基础校验
  787. baseCheckCurrentVideoUrl() {
  788. // debug("current video url: " + currentVideoUrl);
  789. if (!currentVideoUrl || !currentVideoUrl.startsWith("http")
  790. || currentVideoUrl.indexOf("yun.66dm.net") != -1
  791. || currentVideoUrl.indexOf("www.xmfans.me") != -1
  792. || currentVideoUrl.indexOf("sod.bunediy.com") != -1
  793. || currentVideoUrl.indexOf("c2.monidai.com") != -1) {
  794. return false;
  795. }
  796. return true;
  797. }
  798. }
  799.  
  800. // 油管
  801. const YOUTUBE = "www.youtube.com";
  802. const YOUTUBE_QN = {
  803. "unlimited": "",
  804. "2160p": "--ytdl-format=bestvideo[height<=?2160]%2Bbestaudio/best",
  805. "1440p": "--ytdl-format=bestvideo[height<=?1440]%2Bbestaudio/best",
  806. "1080p": "--ytdl-format=bestvideo[height<=?1080]%2Bbestaudio/best",
  807. "720p": "--ytdl-format=bestvideo[height<=?720]%2Bbestaudio/best",
  808. "480p": "--ytdl-format=bestvideo[height<=?480]%2Bbestaudio/best",
  809. };
  810. class YoutubeHandler extends Handler {
  811. getCurrentVideoUrl() {
  812. currentVideoUrl = currentUrl;
  813. this.checkCurrentVideoUrl();
  814. }
  815. getStartTime() {
  816. return this.getStartTimeByClassName("ytp-time-current");
  817. }
  818. getUrlProtocolLink() {
  819. let urlProtocol = new UrlProtocol;
  820. urlProtocol.appendStartTime();
  821. urlProtocol.appendProxy();
  822. if (bestQuality) {
  823. urlProtocol.append(YOUTUBE_QN[bestQuality]);
  824. }
  825. return urlProtocol.getLink();
  826. }
  827. checkCurrentVideoUrl() {
  828. if (currentUrl.indexOf("/watch") == -1 && currentUrl.indexOf("/playlist") == -1) {
  829. return false;
  830. }
  831. return super.checkCurrentVideoUrl();
  832. }
  833. }
  834.  
  835. // B站
  836. const BILIBILI = "www.bilibili.com";
  837. // B站 API
  838. const BILIBILI_API = 'https://api.bilibili.com';
  839. // cid 用于传递给 mpv 获取弹幕
  840. var bilibiliCid;
  841. const BILIBILI_QN = {
  842. "unlimited": 127,
  843. "2160p": 126,
  844. "1440p": 116,
  845. "1080p": 116,
  846. "720p": 74,
  847. "480p": 32,
  848. };
  849. class BilibiliHandler extends Handler {
  850. getCurrentVideoUrl() {
  851. let index = currentUrl.indexOf('/video/');
  852. if (index != -1) {
  853. // 投稿视频
  854. let param = "";
  855. let videoId = currentUrl.substring(index + 7);
  856. if (videoId.startsWith("BV")) {
  857. param = "bvid=" + videoId.match(/BV([0-9a-zA-Z]+)/)[1];
  858. } else if (videoId.startsWith("av")) {
  859. param = "aid=" + videoId.match(/av([0-9]+)/)[1];
  860. } else {
  861. // debug("bilibili video id invalid: " + videoId);
  862. return;
  863. }
  864. // debug("bilibili video id: " + param);
  865. getBilibiliVideoUrl(param);
  866.  
  867. } else {
  868. // 番剧
  869. let visitedLi = document.getElementsByClassName("ep-item cursor visited")[0];
  870. visitedLi = visitedLi ? visitedLi : document.getElementsByClassName('ep-item cursor')[0];
  871. let epid = visitedLi.getElementsByTagName('a')[0].href.match(/ep(\d+)/)[1];
  872. let className = visitedLi.parentElement.parentElement.className;
  873. getBilibiliBangumiUrl(epid, className);
  874. }
  875. }
  876. getStartTime() {
  877. let startTime = this.getStartTimeByClassName("bpx-player-ctrl-time-current");
  878. if (!startTime) {
  879. startTime = this.getStartTimeByClassName("squirtle-video-time-now");
  880. }
  881. return startTime;
  882. }
  883. getUrlProtocolLink() {
  884. let urlProtocol = new UrlProtocol;
  885. urlProtocol.appendStartTime();
  886. urlProtocol.appendTitle();
  887. urlProtocol.append('--audio-file="' + currentAudioUrl + '"');
  888. urlProtocol.append('--http-header-fields="referer: https://www.bilibili.com, user-agent: ' + navigator.userAgent + '"');
  889. urlProtocol.append('--script-opts="cid=' + bilibiliCid + '"');
  890. return urlProtocol.getLink();
  891. }
  892. }
  893. // 获取B站投稿视频链接
  894. function getBilibiliVideoUrl(param) {
  895. $.ajax({
  896. type: "GET",
  897. url: BILIBILI_API + "/x/web-interface/view?" + param,
  898. xhrFields: {
  899. withCredentials: true
  900. },
  901. success: function (res) {
  902. // debug("get acid and cid by avid/bvid result: ");
  903. // debug(res);
  904. let avid = res.data.aid;
  905. let cid = res.data.cid;
  906. let index = currentUrl.indexOf("?p=");
  907. if (index != -1 && res.data.pages.length > 1) {
  908. let p = currentUrl.substring(index + 3);
  909. let endIndex = p.indexOf("&");
  910. if (endIndex != -1) {
  911. p = p.substring(0, endIndex);
  912. }
  913. cid = res.data.pages[p - 1].cid;
  914. }
  915. getBilibiliPlayUrl(avid, cid);
  916. }
  917. })
  918. }
  919. // 获取B站番剧视频链接
  920. function getBilibiliBangumiUrl(epid, className) {
  921. // debug('epid: ' + epid);
  922. // debug('className: ' + className);
  923. $.ajax({
  924. type: "GET",
  925. url: BILIBILI_API + "/pgc/view/web/season?ep_id=" + epid,
  926. xhrFields: {
  927. withCredentials: true
  928. },
  929. success: function (res) {
  930. // debug("get acid and cid by epid result: ");
  931. // debug(res);
  932. var currentEpisode;
  933. var section = new Array;
  934. if (className.indexOf("list-wrapper") != -1) {
  935. section[0] = { episodes: res.result.episodes };
  936. } else {
  937. section = res.result.section;
  938. }
  939. for (let i = 0; i < section.length; i++) {
  940. let episodes = section[i].episodes;
  941. for (const episode of episodes) {
  942. if (episode.id == epid) {
  943. currentEpisode = episode;
  944. break;
  945. }
  946. }
  947. if (currentEpisode) {
  948. break;
  949. }
  950. }
  951. getBilibiliPlayUrl(currentEpisode.aid, currentEpisode.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. return urlProtocol.getLink();
  1051. }
  1052. }
  1053.  
  1054. // 低端影视
  1055. const DDRK = "ddys.tv, ddys2.me";
  1056. // 低端影视播放状态
  1057. var ddrkPlayStatus;
  1058.  
  1059. class DdrkHandler extends Handler {
  1060. getCurrentVideoUrl() {
  1061. // 点击播放按钮加载 video 元素
  1062. if (!ddrkPlayStatus) {
  1063. let ddrkPlayButton = document.getElementsByClassName('vjs-big-play-button')[0];
  1064. if (!ddrkPlayButton) {
  1065. // debug("ddrk get play button fail");
  1066. return;
  1067. }
  1068. ddrkPlayButton.click();
  1069. ddrkPlayStatus = true;
  1070. }
  1071. currentVideoUrl = document.getElementById('vjsp_html5_api').src;
  1072. this.checkCurrentVideoUrl();
  1073. }
  1074. getStartTime() {
  1075. document.title = document.getElementsByClassName("post-title")[0].textContent + document.getElementsByClassName("wp-playlist-playing")[0].textContent
  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') + 5;
  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') + 5;
  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, 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, p.cfnode1.xyz";
  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 PKMP4 = "www.pkmp4.com";
  1422.  
  1423. class Pkmp4Handler extends Handler {
  1424. getCurrentVideoUrl() {
  1425. currentVideoUrl = player_aaaa.url;
  1426. handler.checkCurrentVideoUrl();
  1427. }
  1428. pauseCurrentVideo() {
  1429. document.getElementsByTagName("iframe")[2].contentWindow.document.getElementsByTagName("video")[0].pause();
  1430. }
  1431. }
  1432.  
  1433. // 稀饭动漫
  1434. const XFANI = "dick.xfani.com";
  1435.  
  1436. class XfaniHandler extends Handler {
  1437. constructor() {
  1438. super();
  1439. window.addEventListener('message', function (event) {
  1440. currentVideoUrl = event.data;
  1441. handler.checkCurrentVideoUrl();
  1442. window.removeEventListener("message", () => { });
  1443. }, false);
  1444. }
  1445. pauseCurrentVideo() {
  1446. document.getElementsByTagName("iframe")[2].contentWindow.postMessage("pause", "https://" + XFANI_PLAYER);
  1447. }
  1448. }
  1449.  
  1450. // 稀饭动漫实际播放地址
  1451. const XFANI_PLAYER = "m3.moedot.net";
  1452.  
  1453. class XfaniPlayerHandler extends Handler {
  1454. constructor() {
  1455. super();
  1456. window.addEventListener("message", function (event) {
  1457. if (event.data == "pause") {
  1458. document.getElementsByTagName('video')[0].pause();
  1459. }
  1460. }, false);
  1461. }
  1462. getCurrentVideoUrl() {
  1463. if (config.url.indexOf(".m3u8") > 0 || config.url.indexOf(".mp4") > 0 || config.url.indexOf(".flv") > 0) {
  1464. currentVideoUrl = config.url;
  1465. if (handler.checkCurrentVideoUrl()) {
  1466. window.top.postMessage(currentVideoUrl, "*");
  1467. }
  1468. } else {
  1469. $.ajax({
  1470. type: "POST",
  1471. url: "api_config.php",
  1472. data: { "url": config.url, "time": config.time, "key": config.key, "title": config.title },
  1473. success: function (res) {
  1474. if (res.code == "200") {
  1475. currentVideoUrl = res.url;
  1476. if (handler.checkCurrentVideoUrl()) {
  1477. window.top.postMessage(currentVideoUrl, "*");
  1478. }
  1479. }
  1480. }
  1481. });
  1482. }
  1483. }
  1484. checkCurrentVideoUrl() {
  1485. return this.baseCheckCurrentVideoUrl();
  1486. }
  1487. }
  1488.  
  1489. // 橘子动漫
  1490. const MGNACG = "www.mgnacg.com";
  1491.  
  1492. class MgnacgHandler extends Handler {
  1493. constructor() {
  1494. super();
  1495. window.addEventListener('message', function (event) {
  1496. currentVideoUrl = event.data;
  1497. handler.checkCurrentVideoUrl();
  1498. window.removeEventListener("message", () => { });
  1499. }, false);
  1500. }
  1501. getUrlProtocolLink() {
  1502. let urlProtocol = new UrlProtocol;
  1503. urlProtocol.appendTitle();
  1504. urlProtocol.append('--http-header-fields="referer: https://' + MGNACG_PLAYER + '"');
  1505. return urlProtocol.getLink();
  1506. }
  1507. pauseCurrentVideo() {
  1508. document.getElementsByTagName("iframe")[2].contentWindow.postMessage("pause", "https://" + MGNACG_PLAYER);
  1509. }
  1510. }
  1511.  
  1512. // 橘子动漫实际播放地址
  1513. const MGNACG_PLAYER = "play.mknacg.top:8585";
  1514.  
  1515. class MgnacgPlayerHandler extends Handler {
  1516. constructor() {
  1517. super();
  1518. window.addEventListener("message", function (event) {
  1519. if (event.data == "pause") {
  1520. document.getElementsByTagName('video')[0].pause();
  1521. }
  1522. }, false);
  1523. }
  1524. getCurrentVideoUrl() {
  1525. currentVideoUrl = config.url;
  1526. if (handler.checkCurrentVideoUrl()) {
  1527. window.top.postMessage(currentVideoUrl, "*");
  1528. }
  1529. }
  1530. checkCurrentVideoUrl() {
  1531. return this.baseCheckCurrentVideoUrl();
  1532. }
  1533. }
  1534.  
  1535. // 迅猫动漫
  1536. const SPDCAT = "spdcat.net";
  1537.  
  1538. class SpdcatHandler extends Handler {
  1539. getCurrentVideoUrl() {
  1540. let videoUrl = document.getElementsByTagName('iframe')[2].src;
  1541. let startIndex = videoUrl.indexOf('url=http') + 4;
  1542. let endIndex = videoUrl.indexOf('.m3u8') + 5;
  1543. currentVideoUrl = decodeURIComponent(videoUrl.substring(startIndex, endIndex));
  1544. this.checkCurrentVideoUrl();
  1545. }
  1546. pauseCurrentVideo() {
  1547. document.getElementsByTagName("iframe")[2].contentWindow.document.getElementsByTagName("video")[0].pause();
  1548. }
  1549. }
  1550.  
  1551. // 最大尝试次数
  1552. const MAX_TRY_TIME = 8;
  1553. // 定时器
  1554. var timers;
  1555. // 当前页面链接
  1556. var currentUrl;
  1557. // 当前页面域名
  1558. var currentDomain;
  1559. // 当前页面视频链接
  1560. var currentVideoUrl;
  1561. // 当前页面音频链接
  1562. var currentAudioUrl;
  1563. // 巴哈姆特视频时长
  1564. var gamerDurationTime;
  1565.  
  1566. // 初始化当前页信息
  1567. function initCurrentPageInfo() {
  1568. // debug("init current page info ......");
  1569. document.getElementById(BUTTON_DIV).style.display = DISPLAY_NONE;
  1570. if (timers) {
  1571. for (let timer of timers) {
  1572. // debug("clear timer");
  1573. clearTimeout(timer);
  1574. }
  1575. }
  1576. currentUrl = window.location.href;
  1577. currentDomain = window.location.host;
  1578. currentVideoUrl = "";
  1579. ddrkPlayStatus = false;
  1580. }
  1581. // 创建处理器
  1582. function createHandler() {
  1583. // debug("start create handler: " + currentDomain);
  1584. if (BILIBILI.indexOf(currentDomain) != -1) {
  1585. handler = new BilibiliHandler();
  1586. } else if (BILIBILI_LIVE.indexOf(currentDomain) != -1) {
  1587. handler = new BilibiliLiveHandler();
  1588. } else if (DDRK.indexOf(currentDomain) != -1) {
  1589. handler = new DdrkHandler();
  1590. } else if (YOUTUBE.indexOf(currentDomain) != -1) {
  1591. handler = new YoutubeHandler();
  1592. } else if (DM6CC.indexOf(currentDomain) != -1) {
  1593. handler = new Dm6ccHandler();
  1594. } else if (DMLACC.indexOf(currentDomain) != -1) {
  1595. handler = new DmlaccHandler();
  1596. } else if (YHDMJX.indexOf(currentDomain) != -1) {
  1597. handler = new YhdmjxHandler();
  1598. } else if (DM233.indexOf(currentDomain) != -1) {
  1599. handler = new Dm233Handler();
  1600. } else if (DMH8.indexOf(currentDomain) != -1) {
  1601. handler = new Dmh8Handler();
  1602. } else if (YHDMP.indexOf(currentDomain) != -1) {
  1603. handler = new YhdmpHandler();
  1604. } else if (GAMER.indexOf(currentDomain) != -1) {
  1605. handler = new GamerHandler();
  1606. } else if (HDZYK.indexOf(currentDomain) != -1) {
  1607. handler = new HdzykHandler();
  1608. } else if (ZYKBF.indexOf(currentDomain) != -1) {
  1609. handler = new ZykbfHandler();
  1610. } else if (KK151.indexOf(currentDomain) != -1) {
  1611. handler = new Kk151Handler();
  1612. } else if (JXM3U8TV.indexOf(currentDomain) != -1) {
  1613. handler = new Jxm3u8tvHandler();
  1614. } else if (LIBVIO.indexOf(currentDomain) != -1) {
  1615. handler = new LibvioHandler();
  1616. } else if (LIBVIO_PLAYER.indexOf(currentDomain) != -1) {
  1617. handler = new LibvioPlayerHandler();
  1618. } else if (BDYS01.indexOf(currentDomain) != -1) {
  1619. handler = new Bdys01Handler();
  1620. } else if (BTNULL.indexOf(currentDomain) != -1) {
  1621. handler = new BtnullHandler();
  1622. } else if (PKMP4.indexOf(currentDomain) != -1) {
  1623. handler = new Pkmp4Handler();
  1624. } else if (XFANI.indexOf(currentDomain) != -1) {
  1625. handler = new XfaniHandler();
  1626. } else if (XFANI_PLAYER.indexOf(currentDomain) != -1) {
  1627. handler = new XfaniPlayerHandler();
  1628. } else if (MGNACG.indexOf(currentDomain) != -1) {
  1629. handler = new MgnacgHandler();
  1630. } else if (MGNACG_PLAYER.indexOf(currentDomain) != -1) {
  1631. handler = new MgnacgPlayerHandler();
  1632. } else if (SPDCAT.indexOf(currentDomain) != -1) {
  1633. handler = new SpdcatHandler();
  1634. } else {
  1635. if (document.title.toLowerCase().indexOf(ALIST) != -1) {
  1636. handler = new AlistHandler();
  1637. }
  1638. }
  1639. }
  1640. // 刷新视频链接
  1641. function refreshCurrentVideoUrl() {
  1642. // debug("refresh current video url: " + currentVideoUrl);
  1643. // debug("current url: " + currentUrl);
  1644. timers = new Array();
  1645. let tryTime = 0;
  1646. while (tryTime < MAX_TRY_TIME) {
  1647. timers[tryTime] = setTimeout(function () {
  1648. if (!handler.checkCurrentVideoUrl()) {
  1649. handler.getCurrentVideoUrl();
  1650. }
  1651. // debug("timer done");
  1652. }, tryTime * 2000 + 700);
  1653. tryTime = tryTime + 1;
  1654. }
  1655. }
  1656. // 页面变更监听器
  1657. function pageChangeListener() {
  1658. // debug("page change listener");
  1659. let needRefresh = false;
  1660. let newCurrentUrl = window.location.href;
  1661. if (currentUrl != newCurrentUrl) {
  1662. needRefresh = true;
  1663. }
  1664. // 巴哈姆特
  1665. if (!needRefresh && GAMER.indexOf(currentDomain) != -1) {
  1666. let oldGamerDurationTime = gamerDurationTime;
  1667. let durationDiv = document.getElementsByClassName("vjs-duration-display")[0];
  1668. if (durationDiv) {
  1669. gamerDurationTime = durationDiv.innerHTML;
  1670. if (oldGamerDurationTime && oldGamerDurationTime != gamerDurationTime) {
  1671. needRefresh = true;
  1672. }
  1673. }
  1674. }
  1675. if (needRefresh) {
  1676. // debug("page change");
  1677. initCurrentPageInfo();
  1678. refreshCurrentVideoUrl();
  1679. }
  1680. }
  1681. // 初始化
  1682. function init() {
  1683. console.log("Play-With-MPV ......");
  1684. currentUrl = window.location.href;
  1685. currentDomain = window.location.host;
  1686. if (currentUrl.startsWith("https://live.bilibili.com/p/html/live-web-mng/index.html")) {
  1687. console.log("排除页面:" + currentUrl);
  1688. } else {
  1689. // 创建处理器
  1690. createHandler();
  1691. if (handler) {
  1692. // 添加组件和监听器
  1693. appendHTML();
  1694. appendCSS();
  1695. addListener();
  1696.  
  1697. // 初始化页面信息
  1698. initCurrentPageInfo();
  1699. // 刷新视频链接
  1700. refreshCurrentVideoUrl();
  1701. // 定时监听页面变化
  1702. setInterval(pageChangeListener, 700);
  1703. } else {
  1704. console.log("create handler fail");
  1705. }
  1706. }
  1707. }
  1708. init();