-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (25 loc) · 792 Bytes
/
Copy pathbackground.js
File metadata and controls
27 lines (25 loc) · 792 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
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "setName",
title: "Set Custom Name for Address/Hash",
contexts: ["selection"],
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "setName") {
const selectedText = info.selectionText;
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: promptAndSetName,
args: [selectedText]
}).catch(err => console.error("Error executing script:", err));
}
});
function promptAndSetName(selectedText) {
const customName = prompt("Enter a custom name for this address/hash:", selectedText);
if (customName) {
chrome.storage.sync.set({ [selectedText]: customName }, () => {
location.reload();
});
}
}