Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- const videoId = 'video-player';
- let video = document.getElementById(videoId);
- if (!video) {
- video = document.querySelector('video');
- if (!video) {
- console.error('No video element found on the page.');
- return;
- }
- }
- const container = document.createElement('div');
- container.style.position = 'relative';
- container.style.display = 'inline-block';
- video.parentNode.insertBefore(container, video);
- container.appendChild(video);
- const timeInput = document.createElement('input');
- timeInput.type = 'text';
- timeInput.placeholder = 'Enter time (HH:MM:SS or MM:SS)';
- timeInput.style.position = 'absolute';
- timeInput.style.left = '284px';
- timeInput.style.bottom = '13px';
- timeInput.style.zIndex = '9999';
- timeInput.style.width = '170px';
- timeInput.style.padding = '5px';
- timeInput.style.fontSize = '10px';
- timeInput.style.color = 'black';
- const seekButton = document.createElement('button');
- seekButton.textContent = 'Go';
- seekButton.style.position = 'absolute';
- seekButton.style.right = '0';
- seekButton.style.bottom = '-30px';
- seekButton.style.zIndex = '9999';
- seekButton.style.padding = '5px 10px';
- seekButton.style.fontSize = '14px';
- seekButton.style.cursor = 'pointer';
- container.appendChild(timeInput);
- container.appendChild(seekButton);
- const timeDisplay = document.createElement('div');
- timeDisplay.style.position = 'absolute';
- timeDisplay.style.right = '10px';
- timeDisplay.style.bottom = '-55px'; // Adjust as needed
- timeDisplay.style.color = 'white';
- timeDisplay.style.fontSize = '14px';
- timeDisplay.style.fontFamily = 'Arial, sans-serif';
- timeDisplay.style.textShadow = '1px 1px 2px black';
- container.appendChild(timeDisplay);
- if (video.readyState < 1) {
- // Wait for metadata to load
- video.addEventListener('loadedmetadata', initializeControls);
- } else {
- initializeControls();
- }
- function formatTime(seconds) {
- const hrs = Math.floor(seconds / 3600);
- const mins = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
- const secs = Math.floor(seconds % 60).toString().padStart(2, '0');
- if (hrs > 0) {
- return `${hrs}:${mins}:${secs}`;
- } else {
- return `${mins}:${secs}`;
- }
- }
- function parseTime(timeString) {
- const parts = timeString.split(':').map(Number);
- if (parts.length === 3) {
- // HH:MM:SS
- return parts[0] * 3600 + parts[1] * 60 + parts[2];
- } else if (parts.length === 2) {
- // MM:SS
- return parts[0] * 60 + parts[1];
- } else if (parts.length === 1) {
- // SS
- return parts[0];
- } else {
- return NaN;
- }
- }
- function initializeControls() {
- video.addEventListener('timeupdate', function() {
- timeDisplay.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
- });
- timeDisplay.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
- seekButton.addEventListener('click', function() {
- const timeString = timeInput.value.trim();
- const timeInSeconds = parseTime(timeString);
- if (!isNaN(timeInSeconds) && timeInSeconds >= 0 && timeInSeconds <= video.duration) {
- video.currentTime = timeInSeconds;
- } else {
- alert('Invalid time entered.');
- }
- });
- timeInput.addEventListener('keydown', function(event) {
- if (event.key === 'Enter') {
- seekButton.click();
- }
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement