-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
31 lines (30 loc) · 985 Bytes
/
background.js
File metadata and controls
31 lines (30 loc) · 985 Bytes
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
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "convertEpoch",
title: "Convert from epoch",
contexts: ["selection"],
});
chrome.contextMenus.create({
id: "grabDateNow",
title: "Give me Date.now to clipboard",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "openModal",
title: "Open Date to Epoch Converter",
contexts: ["all"],
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "convertEpoch") {
const epochTime = parseInt(info.selectionText.trim(), 10);
if (!isNaN(epochTime)) {
const convertedDate = new Date(epochTime).toLocaleString();
chrome.tabs.sendMessage(tab.id, { date: convertedDate });
}
} else if (info.menuItemId === "grabDateNow") {
chrome.tabs.sendMessage(tab.id, { msg: "Date.now()" });
} else if (info.menuItemId === "openModal") {
chrome.tabs.sendMessage(tab.id, { action: "openModal" });
}
});