-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
background.js
82 lines (77 loc) · 2.25 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function ext() {
chrome.action.disable();
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
let rule = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: "github.com" },
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: "gitlab.com" },
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: "bitbucket.org" },
}),
],
actions: [new chrome.declarativeContent.ShowAction()],
};
let rules = [rule];
chrome.declarativeContent.onPageChanged.addRules(rules);
});
}
chrome.runtime.onStartup.addListener(() => {
ext();
});
chrome.runtime.onInstalled.addListener(() => {
ext();
});
chrome.action.onClicked.addListener((tab) => {
chrome.storage.sync.get(
{
protocol: "HTTPS",
application: "VS Code",
},
function (items) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
const url = new URL(tabs[0].url);
const path = url.pathname.split("/");
if (items.application == "VS Code") {
openApp = "vscode";
} else if (items.application == "VS Code Insiders") {
openApp = "vscode-insiders";
} else if (items.application == "VSCodium") {
openApp = "vscodium";
} else if (items.application == "VSCodium Insiders") {
openApp = "vscodium-insiders";
}
if (path[1] !== undefined && path[2] !== undefined) {
if (items.protocol == "HTTPS") {
chrome.tabs.update({
url:
openApp +
"://vscode.git/clone?url=https://" +
url.hostname +
"/" +
path[1] +
"/" +
path[2] +
".git",
});
} else if (items.protocol == "SSH") {
chrome.tabs.update({
url:
openApp +
"://vscode.git/clone?url=git@" +
url.hostname +
":" +
path[1] +
"/" +
path[2] +
".git",
});
}
}
});
}
);
});