This commit is contained in:
Official Noob 2019-01-18 20:00:57 +00:00 committed by GitHub
parent 4bf3cac622
commit 527c999ed5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
chrome.tabs.onUpdated.addListener( chrome.tabs.onUpdated.addListener( // On tab update
function(tabId, changeInfo, tab) { function(tabId, changeInfo, tab) {
if (changeInfo.url && id = youtube_parser(changeInfo.url)) { if (changeInfo.url && id = youtube_parser(changeInfo.url)) { // If URL changed and is youtube video message ContentScript the video id
chrome.tabs.sendMessage( tabId, { chrome.tabs.sendMessage( tabId, {
message: 'ytvideoid', message: 'ytvideoid',
id: id id: id
@ -8,7 +8,7 @@ chrome.tabs.onUpdated.addListener(
} }
} }
); );
function youtube_parser(url) { function youtube_parser(url) { // Return video id or false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp); var match = url.match(regExp);
return (match && match[7].length == 11) ? match[7] : false; return (match && match[7].length == 11) ? match[7] : false;