-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
55 lines (49 loc) · 1.24 KB
/
Copy pathbackground.js
File metadata and controls
55 lines (49 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let matchesGH = (url) => {
return url.hostname == "github.com";
};
let matchesAD = (url) => {
const azureRegex = new RegExp("_git");
return url.hostname == "dev.azure.com" && azureRegex.test(url.pathname);
};
let redirectGH = (resp) => {
if (!resp.found) {
notFound(resp.tab);
return;
}
const url = new URL(resp.tab.url);
chrome.tabs.create({
url: "https://vscode.dev/github" + url.pathname,
});
};
let redirectAZ = (resp) => {
if (!resp.found) {
notFound(resp.tab);
return;
}
const url = new URL(resp.tab.url);
const search = url.searchParams;
if (!search.get("version")) {
search.set("version", resp.version)
}
chrome.tabs.create({
url:
"https://vscode.dev/azurerepos" + url.pathname + "?" + search.toString(),
});
};
let notFound = (tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["alert.js"],
});
};
chrome.action.onClicked.addListener((tab) => {
const url = new URL(tab.url);
console.log(url);
if (matchesGH(url)) {
chrome.tabs.sendMessage(tab.id, { tab: tab, page: "github" }, redirectGH);
} else if (matchesAD(url)) {
chrome.tabs.sendMessage(tab.id, { tab: tab, page: "devops" }, redirectAZ);
} else {
notFound(tab);
}
});