From e5ee77bf369c30c8b23ecfa7496d75503be5ef56 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Fri, 18 Jan 2019 19:49:43 +0000 Subject: Bug fix for direct links --- ContentScript.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ContentScript.js b/ContentScript.js index 4c37d633..7ef58317 100644 --- a/ContentScript.js +++ b/ContentScript.js @@ -1,4 +1,9 @@ -chrome.runtime.onMessage.addListener( +if(id = youtube_parser(document.URL)){ // Direct Links + SponsorsLookup(id); +} + + +chrome.runtime.onMessage.addListener( // URL Changes function(request, sender, sendResponse) { if (request.message === 'ytvideoid') { SponsorsLookup(request.id); @@ -20,10 +25,16 @@ function SponsorsLookup(id) { xmlhttp.send(null); } -function SponsorCheck(Sponsors) { +function SponsorCheck(Sponsors) { // Video skipping Sponsors.forEach(function (el, index) { if ((Math.floor(v.currentTime)) == el[0]) { v.currentTime = el[1]; } }); } + +function youtube_parser(url) { + var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; + var match = url.match(regExp); + return (match && match[7].length == 11) ? match[7] : false; +} -- cgit v1.2.3