feat: add timecode if there

This commit is contained in:
2025-07-21 19:23:15 +02:00
parent e5097d820a
commit 78d23a978d
3 changed files with 12 additions and 12 deletions

View File

@@ -1,21 +1,21 @@
// 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
// Extract the video ID from the URL params
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 };
// Rewrite to the embedded URL format, picking timecode if available
const timecode = url.searchParams.get("t");
return {
redirectUrl: `https://www.youtube-nocookie.com/embed/${videoId}?rel=0` + (timecode ? "&start=" + timecode : "")
};
}
}
},
{ urls: [ "*://www.youtube.com/*",
"*://youtube.com/*"] },
{ urls: [
"*://www.youtube.com/*",
"*://youtube.com/*"
]},
["blocking"]
);