-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
164 lines (143 loc) · 4.67 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Update the relevant fields with the new data.
window.onload = function () {
document.getElementById("loading").style.display = "none";
};
var photoIds = [];
var profileName;
var profileLink;
var wrapper;
const setDOMInfo = (info) => {
info.photoInfo.forEach((element) => {
if (!_.includes(photoIds, element.id)) {
// photoInfo.push({
// id: photoId,
// link: photoLink,
// place: photoPlace,
// address: photoAddress,
// });
photoIds.push(element.id);
// var src = element + "media?size=l";
var anchor = document.createElement("a");
anchor.id = element.id;
anchor.href = element.link;
anchor.download = "image";
anchor.classList.add("dl");
var img = document.createElement("img");
img.classList.add("download-image");
img.src = element.link;
toDataURL(img.src, function (dataURL) {
img.src = dataURL;
});
var place = document.createElement("p");
place.textContent = element.place;
place.classList.add("place");
var address = document.createElement("p");
address.textContent = element.address;
address.classList.add("address");
anchor.appendChild(img);
anchor.appendChild(place);
anchor.appendChild(address);
wrapper.appendChild(anchor);
}
});
document.getElementById("photos").textContent = photoIds.length;
document.getElementById("loading").style.display = "none";
};
const setBaseInfo = (info) => {
profileName = info.profile;
profileLink = info.link;
document.getElementById("title").textContent = info.profile + "'s profile";
document.getElementById("total").textContent = info.total;
document.getElementById("profile-link").textContent = info.link;
};
// Once the DOM is ready...
window.addEventListener("DOMContentLoaded", () => {
wrapper = document.getElementById("photo-grid");
// ...query for the active tab...
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
(tabs) => {
// ...and send a request for the DOM info...
chrome.tabs.sendMessage(
tabs[0].id,
{ from: "popup", subject: "baseInfo" },
// ...also specifying a callback to be called
// from the receiving end (content script).
setBaseInfo
);
}
);
document.getElementById("capture").addEventListener("click", () => {
document.getElementById("loading").style.display = "block";
// ...query for the active tab...
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
(tabs) => {
// ...and send a request for the DOM info...
chrome.tabs.sendMessage(
tabs[0].id,
{ from: "popup", subject: "capture" },
// ...also specifying a callback to be called
// from the receiving end (content script).
setDOMInfo
);
}
);
});
document.getElementById("dl_all").addEventListener("click", download_all);
});
function download(data) {
const a = document.createElement("a");
a.href = "data:application/zip;base64," + data;
a.setAttribute("download", profileName + "-burpple.zip");
a.style.display = "none";
a.addEventListener("click", (e) => e.stopPropagation()); // not relevant for modern browsers
document.body.appendChild(a);
setTimeout(() => {
// setTimeout - not relevant for modern browsers
a.click();
document.body.removeChild(a);
}, 0);
document.getElementById("loading").style.display = "none";
}
function download_all() {
document.getElementById("loading").style.display = "block";
var csvString = "fileName;place,;address;creditName;creditSocial\n";
var zip = new JSZip();
[...document.getElementsByClassName("dl")].forEach((anchor, i) => {
var img = anchor.querySelector(".download-image");
var fileName = profileName + "-img-" + i + ".jpg";
var place = anchor
.querySelector(".place")
.textContent.replace(/[']/g, "\\$&");
var address = anchor
.querySelector(".address")
.textContent.replace(/[']/g, "\\$&");
var csvRow = [fileName, place, address, profileName, profileLink].join(";");
csvString += csvRow + "\n";
zip.file(fileName, img.src.replace(/data:.*?;base64,/, ""), {
base64: true,
});
});
zip.file(profileName + "-img-details.csv", csvString);
zip.generateAsync({ type: "base64" }).then(download);
}
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("get", url);
xhr.responseType = "blob";
xhr.onload = function () {
var fr = new FileReader();
fr.onload = function () {
callback(this.result);
};
fr.readAsDataURL(xhr.response); // async call
};
xhr.send();
}