working
This commit is contained in:
commit
b92fdb6b91
20
background.js
Normal file
20
background.js
Normal file
@ -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: ["<all_urls>"] },
|
||||||
|
["blocking"]
|
||||||
|
);
|
||||||
|
|
17
manifest.json
Normal file
17
manifest.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 2,
|
||||||
|
"name": "YouTube URL Rewriter",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "Rewrites YouTube URLs to embedded format.",
|
||||||
|
"permissions": [
|
||||||
|
"webRequest",
|
||||||
|
"webRequestBlocking",
|
||||||
|
"<all_urls>"
|
||||||
|
],
|
||||||
|
"background": {
|
||||||
|
"scripts": ["background.js"]
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"128": "icon.png"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user