aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOfficial Noob <[email protected]>2019-08-07 15:34:21 +0100
committerGitHub <[email protected]>2019-08-07 15:34:21 +0100
commitc6c8d7de491281e38d21c0d9124bdb0e6c1d7644 (patch)
treeee468cff2c8f71dd2fae1710f42da0b1d667b886
parent02e11503cba1ee420a338e200e1a873ff71d081e (diff)
downloadSponsorBlock-c6c8d7de491281e38d21c0d9124bdb0e6c1d7644.tar.gz
SponsorBlock-c6c8d7de491281e38d21c0d9124bdb0e6c1d7644.zip
Update utils.js
-rw-r--r--utils.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/utils.js b/utils.js
index c1d6c23d..5e470e27 100644
--- a/utils.js
+++ b/utils.js
@@ -1,9 +1,21 @@
function getYouTubeVideoID(url) {
- let obj = new URL(url);
- if(obj.host !== "www.youtube.com" || "www.youtube-nocookie.com") return false // Check if valid hostname
- if (obj.pathname == "/watch") id = obj.searchParams.get("v"); // Get ID from searchParam
- if (obj.pathname.startsWith("/embed/")) id = obj.pathname.slice("/embed/".length); // Get ID from end or URL
- return id.length == 11 ? id : false;
+
+ try { // Attempt to parse url
+ let obj = new URL(url);
+ } catch (e) {
+ 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)