Advertisement
Guest User

кал

a guest
Dec 17th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.49 KB | Cryptocurrency | 0 0
  1. (function() {
  2.   const videoId = 'video-player';
  3.   let video = document.getElementById(videoId);
  4.   if (!video) {
  5.     video = document.querySelector('video');
  6.     if (!video) {
  7.       console.error('No video element found on the page.');
  8.       return;
  9.     }
  10.   }
  11.  
  12.   const container = document.createElement('div');
  13.   container.style.position = 'relative';
  14.   container.style.display = 'inline-block';
  15.  
  16.   video.parentNode.insertBefore(container, video);
  17.   container.appendChild(video);
  18.  
  19.   const timeInput = document.createElement('input');
  20.   timeInput.type = 'text';
  21.   timeInput.placeholder = 'Enter time (HH:MM:SS or MM:SS)';
  22.   timeInput.style.position = 'absolute';
  23.   timeInput.style.left = '284px';
  24.   timeInput.style.bottom = '13px';
  25.   timeInput.style.zIndex = '9999';
  26.   timeInput.style.width = '170px';
  27.   timeInput.style.padding = '5px';
  28.   timeInput.style.fontSize = '10px';
  29.   timeInput.style.color = 'black';
  30.  
  31.   const seekButton = document.createElement('button');
  32.   seekButton.textContent = 'Go';
  33.   seekButton.style.position = 'absolute';
  34.   seekButton.style.right = '0';
  35.   seekButton.style.bottom = '-30px';
  36.   seekButton.style.zIndex = '9999';
  37.   seekButton.style.padding = '5px 10px';
  38.   seekButton.style.fontSize = '14px';
  39.   seekButton.style.cursor = 'pointer';
  40.  
  41.   container.appendChild(timeInput);
  42.   container.appendChild(seekButton);
  43.  
  44.   const timeDisplay = document.createElement('div');
  45.   timeDisplay.style.position = 'absolute';
  46.   timeDisplay.style.right = '10px';
  47.   timeDisplay.style.bottom = '-55px'; // Adjust as needed
  48.   timeDisplay.style.color = 'white';
  49.   timeDisplay.style.fontSize = '14px';
  50.   timeDisplay.style.fontFamily = 'Arial, sans-serif';
  51.   timeDisplay.style.textShadow = '1px 1px 2px black';
  52.   container.appendChild(timeDisplay);
  53.  
  54.   if (video.readyState < 1) {
  55.     // Wait for metadata to load
  56.     video.addEventListener('loadedmetadata', initializeControls);
  57.   } else {
  58.     initializeControls();
  59.   }
  60.  
  61.   function formatTime(seconds) {
  62.     const hrs = Math.floor(seconds / 3600);
  63.     const mins = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
  64.     const secs = Math.floor(seconds % 60).toString().padStart(2, '0');
  65.     if (hrs > 0) {
  66.       return `${hrs}:${mins}:${secs}`;
  67.     } else {
  68.       return `${mins}:${secs}`;
  69.     }
  70.   }
  71.  
  72.   function parseTime(timeString) {
  73.     const parts = timeString.split(':').map(Number);
  74.     if (parts.length === 3) {
  75.       // HH:MM:SS
  76.       return parts[0] * 3600 + parts[1] * 60 + parts[2];
  77.     } else if (parts.length === 2) {
  78.       // MM:SS
  79.       return parts[0] * 60 + parts[1];
  80.     } else if (parts.length === 1) {
  81.       // SS
  82.       return parts[0];
  83.     } else {
  84.       return NaN;
  85.     }
  86.   }
  87.  
  88.   function initializeControls() {
  89.     video.addEventListener('timeupdate', function() {
  90.       timeDisplay.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
  91.     });
  92.  
  93.     timeDisplay.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
  94.  
  95.     seekButton.addEventListener('click', function() {
  96.       const timeString = timeInput.value.trim();
  97.       const timeInSeconds = parseTime(timeString);
  98.       if (!isNaN(timeInSeconds) && timeInSeconds >= 0 && timeInSeconds <= video.duration) {
  99.         video.currentTime = timeInSeconds;
  100.       } else {
  101.         alert('Invalid time entered.');
  102.       }
  103.     });
  104.  
  105.     timeInput.addEventListener('keydown', function(event) {
  106.       if (event.key === 'Enter') {
  107.         seekButton.click();
  108.       }
  109.     });
  110.   }
  111. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement