爱壹帆IYF网页全屏(国际版)

Toggle the video container between normal and maximized view with a button and the "M" key shortcut. The button has enhanced styling.

  1. // ==UserScript==
  2. // @name 爱壹帆IYF网页全屏(国际版)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Toggle the video container between normal and maximized view with a button and the "M" key shortcut. The button has enhanced styling.
  6. // @match https://www.yfsp.tv/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let container, toggleButton;
  15. let maximized = false;
  16. let originalStyles = {};
  17.  
  18. function waitForVideo() {
  19. // Target the video element by its id.
  20. const video = document.querySelector('video#video_player');
  21. if (video) {
  22. console.log("Video found!");
  23. initialize(video);
  24. } else {
  25. console.log("Waiting for video element...");
  26. setTimeout(waitForVideo, 1000);
  27. }
  28. }
  29.  
  30. function initialize(video) {
  31. // Use closest() to find the <vg-player> container.
  32. container = video.closest('vg-player');
  33. if (!container) {
  34. container = video.parentElement;
  35. }
  36. console.log("Container found:", container);
  37. addToggleButton();
  38. addKeyboardShortcut();
  39. }
  40.  
  41. function addToggleButton() {
  42. toggleButton = document.createElement('button');
  43. toggleButton.innerHTML = 'Toggle Maximize';
  44. // Enhanced styling: bold border and transparent filling.
  45. toggleButton.style.position = 'fixed';
  46. toggleButton.style.bottom = '20px';
  47. toggleButton.style.right = '20px';
  48. toggleButton.style.zIndex = '10000';
  49. toggleButton.style.padding = '8px 12px';
  50. toggleButton.style.fontWeight = 'bold';
  51. toggleButton.style.border = '2px solid white';
  52. toggleButton.style.backgroundColor = 'rgba(0, 0, 0, 0.3)';
  53. toggleButton.style.color = 'white';
  54. toggleButton.style.borderRadius = '5px';
  55. toggleButton.style.cursor = 'pointer';
  56. document.body.appendChild(toggleButton);
  57.  
  58. toggleButton.addEventListener('click', toggleMaximize);
  59. }
  60.  
  61. function addKeyboardShortcut() {
  62. document.addEventListener('keydown', function(e) {
  63. // Toggle when pressing 'M' (ignore if typing in an input field)
  64. if (e.target.tagName.toLowerCase() !== 'input' && e.key.toLowerCase() === 'm') {
  65. toggleMaximize();
  66. }
  67. });
  68. }
  69.  
  70. function toggleMaximize() {
  71. if (!maximized) {
  72. // Save current inline styles.
  73. originalStyles = {
  74. position: container.style.position,
  75. top: container.style.top,
  76. left: container.style.left,
  77. width: container.style.width,
  78. height: container.style.height,
  79. zIndex: container.style.zIndex
  80. };
  81. // Maximize the container.
  82. container.style.position = 'fixed';
  83. container.style.top = '0';
  84. container.style.left = '0';
  85. container.style.width = '100vw';
  86. container.style.height = '100vh';
  87. container.style.zIndex = '9999';
  88. document.body.style.overflow = 'hidden';
  89. toggleButton.innerHTML = 'Restore';
  90. maximized = true;
  91. console.log("Container maximized.");
  92. } else {
  93. // Restore original styles.
  94. container.style.position = originalStyles.position;
  95. container.style.top = originalStyles.top;
  96. container.style.left = originalStyles.left;
  97. container.style.width = originalStyles.width;
  98. container.style.height = originalStyles.height;
  99. container.style.zIndex = originalStyles.zIndex;
  100. document.body.style.overflow = '';
  101. toggleButton.innerHTML = 'Toggle Maximize';
  102. maximized = false;
  103. console.log("Container restored.");
  104. }
  105. }
  106.  
  107. waitForVideo();
  108. })();

QingJ © 2025

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