Play-With-MPV

使用 MPV 播放网页上的视频

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

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