-
Notifications
You must be signed in to change notification settings - Fork 7
/
background.js
37 lines (32 loc) · 1.05 KB
/
background.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
const REQUEST_TITLE = 'copy-title-url-to-clipboard';
const REQUEST_SELECTION = 'copy-selection-url-to-clipboard';
/* This extension creates two context menu items: one for the default case,
and one to use when some text is selected on a web page. Only one of the
two items is shown at a time, otherwise Firefox puts them in a submenu,
which requires additional clicks to navigate.
*/
// support Firefox and Chrome
if (!browser) {
var browser = chrome;
}
browser.contextMenus.create({
id: REQUEST_TITLE,
title: "Copy Page Title and Url",
contexts: ["page"],
onclick: handleCopyRequest
});
browser.contextMenus.create({
id: REQUEST_SELECTION,
title: "Copy Selection and Url",
contexts: ["selection"],
onclick: handleCopyRequest
});
function handleCopyRequest(info, tab) {
// check in which context the command was clicked
const useSelection = info.menuItemId === REQUEST_SELECTION;
chrome.tabs.sendMessage(tab.id,
{tabUrl: tab.url,
tabTitle: tab.title,
useSelection: useSelection
});
}