-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (34 loc) · 1.07 KB
/
background.js
File metadata and controls
38 lines (34 loc) · 1.07 KB
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
const CONTEXT_MENU_ID = "copyRepostUrl";
let isCreatingMenu = false;
function setupContextMenu() {
if (isCreatingMenu) {
return;
}
isCreatingMenu = true;
chrome.contextMenus.removeAll(() => {
chrome.contextMenus.create({
id: CONTEXT_MENU_ID,
title: chrome.i18n.getMessage("contextMenuTitle"),
contexts: ["page", "selection", "link", "image", "video"],
documentUrlPatterns: ["*://x.com/*", "*://twitter.com/*"]
}, () => {
isCreatingMenu = false;
});
});
}
chrome.runtime.onInstalled.addListener(setupContextMenu);
chrome.runtime.onStartup.addListener(setupContextMenu);
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "UPDATE_CONTEXT_MENU") {
chrome.contextMenus.update(CONTEXT_MENU_ID, {
enabled: message.enabled
}, () => {
if (chrome.runtime.lastError) {}
});
}
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === CONTEXT_MENU_ID && tab.id) {
chrome.tabs.sendMessage(tab.id, { type: "COPY_REPOST_URL_REQUEST" });
}
});