유튜브 팟 플레이어로 보기 버튼 추가

유튜브 동영상을 팟 플레이어로 열 수 있는 버튼을 추가합니다. 기존 영상은 일시 정지 됩니다.

  1. // ==UserScript==
  2. // @name 유튜브 팟 플레이어로 보기 버튼 추가
  3. // @namespace 유튜브 팟 플레이어로 보기 버튼 추가
  4. // @version 0.4
  5. // @description 유튜브 동영상을 팟 플레이어로 열 수 있는 버튼을 추가합니다. 기존 영상은 일시 정지 됩니다.
  6. // @match *://*.youtube.com/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=YouTube.com
  8. // @author mickey90427 <mickey90427@naver.com>
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let videoID = '';
  15.  
  16. // Extract video ID from the URL
  17. function getVideoID() {
  18. const urlParams = new URLSearchParams(window.location.search);
  19. return urlParams.get('v');
  20. }
  21.  
  22. // Get the current video's duration in seconds
  23. function getVideoDuration() {
  24. const videoElement = document.querySelector('video');
  25. return videoElement ? videoElement.duration : 0;
  26. }
  27.  
  28. // Convert time format (hh:mm:ss or mm:ss) to seconds
  29. function timeToSeconds(time) {
  30. const parts = time.split(':');
  31. let hours = 0;
  32. let minutes = 0;
  33. let seconds = 0;
  34.  
  35. if (parts.length === 3) {
  36. hours = parseInt(parts[0]) || 0;
  37. minutes = parseInt(parts[1]) || 0;
  38. seconds = parseInt(parts[2]) || 0;
  39. } else if (parts.length === 2) {
  40. minutes = parseInt(parts[0]) || 0;
  41. seconds = parseInt(parts[1]) || 0;
  42. }
  43.  
  44. return hours * 3600 + minutes * 60 + seconds;
  45. }
  46.  
  47. // Create the PotPlayer URL with the updated start time
  48. function createPotPlayerURL(videoID, startTime) {
  49. const baseURL = 'potplayer:https://www.youtube.com/watch?v=' + videoID;
  50. const params = new URLSearchParams({
  51. t: startTime,
  52. });
  53.  
  54. return baseURL + '?' + params.toString();
  55. }
  56.  
  57. // Open the video in PotPlayer with the current playback position
  58. function openInPotPlayer() {
  59. const player = document.querySelector('.html5-main-video');
  60. if (player) {
  61. // Pause YouTube player
  62. player.pause();
  63.  
  64. // Get the current playback time in seconds
  65. const currentTime = Math.floor(player.currentTime);
  66.  
  67. // Create the PotPlayer URL
  68. const potPlayerURL = createPotPlayerURL(videoID, currentTime);
  69.  
  70. // Open the video in PotPlayer with the current playback position
  71. window.location.href = potPlayerURL;
  72. }
  73. }
  74.  
  75. // Create and append the PotPlayer button
  76. function createPotPlayerButton(videoID) {
  77. // Check if the button already exists
  78. if (document.getElementById('potplayer-button')) {
  79. return;
  80. }
  81.  
  82. const logoContainer = document.getElementById('logo');
  83. if (!logoContainer) {
  84. return;
  85. }
  86.  
  87. const videoDuration = getVideoDuration();
  88. if (videoDuration === 0) {
  89. setTimeout(function() {
  90. createPotPlayerButton(videoID);
  91. }, 100);
  92. return;
  93. }
  94.  
  95. // Create the PotPlayer URL
  96. const potPlayerURL = createPotPlayerURL(videoID, '0');
  97.  
  98. const button = document.createElement('button');
  99. button.textContent = 'Open in PotPlayer';
  100. button.id = 'potplayer-button';
  101. button.setAttribute('data-potplayer-url', potPlayerURL);
  102. button.style.cssText = `
  103. background-color: #ff0;
  104. color: #000;
  105. border: none;
  106. padding: 10px;
  107. margin-left: 10px;
  108. cursor: pointer;
  109. border-radius: 5px;
  110. `;
  111.  
  112. button.addEventListener('click', openInPotPlayer);
  113.  
  114. logoContainer.parentNode.insertBefore(button, logoContainer.nextSibling);
  115. }
  116.  
  117. function updateVideoID() {
  118. const newVideoID = getVideoID();
  119. if (newVideoID && newVideoID !== videoID) {
  120. videoID = newVideoID;
  121. createPotPlayerButton(videoID);
  122. }
  123.  
  124. requestAnimationFrame(updateVideoID);
  125. }
  126.  
  127. function waitForLogo() {
  128. const logoContainer = document.getElementById('logo');
  129. if (logoContainer) {
  130. videoID = getVideoID();
  131. if (videoID) {
  132. createPotPlayerButton(videoID);
  133. updateVideoID();
  134. }
  135. } else {
  136. setTimeout(waitForLogo, 100);
  137. }
  138. }
  139.  
  140. waitForLogo();
  141. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址