-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
37 lines (35 loc) · 1.32 KB
/
background.js
File metadata and controls
37 lines (35 loc) · 1.32 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
browser.pageAction.onClicked.addListener(async (tab) => {
const pageTitle = tab.title;
const pageURL = tab.url;
pasteToClipboard(await fillFormatStructure(pageURL, pageTitle, await getFormats()))
});
browser.contextMenus.removeAll().then(() => {
browser.contextMenus.create({
id: "share-dis-copy-page",
title: "Copy page URL as formatted link to clipboard",
contexts: ["page", "selection", "link"]
});
browser.contextMenus.create({
id: "share-dis-copy-selection",
title: "Quote selected text in page as formatted link to clipboard",
contexts: ["selection"]
});
browser.contextMenus.create({
id: "share-dis-copy-link",
title: "Copy highlighted link in page as formatted link to clipboard",
contexts: ["link"]
});
});
browser.contextMenus.onClicked.addListener(async (info, tab) => {
let pageTitle = tab.title;
let pageURL = tab.url;
let method = 'default';
if (info.menuItemId === "share-dis-copy-link" && info.linkUrl) {
pageURL = info.linkUrl;
}
else if (info.menuItemId === "share-dis-copy-selection" && info.selectionText) {
pageTitle = `‟${info.selectionText}”`;
method = 'quote';
}
pasteToClipboard(await fillFormatStructure(pageURL, pageTitle, await getFormats(method)));
});