mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 07:57:09 +03:00
Removed Regex as "looks bad"
This commit is contained in:
11
utils.js
11
utils.js
@@ -1,8 +1,9 @@
|
|||||||
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
function getYouTubeVideoID(url) {
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
let obj = new URL(url);
|
||||||
var match = url.match(regExp);
|
if(obj.host !== "www.youtube.com" || "www.youtube-nocookie.com") return false // Check if valid hostname
|
||||||
var id = url.includes("/embed/") ? match[7] : new URL(url).searchParams.get("v");
|
if (obj.pathname == "/watch") id = obj.searchParams.get("v"); // Get ID from searchParam
|
||||||
return (match && id.length === 11) ? id : false;
|
if (obj.pathname.startsWith("/embed/")) id = obj.pathname.slice("/embed/".length); // Get ID from end or URL
|
||||||
|
return id.length == 11 ? id : 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