-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
42 lines (39 loc) · 1.13 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
// This function copies the page title and URL to the clipboard
// Ctrl+Shift+C
function copyToClipboard() {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
const activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, { action: 'copyToClipboard' });
});
}
chrome.commands.onCommand.addListener(function (command) {
console.log('command', command)
if (command === 'copy-to-clipboard') {
copyToClipboard();
}
});
chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.create({
id: 'copyPageTitleAndUrl',
title: 'Copy Page Title and URL',
type: 'normal',
contexts: ['page']
})
})
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === 'copyPageTitleAndUrl') {
copyToClipboard()
}
})
// Notification
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'showNotification') {
// TODO show notification
// chrome.notifications.create({
// type: 'basic',
// iconUrl: './icons/icon.webp',
// title: request.title,
// message: request.message
// })
}
})