forked from jaxnz/spfx-workbench-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
31 lines (28 loc) · 941 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
chrome.tabs.onActivated.addListener(tab => {
getTab().then(url => {
console.log(url);
if (url.endsWith('_layouts/15/workbench.aspx')) {
chrome.scripting.executeScript({
target: { tabId: tab.tabId, allFrames: true },
files: ['./foreground.js'],
}, );
}
});
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
getTab().then(url => {
if (url.endsWith('_layouts/15/workbench.aspx')) {
chrome.scripting.executeScript({
target: { tabId: tabId, allFrames: true },
files: ['./foreground.js'],
}, );
}
});
}
});
async function getTab() {
let queryOptions = { active: true, currentWindow: true };
let tabs = await chrome.tabs.query(queryOptions);
return tabs[0].url;
}