mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-11 09:30:46 +01:00
Merge pull request #214 from OfficialNoob/patch-26
getYouTubeVideoID ~ TV support
This commit is contained in:
commit
9cb4fd6f79
1 changed files with 10 additions and 8 deletions
12
utils.js
12
utils.js
|
@ -19,20 +19,23 @@ async function wait(condition, timeout = 5000, check = 100) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) {
|
function getYouTubeVideoID(url) {
|
||||||
|
// For YouTube TV support
|
||||||
|
if(document.URL.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", "");
|
||||||
|
|
||||||
//Attempt to parse url
|
//Attempt to parse url
|
||||||
let urlObject = null;
|
let urlObject = null;
|
||||||
try {
|
try {
|
||||||
urlObject = new URL(url);
|
urlObject = new URL(url);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[SB] Unable to parse URL: " + url);
|
console.error("[SB] Unable to parse URL: " + url);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if valid hostname
|
//Check if valid hostname
|
||||||
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
|
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
|
||||||
|
|
||||||
//Get ID from searchParam
|
//Get ID from searchParam
|
||||||
if ((urlObject.pathname == "/watch" || urlObject.pathname == "/watch/") && urlObject.searchParams.has("v")) {
|
if (urlObject.searchParams.has("v") && ["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) {
|
||||||
id = urlObject.searchParams.get("v");
|
id = urlObject.searchParams.get("v");
|
||||||
return id.length == 11 ? id : false;
|
return id.length == 11 ? id : false;
|
||||||
} else if (urlObject.pathname.startsWith("/embed/")) {
|
} else if (urlObject.pathname.startsWith("/embed/")) {
|
||||||
|
@ -43,7 +46,6 @@ function getYouTubeVideoID(url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue