SponsorBlock/background.js

16 lines
591 B
JavaScript
Raw Normal View History

2019-01-18 21:00:57 +01:00
chrome.tabs.onUpdated.addListener( // On tab update
2019-01-15 19:24:44 +01:00
function(tabId, changeInfo, tab) {
2019-01-18 21:00:57 +01:00
if (changeInfo.url && id = youtube_parser(changeInfo.url)) { // If URL changed and is youtube video message ContentScript the video id
2019-01-15 19:24:44 +01:00
chrome.tabs.sendMessage( tabId, {
2019-01-15 20:01:37 +01:00
message: 'ytvideoid',
2019-01-18 20:50:09 +01:00
id: id
2019-01-15 19:24:44 +01:00
})
}
}
);
2019-01-18 21:00:57 +01:00
function youtube_parser(url) { // Return video id or false
2019-01-15 19:24:44 +01:00
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
return (match && match[7].length == 11) ? match[7] : false;
}