Create background.js

This commit is contained in:
Official Noob
2019-01-15 18:24:44 +00:00
committed by GitHub
parent 27226b1168
commit ec47040844

15
background.js Normal file
View File

@@ -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;
}