feat: add timecode if there
This commit is contained in:
parent
e5097d820a
commit
7e6fc2e6e4
@ -1,21 +1,21 @@
|
|||||||
// Listen for web requests
|
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
function(details) {
|
function(details) {
|
||||||
const url = new URL(details.url);
|
const url = new URL(details.url);
|
||||||
|
|
||||||
// Check if the URL is a YouTube URL
|
|
||||||
if (url.hostname === "www.youtube.com" || url.hostname === "youtube.com") {
|
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");
|
const videoId = url.searchParams.get("v");
|
||||||
if (videoId) {
|
if (videoId) {
|
||||||
// Rewrite to the embedded URL format
|
// Rewrite to the embedded URL format, picking timecode if available
|
||||||
const embedUrl = `https://www.youtube.com/embed/${videoId}`;
|
const timecode = url.searchParams.get("t");
|
||||||
return { redirectUrl: embedUrl };
|
return {
|
||||||
|
redirectUrl: `https://www.youtube-nocookie.com/embed/${videoId}?rel=0` + (timecode ? "&start=" + timecode : "");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ urls: [ "*://www.youtube.com/*",
|
{ urls: [
|
||||||
"*://youtube.com/*"] },
|
"*://www.youtube.com/*",
|
||||||
|
"*://youtube.com/*"
|
||||||
|
]},
|
||||||
["blocking"]
|
["blocking"]
|
||||||
);
|
);
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "YouTube URL Rewriter",
|
"name": "YouTube force embed",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"description": "Rewrites YouTube URLs to embedded format.",
|
"description": "Rewrites YouTube URLs to embedded format.",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user