mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Added getYouTubeVideoID
This commit is contained in:
parent
18909ffef6
commit
f6c9e8e235
1 changed files with 11 additions and 0 deletions
11
utils.js
Normal file
11
utils.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||
var match = url.match(regExp);
|
||||
var id = new URL(url).searchParams.get("v");
|
||||
if (url.includes("/embed/")) {
|
||||
//it is an embed, don't search for v
|
||||
id = match[7];
|
||||
}
|
||||
|
||||
return (match && match[7].length == 11) ? id : false;
|
||||
}
|
Loading…
Reference in a new issue