mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
20 lines
No EOL
719 B
JavaScript
20 lines
No EOL
719 B
JavaScript
chrome.tabs.onUpdated.addListener( // On tab update
|
|
function(tabId, changeInfo, tab) {
|
|
if (changeInfo != undefined && changeInfo.url != undefined) {
|
|
console.log(changeInfo)
|
|
let id = youtube_parser(changeInfo.url);
|
|
if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id
|
|
chrome.tabs.sendMessage( tabId, {
|
|
message: 'ytvideoid',
|
|
id: id
|
|
})
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
function youtube_parser(url) { // Return video id or false
|
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
|
var match = url.match(regExp);
|
|
return (match && match[7].length == 11) ? match[7] : false;
|
|
} |