diff options
author | Official Noob <[email protected]> | 2019-01-18 19:49:43 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-01-18 19:49:43 +0000 |
commit | e5ee77bf369c30c8b23ecfa7496d75503be5ef56 (patch) | |
tree | 20cb038c4e40ef3def2028e529cc123d169a2c0f | |
parent | 9546fd42b1b740bcd38009fd25de0bd8a3bbd172 (diff) | |
download | SponsorBlock-e5ee77bf369c30c8b23ecfa7496d75503be5ef56.tar.gz SponsorBlock-e5ee77bf369c30c8b23ecfa7496d75503be5ef56.zip |
Bug fix for direct links
-rw-r--r-- | ContentScript.js | 15 |
1 files 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; +} |