-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
background-ff.js
83 lines (79 loc) · 2.26 KB
/
background-ff.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
83
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (
tab.url.match(/^https:\/\/github.com\/.*/) ||
tab.url.match(/^https:\/\/gitlab.com\/.*/) ||
tab.url.match(/^https:\/\/bitbucket.org\/.*/)
) {
chrome.action.enable(tabId);
} else {
chrome.action.disable(tabId);
}
});
chrome.tabs.onCreated.addListener(function (tab) {
if (
tab.url &&
(tab.url.match(/^https:\/\/github.com\/.*/) ||
tab.url.match(/^https:\/\/gitlab.com\/.*/) ||
tab.url.match(/^https:\/\/bitbucket.org\/.*/))
) {
chrome.action.enable(tabId);
} else if (tab.url) {
chrome.action.disable(tabId);
}
});
chrome.runtime.onStartup.addListener(() => {
chrome.action.disable();
});
chrome.runtime.onInstalled.addListener(() => {
chrome.action.disable();
});
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",
});
}
}
});
}
);
});