-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
30 lines (26 loc) · 893 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
// Oliver Kovacs 2021
const github = new RegExp("https:\/\/github\.com\/\\w+\/\\w+");
const timeout = 1000; // Google pls fix
const update = (url, tabId) => {
if (!url.match(github)) {
return chrome.action.disable(tabId);
}
chrome.action.enable(tabId);
chrome.action.onClicked.addListener(tab => {
chrome.storage.sync.get({ insiders: false }, items => {
chrome.tabs.update(tab.id, {
url: `vscode${items.insiders ? "-insiders" : ""}://GitHub.remotehub/open?url=${url}`,
});
});
});
};
chrome.tabs.onActivated.addListener(info => {
setTimeout(async () => {
const tab = await chrome.tabs.get(info.tabId);
update(tab.url, tab.id);
}, timeout);
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (!changeInfo.url) return;
update(changeInfo.url, tabId);
});