diff options
author | Official Noob <[email protected]> | 2019-01-15 18:24:44 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-01-15 18:24:44 +0000 |
commit | ec470408441d64b99a46b5e4af5d6151cfe74690 (patch) | |
tree | d00abd8f7affb8a0bd742c8ba15f3630bbacfca4 | |
parent | 27226b11688d48e02815ad1e61fad87bfa6ded64 (diff) | |
download | SponsorBlock-ec470408441d64b99a46b5e4af5d6151cfe74690.tar.gz SponsorBlock-ec470408441d64b99a46b5e4af5d6151cfe74690.zip |
Create background.js
-rw-r--r-- | background.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/background.js b/background.js new file mode 100644 index 00000000..3c0a0222 --- /dev/null +++ b/background.js @@ -0,0 +1,15 @@ +chrome.tabs.onUpdated.addListener( + function(tabId, changeInfo, tab) { + if (youtube_parser(changeInfo.url)) { + chrome.tabs.sendMessage( tabId, { + message: 'ytvideo', + url: changeInfo.url + }) + } + } +); +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; +} |