-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
56 lines (51 loc) · 2.16 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
'use strict';
chrome.runtime.onInstalled.addListener(() => {});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'updateContextMenu') {
if (message.showMenu) {
chrome.contextMenus.removeAll(() => {
chrome.contextMenus.create({
id: "copyLinkText",
title: "Copy Link Text",
contexts: ["all"],
documentUrlPatterns: ["<all_urls>"]
});
});
} else {
chrome.contextMenus.removeAll();
}
}
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === 'copyLinkText') {
chrome.tabs.sendMessage(tab.id, 'copy', { frameId: info.frameId }, response => {
if (response && response.copiedText) {
chrome.storage.sync.get(['notificationsEnabled'], (result) => {
const notificationsEnabled = result.notificationsEnabled !== undefined ? result.notificationsEnabled : true;
if (notificationsEnabled) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'images/icon-48x48.png',
title: 'Copy Link Text',
message: `Copied: "${response.copiedText}"`,
silent: true
});
}
});
} else {
chrome.storage.sync.get(['notificationsEnabled'], (result) => {
const notificationsEnabled = result.notificationsEnabled !== undefined ? result.notificationsEnabled : true;
if (notificationsEnabled) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'images/icon-48x48.png',
title: 'Copy Link Text',
message: 'No text to copy.',
silent: true
});
}
});
}
});
}
});