-
Notifications
You must be signed in to change notification settings - Fork 6
/
background.js
62 lines (53 loc) · 1.64 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Create all the context menu items.
*/
browser.contextMenus.create({
id: "clnu-link-context-n",
title: browser.i18n.getMessage("contextMenuItemOnLink"),
contexts: ["link"]
});
function createContextMenuItemOnTab(info) {
var mainversn = parseInt(info.version.split(".",1)[0]);
var onwhat = 'tab';
if (mainversn<53) {onwhat="all";}
browser.contextMenus.create({
id: "clnu-tab-context-n",
title: browser.i18n.getMessage("contextMenuItemOnTab"),
contexts: [onwhat]
});
}
browser.runtime.getBrowserInfo().then(createContextMenuItemOnTab);
var _linkinfo; //保存contentjs发送来的链接信息
browser.runtime.onMessage.addListener(function (info) {
_linkinfo = info;
});
function CopyOnLink(info,tab)
{
browser.storage.local.get('format').then((res) => {
formatvalue = res.format || '%U %T';
browser.tabs.sendMessage(tab.id, formatvalue.replace('%U',_linkinfo.url).replace('%T',_linkinfo.name));
});
//browser.tabs.sendMessage(tab.id, _linkinfo.url+ ' '+ _linkinfo.name);
}
function CopyOnTab(tab)
{
browser.storage.local.get('format').then((res) => {
formatvalue = res.format || '%U %T';
browser.tabs.sendMessage(tab.id, formatvalue.replace('%U',tab.url).replace('%T', tab.title));
});
//browser.tabs.sendMessage(tab.id,tab.url+ ' '+ tab.title);
}
/*
The click event listener, where we perform the appropriate action given the
ID of the menu item that was clicked.
*/
browser.contextMenus.onClicked.addListener(function(info, tab) {
switch (info.menuItemId) {
case "clnu-link-context-n":
CopyOnLink(info,tab);
break;
case "clnu-tab-context-n":
CopyOnTab(tab);
break;
}
});