From ec470408441d64b99a46b5e4af5d6151cfe74690 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 15 Jan 2019 18:24:44 +0000 Subject: Create background.js --- background.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 background.js 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; +} -- cgit v1.2.3