A2p

Anime2Potplayer,把浏览器播放的动漫在Potplayer打开,这样就可以使用SVP4补帧!

当前为 2025-05-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name A2p
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description Anime2Potplayer,把浏览器播放的动漫在Potplayer打开,这样就可以使用SVP4补帧!
  6. // @author MakotoArai(https://github.com/MakotoArai-CN)
  7. // @supportURL https://blog.ciy.cool
  8. // @license GPL-v3
  9. // @icon https://cravatar.cn/avatar/1e84fce3269537e4aa7473602516bf6d?s=256
  10. // @match *anich.emmmm.eu.org/*
  11. // @match *.mutedm.com/*
  12. // @match *.iyinghua.com/*
  13. // @match *.5dm.link/*
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. window.onload = function () {
  22. console.info("%cA2P%c%s", "color:red;font-size:40px;font-weight:bold;", "color:black;font-size:16px;font-weight:normal", GM_info.script.version);
  23.  
  24. // 定时器用于动态嗅探视频链接
  25. const videoTimer = setInterval(findVideoUrl, 1000);
  26. function findVideoUrl() {
  27. const videoElement = document.querySelector("video");
  28. if (videoElement && videoElement.src) {
  29. clearInterval(videoTimer);
  30. preparePotplayerInteraction(videoElement, GM_getValue("check") ?? false);
  31. }
  32. }
  33.  
  34. function preparePotplayerInteraction(videoElement, check = true) {
  35. const videoUrl = videoElement.src;
  36. console.log(`检测到视频链接: ${videoUrl}`);
  37.  
  38. creatBtn(videoElement);
  39. if (check) window.location.href = `potplayer://${videoUrl}`;
  40. // 暂停网页视频的播放
  41. videoElement.autoplay = false;
  42. }
  43.  
  44. function creatBtn(videoElement) {
  45. // 插入自定义CDN
  46. document.head.insertAdjacentHTML("beforeend", `
  47. <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
  48. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  49. `);
  50. // 右键菜单
  51. var menu = document.createElement("div");
  52. // 插入自定义css
  53. document.head.insertAdjacentHTML("beforeend", `
  54. <style>
  55. a {text-decoration: none;}
  56. div.usercm{background-repeat:no-repeat;background-position:center center;background-size:cover;background-color:#fff;font-size:13px!important;width:160px;-moz-box-shadow:1px 1px 3px rgba
  57. (0,0,0,.3);box-shadow:0px 0px 15px #333;position:absolute;display:none;z-index:10000;opacity:0.9; border-radius: 8px;}
  58. div.usercm ul{list-style-type:none;list-style-position:outside;margin:0px;padding:0px;display:block}
  59. div.usercm ul li{margin:0px;padding:0px;line-height:35px;}
  60. div.usercm ul li a{color:#666;padding:0 15px;display:block}
  61. /* div.usercm ul li a:hover{color:#fff;background:rgba(170,222,18,0.88)} */
  62. div.usercm ul li a:hover{color:#fff;background:rgba(15, 120, 233, 0.88)} /* 蓝色 */
  63. div.usercm ul li a i{margin-right:10px}
  64. a.disabled{color:#c8c8c8!important;cursor:not-allowed}
  65. a.disabled:hover{background-color:rgba(255,11,11,0)!important}
  66. div.usercm{background:#fff !important;}
  67. </style>
  68. )`);
  69.  
  70. /* 右键菜单 */
  71. menu.innerHTML = `
  72. <div class="usercm" style="left: 199px; top: 5px; display: none;">
  73. <ul>
  74. <li><a href="/"><i class="fa fa-home fa-fw"></i><span>首页</span></a></li>
  75. <li><a href="javascript:void(0);" onclick="'' == (window.getSelection ? window.getSelection() : document.selection.createRange().text) ? console.log() : document.execCommand('Copy')"><i class="fa fa-copy fa-fw"></i><span>复制</span></a></li>
  76. <li><a href="javascript:history.go(1);"><i class="fa fa-arrow-right fa-fw"></i><span>前进</span></a></li>
  77. <li><a href="javascript:history.go(-1);"><i class="fa fa-arrow-left fa-fw"></i><span>后退</span></a></li>
  78. <li style="border-bottom:1px solid gray"><a href="javascript:window.location.reload();"><i class="fa fa-refresh fa-fw"></i><span>重载网页</span></a></li>
  79. <li><a href="javascript:void(0);" class="potplayer"><i class="fa fa-arrow-right fa-fw"></i><span>Potplayer</span></a></li>
  80. <li><a href="javascript:void(0);" class="aa2p"><i class="fa fa-arrow-right fa-fw"></i><span>自动跳转</span></a></li>
  81. <li><a href="https://blog.ciy.cool"><i class="fa fa-pencil-square-o fa-fw"></i><span>关于我</span></a></li>
  82. </ul>
  83. </div>
  84. `;
  85. document.body.appendChild(menu);
  86. // 自定义鼠标右键
  87. (function (a) {
  88. a.extend({
  89. mouseMoveShow: function (b) {
  90. var d = 0,
  91. c = 0,
  92. h = 0,
  93. k = 0,
  94. e = 0,
  95. f = 0;
  96. a(window).mousemove(function (g) {
  97. d = a(window).width();
  98. c = a(window).height();
  99. h = g.clientX;
  100. k = g.clientY;
  101. e = g.pageX;
  102. f = g.pageY;
  103. h + a(b).width() >= d && (e = e - a(b).width() - 5);
  104. k + a(b).height() >= c && (f = f - a(b).height() - 5);
  105. a("html").on({
  106. contextmenu: function (c) {
  107. 3 == c.which && a(b).css({
  108. left: e,
  109. top: f
  110. }).show()
  111. },
  112. click: function () {
  113. a(b).hide()
  114. }
  115. })
  116. })
  117. },
  118. disabledContextMenu: function () {
  119. window.oncontextmenu = function (e) {
  120. // 阻止默认事件
  121. e.preventDefault();
  122. return !1
  123. }
  124. }
  125. })
  126. })(jQuery);
  127.  
  128. $(function () {
  129. for (var a = navigator.userAgent, b = "Android;iPhone;SymbianOS;Windows Phone;iPad;iPod".split(";"), d = !0, c = 0; c < b.length; c++) if (0 < a.indexOf(b[c])) {
  130. d = !1;
  131. break
  132. }
  133. d && ($.mouseMoveShow(".usercm"), $.disabledContextMenu())
  134. });
  135.  
  136. const potplayer = document.querySelector(".potplayer");
  137. const aa2p = document.querySelector(".aa2p");
  138. const videoUrl = videoElement.src;
  139. potplayer.addEventListener("click", function () {
  140. window.location.href = `potplayer://${videoUrl}`;
  141. // 暂停播放
  142. videoElement.pause();
  143. })
  144.  
  145. aa2p.innerHTML = `<i class="fa fa-arrow-right fa-fw"></i><span>${GM_getValue("check") ? "关闭自动跳转" : "开启自动跳转"}</span>`;
  146. aa2p.addEventListener("click", function () {
  147. const check = GM_getValue("check") ?? false;
  148. if (check) {
  149. GM_setValue("check", false);
  150. aa2p.innerHTML = `<i class="fa fa-arrow-right fa-fw"></i><span>开启自动跳转</span>`;
  151. } else {
  152. GM_setValue("check", true);
  153. aa2p.innerHTML = `<i class="fa fa-arrow-right fa-fw"></i><span>关闭自动跳转</span>`;
  154. }
  155. })
  156. }
  157. }
  158. })();