-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathservice_worker.js
95 lines (85 loc) · 2.38 KB
/
service_worker.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
84
85
86
87
88
89
90
91
92
93
94
95
// // Remove all existing context menu items to avoid duplicates
// chrome.contextMenus.removeAll(() => {
// // Create the context menu item
// chrome.contextMenus.create({
// id: "LetXPath",
// title: "Select Parent",
// contexts: ["all"],
// });
// });
let isSource = false;
function toggle() {
isSource = !isSource;
if (isSource) {
chrome.contextMenus.update("LetXPath", { title: "Select Child" }, () => {});
} else {
chrome.contextMenus.update(
"LetXPath",
{ title: "Select Parent" },
() => {}
);
}
}
async function sendMessageTotab(tab, msg) {
chrome.tabs.sendMessage(tab, msg).then("Sent to CS");
// return new Promise((resolve) => {
// resolve(response);
// });
}
function getXPath(info, tab) {
const msg = { request: "context_menu_click" };
sendMessageTotab(tab.id, msg);
}
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "LetXPath") {
toggle();
getXPath(info, tab);
}
});
function sendToContentScript(request) {
sendMessageTotab(request.tab, request);
}
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (
["parseAxes", "userSearchXP", "dotheconversion", "cleanhighlight"].includes(
message.request
)
) {
sendToContentScript(message);
sendResponse("Hello");
}
});
const installURL = chrome.runtime.getURL("install.html");
const updateURL = "https://github.com/ortoniKC/LetXPath/releases";
function handleInstall(details) {
if (details.reason === "install") {
chrome.tabs.create({ url: installURL });
chrome.notifications.create({
title: "LetXPath By LetCode with Koushik",
message: "Please restart your browser to use LetXPath",
iconUrl: "assets/32.png",
type: "basic",
});
}
// else if (details.reason === "update") {
// updateNotification();
// chrome.notifications.onClicked.addListener(onClickNotification);
// }
chrome.contextMenus.create({
id: "LetXPath",
title: "Select Parent",
contexts: ["all"],
});
}
function onClickNotification() {
chrome.tabs.create({ url: updateURL });
}
function updateNotification() {
chrome.notifications.create({
title: "LetXPath",
message: "LetXPath has been updated. Please click to read the changelog.",
iconUrl: "assets/32.png",
type: "basic",
});
}
chrome.runtime.onInstalled.addListener(handleInstall);