-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
44 lines (38 loc) · 1.14 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function doCopy() {
var out = document.getElementById("shrtlnk");
var copy = function (e) {
e.preventDefault();
if (e.clipboardData) {
e.clipboardData.setData('text/plain', out.value);
} else if (window.clipboardData) {
window.clipboardData.setData('Text', out.value);
}
}
window.addEventListener('copy', copy);
document.execCommand('copy');
window.removeEventListener('copy', copy);
}
// on load request the short link
document.addEventListener("DOMContentLoaded", function(event) {
var button = document.getElementById("doCopy");
button.onclick = doCopy;
getResults();
});
// update the input field
function showResult(link) {
var out = document.getElementById("shrtlnk");
out.value = link;
}
// call for the results
function getResults() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{action: "checkit"},
function(response) {
if (response != null)
showResult(response.url);
}
);
});
}