-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
81 lines (79 loc) · 2.02 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
function setupContextMenu() {
chrome.contextMenus.update(
"Url-Net",
{ title: "Url Net", contexts: ["link"] },
function () {
if (chrome.runtime.lastError) {
chrome.contextMenus.create({
title: "Url Net",
contexts: ["link"],
id: "Url-Net",
visible: true,
});
}
}
);
}
function create_contribution_menu() {
chrome.contextMenus.update(
"contribute-links",
{ title: "Contribute Links To Us", contexts: ["all"] },
function () {
if (chrome.runtime.lastError) {
chrome.contextMenus.create({
title: "Contribute Links To Us",
contexts: ["link"],
parentId: "Url-Net",
id: "contribute-links",
visible: true,
});
}
}
);
}
function create_inspect_this_link() {
chrome.contextMenus.update(
"inspect-link",
{ title: "Inspect This Link", contexts: ["link"] },
function () {
if (chrome.runtime.lastError) {
chrome.contextMenus.create({
title: "Inspect This Link",
contexts: ["link"],
parentId: "Url-Net",
id: "inspect-link",
visible: true,
});
}
}
);
}
setupContextMenu();
create_contribution_menu();
create_inspect_this_link();
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "inspect-link") {
console.log(info.linkUrl);
fetch(info.linkUrl).then((response) => {
if (response.ok) {
const link = response.url;
console.log("Link stored:", link);
chrome.storage.sync.set({Link: link }, () => {
console.log("Link stored in local storage");
chrome.runtime.sendMessage({Link: link});
});
}
});
chrome.windows.create({
url: "popup/popup.html",
type: "popup",
width: 300,
height: 480,
left: 400,
top: 400
});
} else
if (info.menuItemId === "contribute-links") {
chrome.tabs.create({ url: "Contribute_Links/Contribute.html" });
}
});