BHD Pop-up Player for YT Trailers

A pop-up player for YouTube trailer video on the BHD title page.

  1. // ==UserScript==
  2. // @name BHD Pop-up Player for YT Trailers
  3. // @namespace Violentmonkey Scripts
  4. // @match https://beyond-hd.me/library/title/*
  5. // @match https://beyond-hd.me/torrents/*
  6. // @grant none
  7. // @version 1.0
  8. // @author CodeX0
  9. // @license MIT
  10. // @description A pop-up player for YouTube trailer video on the BHD title page.
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. console.log("[BHD Trailer Pop-Up Player] - Script loaded.");
  17.  
  18. const videoLinkSelector = 'a[href*="youtube.com/watch"]';
  19.  
  20. let popup = null;
  21.  
  22. function extractVideoUrl(redirectUrl) {
  23. console.log("[BHD Trailer Pop-Up Player] - Extracting video URL from:", redirectUrl);
  24.  
  25. if (redirectUrl.startsWith("https://anon.to/?")) {
  26. const realUrl = redirectUrl.split("https://anon.to/?")[1];
  27. console.log("[BHD Trailer Pop-Up Player] - Extracted video URL:", realUrl);
  28. return realUrl;
  29. }
  30.  
  31. console.log("[BHD Trailer Pop-Up Player] - No redirect found, using original URL:", redirectUrl);
  32. return redirectUrl;
  33. }
  34.  
  35. function convertToEmbedUrl(videoUrl) {
  36. console.log("[BHD Trailer Pop-Up Player] - Converting to embed URL:", videoUrl);
  37.  
  38. const videoId = videoUrl.split("v=")[1];
  39. if (!videoId) {
  40. console.error("[BHD Trailer Pop-Up Player] - Could not extract video ID from URL:", videoUrl);
  41. return null;
  42. }
  43.  
  44. const embedUrl = `https://www.youtube.com/embed/${videoId}`;
  45. console.log("[BHD Trailer Pop-Up Player] - Embed URL:", embedUrl);
  46. return embedUrl;
  47. }
  48.  
  49. function createPopup(videoUrl) {
  50. console.log("[BHD Trailer Pop-Up Player] - Creating pop-up for video URL:", videoUrl);
  51.  
  52. popup = document.createElement('div');
  53. popup.style.position = 'fixed';
  54. popup.style.top = '50%';
  55. popup.style.left = '50%';
  56. popup.style.transform = 'translate(-50%, -50%)';
  57. popup.style.width = '640px';
  58. popup.style.height = '360px';
  59. popup.style.backgroundColor = '#000';
  60. popup.style.zIndex = '1000';
  61. popup.style.border = '2px solid #fff';
  62. popup.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
  63.  
  64. const iframe = document.createElement('iframe');
  65. iframe.src = videoUrl;
  66. iframe.style.width = '100%';
  67. iframe.style.height = '100%';
  68. iframe.style.border = 'none';
  69. iframe.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
  70. iframe.allowFullscreen = true;
  71.  
  72. const closeButton = document.createElement('button');
  73. closeButton.innerText = 'X';
  74. closeButton.style.position = 'absolute';
  75. closeButton.style.top = '10px';
  76. closeButton.style.right = '10px';
  77. closeButton.style.backgroundColor = 'red';
  78. closeButton.style.color = 'white';
  79. closeButton.style.border = 'none';
  80. closeButton.style.cursor = 'pointer';
  81. closeButton.style.padding = '5px 10px';
  82. closeButton.style.borderRadius = '50%';
  83. closeButton.onclick = () => {
  84. console.log("[BHD Trailer Pop-Up Player] - Closing pop-up via close button.");
  85. closePopup();
  86. };
  87.  
  88. popup.appendChild(iframe);
  89. popup.appendChild(closeButton);
  90. document.body.appendChild(popup);
  91.  
  92. document.addEventListener('click', handleOutsideClick);
  93.  
  94. console.log("[BHD Trailer Pop-Up Player] - Pop-up created and appended to the body.");
  95. }
  96.  
  97. function closePopup() {
  98. if (popup) {
  99. console.log("[BHD Trailer Pop-Up Player] - Closing pop-up.");
  100. document.body.removeChild(popup);
  101. popup = null;
  102.  
  103. document.removeEventListener('click', handleOutsideClick);
  104. }
  105. }
  106.  
  107. function handleOutsideClick(event) {
  108. if (!popup || popup.contains(event.target)) {
  109. return;
  110. }
  111.  
  112. closePopup();
  113. }
  114.  
  115. document.querySelectorAll(videoLinkSelector).forEach(link => {
  116. link.addEventListener('click', function(event) {
  117. event.preventDefault();
  118. event.stopPropagation();
  119.  
  120. console.log("[BHD Trailer Pop-Up Player] - Video link clicked:", this.href);
  121.  
  122. const videoUrl = extractVideoUrl(this.href);
  123. console.log("[BHD Trailer Pop-Up Player] - Final video URL:", videoUrl);
  124.  
  125. const embedUrl = convertToEmbedUrl(videoUrl);
  126. if (!embedUrl) {
  127. console.error("[BHD Trailer Pop-Up Player] - Failed to convert to embed URL.");
  128. return;
  129. }
  130.  
  131. createPopup(embedUrl);
  132. });
  133. });
  134.  
  135. console.log("[BHD Trailer Pop-Up Player] - Event listeners added to video links.");
  136. })();