21 lines
597 B
JavaScript
21 lines
597 B
JavaScript
// Listen for web requests
|
|
browser.webRequest.onBeforeRequest.addListener(
|
|
function(details) {
|
|
const url = new URL(details.url);
|
|
|
|
// Check if the URL is a YouTube URL
|
|
if (url.hostname === "www.youtube.com" || url.hostname === "youtube.com") {
|
|
// Extract the video ID from the URL
|
|
const videoId = url.searchParams.get("v");
|
|
if (videoId) {
|
|
// Rewrite to the embedded URL format
|
|
const embedUrl = `https://www.youtube.com/embed/${videoId}`;
|
|
return { redirectUrl: embedUrl };
|
|
}
|
|
}
|
|
},
|
|
{ urls: ["<all_urls>"] },
|
|
["blocking"]
|
|
);
|
|
|