// Helper function to extract YouTube Video ID
const extractYouTubeID = (url) => {
const regex = /(?:youtube.com/(?:[^/]+/.+/|(?:v|embed)/|.*[?&]v=)|youtu.be/)([^"&?/\s]{11})/;
const match = url.match(regex);
return match ? match[1] : null;
};
// Reset media containers
videoYouTubeIframe.src = '';
videoYouTubeIframe.style.display = 'none';
videoLocalPlayer.src = '';
videoLocalPlayer.style.display = 'none';
if (url) {
loadYouTubeMedia(url, 'video', false);
// Note: Controlling playback via YouTube IFrame API is not implemented.
// Users can manually control playback via iframe controls.
} else if (file) {
const fileURL = URL.createObjectURL(file);
videoLocalPlayer.src = fileURL;
videoLocalPlayer.currentTime = startTime;
videoLocalPlayer.style.display = 'block';
videoLocalPlayer.play();
} else {
alert('Please provide a YouTube URL or select a video file.');
}
});
// Play Button Handler
playButton.addEventListener('click', () => {
// Play Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.play();
}
// Play Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.play();
}
// Play YouTube Audio
if (audioYouTubeIframe.src) {
// Playing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
// Users need to manually click play on the iframe
alert('Please play the YouTube audio manually using the iframe controls.');
}
// Play YouTube Video
if (videoYouTubeIframe.src) {
// Playing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
// Users need to manually click play on the iframe
alert('Please play the YouTube video manually using the iframe controls.');
}
});
// Pause Button Handler
pauseButton.addEventListener('click', () => {
// Pause Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.pause();
}
// Pause Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.pause();
}
// Pause YouTube Audio
if (audioYouTubeIframe.src) {
// Pausing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please pause the YouTube audio manually using the iframe controls.');
}
// Pause YouTube Video
if (videoYouTubeIframe.src) {
// Pausing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please pause the YouTube video manually using the iframe controls.');
}
});
// Resume Button Handler
resumeButton.addEventListener('click', () => {
// Resume Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.play();
}
// Resume Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.play();
}
// Resume YouTube Audio
if (audioYouTubeIframe.src) {
// Resuming YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please resume the YouTube audio manually using the iframe controls.');
}
// Resume YouTube Video
if (videoYouTubeIframe.src) {
// Resuming YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please resume the YouTube video manually using the iframe controls.');
}
});
// Prevent default behavior for drag-and-drop if needed
window.addEventListener('dragover', (e) => e.preventDefault());
window.addEventListener('drop', (e) => e.preventDefault());
});
i only want completed updated files. make any thing that loads from the load buttons in both the audio and video section centered. make the top section never clip off the top of the screen like it does when i load videos in. make the whole thing except the background and text 50% transparent.
Sure! Below are the fully updated files for your Chrome extension "Sync Waves" with the requested modifications:
Media Loaded via Load Buttons Centered
Prevent Top Section from Clipping
50% Transparency for All Elements Except Background and Text
manifest.json
No changes were necessary for the manifest.json file based on your requirements. However, for completeness, here is the full manifest:
No changes were necessary for the background.js file. Here is the complete script:
javascript
chrome.action.onClicked.addListener((tab) => {
// Get the extension's URL for newtab.html
const newTabURL = chrome.runtime.getURL("newtab.html");
// Create a new tab with newtab.html
chrome.tabs.create({ url: newTabURL });
});
newtab.html
No structural changes were necessary for newtab.html. However, it's included here for completeness:
No changes were necessary for the newtab.js file based on your requirements. Here is the complete script:
javascript
Summary of Changes
Centered Media Containers:
Added display: flex and justify-content: center to .media-container to center the loaded media.
Prevent Top Clipping:
Set max-height: 100vh and overflow-y: auto on .container to ensure that the top section never clips and content is scrollable if it exceeds the viewport height.
50% Transparency:
Applied rgba colors with 0.5 alpha to the backgrounds and borders of input fields and buttons to achieve 50% transparency.
Maintained full opacity for text and the page background by not using the opacity property on parent containers, which would affect child elements.
Responsive Design:
Ensured that on smaller screens (max-width: 800px), the container width adjusts and buttons are resized appropriately.
Hover Effects:
Slightly increased the opacity on hover for buttons to give a visual feedback without breaking the transparency requirement.
Feel free to integrate these updated files into your Chrome extension. If you have any further modifications or encounter any issues, let me know!
Not yet included in a published release.
document.addEventListener('DOMContentLoaded', () => {
// Audio Elements
const audioYouTubeURLInput = document.getElementById('audio-youtube-url');
const audioFileInput = document.getElementById('audio-file-input');
const audioStartTimeInput = document.getElementById('audio-start-time');
const audioLoadButton = document.getElementById('audio-load-button');
const audioLocalPlayer = document.getElementById('audio-local-player');
const audioYouTubeIframe = document.getElementById('audio-youtube-iframe');
const audioYouTubeContainer = document.getElementById('audio-youtube-container');
const audioLocalContainer = document.getElementById('audio-local-container');
// Video Elements
const videoYouTubeURLInput = document.getElementById('video-youtube-url');
const videoFileInput = document.getElementById('video-file-input');
const videoStartTimeInput = document.getElementById('video-start-time');
const videoLoadButton = document.getElementById('video-load-button');
const videoLocalPlayer = document.getElementById('video-local-player');
const videoYouTubeIframe = document.getElementById('video-youtube-iframe');
const videoYouTubeContainer = document.getElementById('video-youtube-container');
const videoLocalContainer = document.getElementById('video-local-container');
// Control Buttons
const playButton = document.getElementById('play-button');
const pauseButton = document.getElementById('pause-button');
const resumeButton = document.getElementById('resume-button');
// Helper function to extract YouTube Video ID
const extractYouTubeID = (url) => {
const regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|embed)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/;
const match = url.match(regex);
return match ? match[1] : null;
};
// Helper function to load YouTube Media
const loadYouTubeMedia = (url, mediaType, isAudio = false) => {
const videoId = extractYouTubeID(url);
if (videoId) {
let embedUrl = `https://www.youtube.com/embed/${videoId}?enablejsapi=1&autoplay=0`;
if (isAudio) {
embedUrl += `&mute=1&controls=1&loop=1&playlist=${videoId}`;
audioYouTubeIframe.src = embedUrl;
audioYouTubeIframe.style.display = 'block';
} else {
embedUrl += `&controls=1`;
videoYouTubeIframe.src = embedUrl;
videoYouTubeIframe.style.display = 'block';
}
} else {
alert('Invalid YouTube URL');
}
};
// Load Audio Handler
audioLoadButton.addEventListener('click', () => {
const url = audioYouTubeURLInput.value.trim();
const file = audioFileInput.files[0];
const startTime = parseInt(audioStartTimeInput.value, 10) || 0;
// Reset media containers
audioYouTubeIframe.src = '';
audioYouTubeIframe.style.display = 'none';
audioLocalPlayer.src = '';
audioLocalPlayer.style.display = 'none';
if (url) {
loadYouTubeMedia(url, 'audio', true);
// Note: Controlling playback via YouTube IFrame API is not implemented.
// Users can manually control playback via iframe controls.
} else if (file) {
const fileURL = URL.createObjectURL(file);
audioLocalPlayer.src = fileURL;
audioLocalPlayer.currentTime = startTime;
audioLocalPlayer.style.display = 'block';
audioLocalPlayer.play();
} else {
alert('Please provide a YouTube URL or select an audio file.');
}
});
// Load Video Handler
videoLoadButton.addEventListener('click', () => {
const url = videoYouTubeURLInput.value.trim();
const file = videoFileInput.files[0];
const startTime = parseInt(videoStartTimeInput.value, 10) || 0;
// Reset media containers
videoYouTubeIframe.src = '';
videoYouTubeIframe.style.display = 'none';
videoLocalPlayer.src = '';
videoLocalPlayer.style.display = 'none';
if (url) {
loadYouTubeMedia(url, 'video', false);
// Note: Controlling playback via YouTube IFrame API is not implemented.
// Users can manually control playback via iframe controls.
} else if (file) {
const fileURL = URL.createObjectURL(file);
videoLocalPlayer.src = fileURL;
videoLocalPlayer.currentTime = startTime;
videoLocalPlayer.style.display = 'block';
videoLocalPlayer.play();
} else {
alert('Please provide a YouTube URL or select a video file.');
}
});
// Play Button Handler
playButton.addEventListener('click', () => {
// Play Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.play();
}
// Play Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.play();
}
// Play YouTube Audio
if (audioYouTubeIframe.src) {
// Playing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please play the YouTube audio manually using the iframe controls.');
}
// Play YouTube Video
if (videoYouTubeIframe.src) {
// Playing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please play the YouTube video manually using the iframe controls.');
}
});
// Pause Button Handler
pauseButton.addEventListener('click', () => {
// Pause Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.pause();
}
// Pause Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.pause();
}
// Pause YouTube Audio
if (audioYouTubeIframe.src) {
// Pausing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please pause the YouTube audio manually using the iframe controls.');
}
// Pause YouTube Video
if (videoYouTubeIframe.src) {
// Pausing YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please pause the YouTube video manually using the iframe controls.');
}
});
// Resume Button Handler
resumeButton.addEventListener('click', () => {
// Resume Local Audio
if (audioLocalPlayer.src) {
audioLocalPlayer.play();
}
// Resume Local Video
if (videoLocalPlayer.src) {
videoLocalPlayer.play();
}
// Resume YouTube Audio
if (audioYouTubeIframe.src) {
// Resuming YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please resume the YouTube audio manually using the iframe controls.');
}
// Resume YouTube Video
if (videoYouTubeIframe.src) {
// Resuming YouTube IFrame content requires YouTube IFrame API
// Not implemented here
alert('Please resume the YouTube video manually using the iframe controls.');
}
});
// Prevent default behavior for drag-and-drop if needed
window.addEventListener('dragover', (e) => e.preventDefault());
window.addEventListener('drop', (e) => e.preventDefault());
});