-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
25 lines (24 loc) · 875 Bytes
/
popup.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
document.getElementById('shortenBtn').addEventListener('click', () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const url = tabs[0].url;
chrome.runtime.sendMessage({ action: "shortenURL", url: url }, (response) => {
const shortUrl = response.shortUrl;
const statusDiv = document.getElementById('status');
statusDiv.textContent = `Short URL: ${shortUrl}`;
statusDiv.style.display = 'block';
copyToClipboard(shortUrl);
statusDiv.addEventListener('click', () => {
copyToClipboard(shortUrl);
});
});
});
});
function copyToClipboard(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Short URL copied');
}