-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
47 lines (44 loc) · 1.28 KB
/
background.js
File metadata and controls
47 lines (44 loc) · 1.28 KB
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
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.sendMessage(tab.id, { action: "extractUrl" }, (response) => {
if (response) {
if (response.success) {
showSuccessIcon();
alert(response.message);
} else {
alert(response.message);
}
} else {
console.error('No response from content script.');
}
});
});
function extractFirstUrl(content) {
const urlMatch = content.match(/https?:\/\/[^\s"]+/);
return urlMatch ? urlMatch[0] : null;
}
function copyToClipboard(text) {
const tempInput = document.createElement('input');
document.body.appendChild(tempInput);
tempInput.value = text;
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
}
function showSuccessIcon() {
chrome.action.setIcon({
path: {
"16": "icon16_success.png",
"48": "icon48_success.png",
"128": "icon128_success.png"
}
});
setTimeout(() => {
chrome.action.setIcon({
path: {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
});
}, 2000); // Revert back after 2 seconds
}