From 78d23a978db28dc945b4d765c4982a27d21edd6c Mon Sep 17 00:00:00 2001 From: setop Date: Mon, 21 Jul 2025 19:23:15 +0200 Subject: [PATCH] feat: add timecode if there --- README.md | 2 +- background.js | 20 ++++++++++---------- manifest.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c8ecac7..5b7d594 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is a Firefox Addon that redirect youtube URL to the embed version to have a * click on "Load Temporary Add-on…" * select "manifest.json" file -## to have it in private navication +## to have it in private navigation * go to "about:addons" * select the extension diff --git a/background.js b/background.js index 15761f8..8e2650d 100644 --- a/background.js +++ b/background.js @@ -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"] ); - diff --git a/manifest.json b/manifest.json index 1a3c19b..e9f8fb4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 2, - "name": "YouTube URL Rewriter", + "name": "YouTube force embed", "version": "1.0", "description": "Rewrites YouTube URLs to embedded format.", "permissions": [