-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground_script.js
More file actions
21 lines (20 loc) · 845 Bytes
/
background_script.js
File metadata and controls
21 lines (20 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
chrome.commands.onCommand.addListener(function(command) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (command === "activate-extension") {
chrome.tabs.sendMessage(tabs[0].id, {command: "toggleExtension"});
} else if (command === "activate-alternate-extension") {
chrome.tabs.sendMessage(tabs[0].id, {command: "toggleAlternateExtension"});
} else if (command === "copy-to-clipboard") {
chrome.tabs.sendMessage(tabs[0].id, {command: "copyToClipboard"}, function(response) {
copyTextToClipboard(response);
});
}
});
});
function copyTextToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
console.log('Text copied to clipboard');
}).catch(err => {
console.error('Failed to copy text: ', err);
});
}