mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Fixed typos.
Co-author worked on creating this url parser. Co-Authored-By: Giacomo Rossetto <jackyman_cs4@live.it>
This commit is contained in:
parent
b964d93ea9
commit
ccafbf663c
1 changed files with 5 additions and 3 deletions
8
utils.js
8
utils.js
|
@ -1,13 +1,15 @@
|
|||
function getYouTubeVideoID(url) {
|
||||
|
||||
try { // Attempt to parse url
|
||||
//Attempt to parse url
|
||||
try {
|
||||
var obj = new URL(url);
|
||||
} catch (e) {
|
||||
console.error("[SB] Unable to parser URL");
|
||||
return false
|
||||
}
|
||||
|
||||
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(obj.host)) return false // Check if valid hostname
|
||||
//Check if valid hostname
|
||||
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(obj.host)) return false;
|
||||
|
||||
if (obj.pathname == "/watch" && obj.searchParams.has("v")) {
|
||||
id = obj.searchParams.get("v"); // Get ID from searchParam
|
||||
|
@ -17,7 +19,7 @@ function getYouTubeVideoID(url) {
|
|||
return obj.pathname.substr(7, 11);
|
||||
} catch (e) {
|
||||
console.error("[SB] Video ID not valid");
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue