-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
33 lines (28 loc) · 948 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
26
27
28
29
30
31
32
33
var ogurl = "";
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, "msg", function(response) {
ogurl = response.ogurl;
document.getElementById("img-preview").src = ogurl;
document.getElementById("img-url").href = ogurl;
var idealLength = 50;
var ogurlLength = ogurl.length;
if (ogurlLength > idealLength) {
var extra = ogurlLength - idealLength;
var middle = Math.floor(ogurlLength/3);
var ogurlTrunc = ogurl.replace(ogurl.slice(middle,middle+extra), "...");
document.getElementById("img-url").innerHTML = ogurlTrunc;
}
else {
document.getElementById("img-url").innerHTML = ogurl;
}
});
});
document.getElementById("img-preview").onclick = download;
function download() {
if (ogurl != "") {
chrome.downloads.download({
url: ogurl,
filename: ogurl.split("/").pop().replace(/\?.*/, '')
});
}
}