mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 13:07:05 +03:00
Update utils.js
This commit is contained in:
22
utils.js
22
utils.js
@@ -1,9 +1,21 @@
|
|||||||
function getYouTubeVideoID(url) {
|
function getYouTubeVideoID(url) {
|
||||||
let obj = new URL(url);
|
|
||||||
if(obj.host !== "www.youtube.com" || "www.youtube-nocookie.com") return false // Check if valid hostname
|
try { // Attempt to parse url
|
||||||
if (obj.pathname == "/watch") id = obj.searchParams.get("v"); // Get ID from searchParam
|
let obj = new URL(url);
|
||||||
if (obj.pathname.startsWith("/embed/")) id = obj.pathname.slice("/embed/".length); // Get ID from end or URL
|
} catch (e) {
|
||||||
return id.length == 11 ? id : false;
|
return false
|
||||||
|
console.error("[SB] Unable to parser URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(obj.host)) return false // Check if valid hostname
|
||||||
|
|
||||||
|
if (obj.pathname == "/watch" && obj.searchParams.has("v")) {
|
||||||
|
id = obj.searchParams.get("v"); // Get ID from searchParam
|
||||||
|
} else if (obj.pathname.startsWith("/embed/")) {
|
||||||
|
id = obj.pathname.slice("/embed/".length); // Get ID from end or URL
|
||||||
|
}
|
||||||
|
|
||||||
|
return id.length == 11 ? id : false; // If ID is not 11 in length return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
||||||
|
|||||||
Reference in New Issue
Block a user