commit b92fdb6b91627e29962335e8ba9c6a7aa721a5f5 Author: setop Date: Tue Mar 18 14:45:35 2025 +0100 working diff --git a/background.js b/background.js new file mode 100644 index 0000000..6b61c29 --- /dev/null +++ b/background.js @@ -0,0 +1,20 @@ +// 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: [""] }, + ["blocking"] +); + diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..797832a Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..1a3c19b --- /dev/null +++ b/manifest.json @@ -0,0 +1,17 @@ +{ + "manifest_version": 2, + "name": "YouTube URL Rewriter", + "version": "1.0", + "description": "Rewrites YouTube URLs to embedded format.", + "permissions": [ + "webRequest", + "webRequestBlocking", + "" + ], + "background": { + "scripts": ["background.js"] + }, + "icons": { + "128": "icon.png" + } +}