-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
19 lines (18 loc) · 827 Bytes
/
background.js
File metadata and controls
19 lines (18 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
chrome.webNavigation.onHistoryStateUpdated.addListener((details) => {
// A workaround because youtube fires mutliple tabs.onUpdated messages
if(details.frameId === 0){
chrome.tabs.get(details.tabId, (tab) => {
if(tab.url && tab.url.includes("youtube.com/watch")) {
// The unique part of a video URL is after the /v=?xxxxxxxxxxxxx
const queryParamters = tab.url.split("?")[1];
const urlParameters = new URLSearchParams(queryParamters);
console.log("message sent");
chrome.tabs.sendMessage(details.tabId, {
type: "NEW_YT_VIDEO",
videoId: urlParameters.get("v"),
ytTabId: details.tabId
});
}
});
}
});