-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestpack.js
More file actions
45 lines (39 loc) · 1.1 KB
/
restpack.js
File metadata and controls
45 lines (39 loc) · 1.1 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
(function(d) {
var s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://restpack.io/save-as-pdf.js";
var x = d.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
})(window.document);
window.document.addEventListener("click", function(event) {
if (event.target.classList.contains("restpack-api")) {
event.preventDefault();
var elem = event.target;
var props = elem.getAttribute("data-props");
document.body.style.cursor = "wait";
var ajaxcallurl = window.ajaxcallurl;
fetch(ajaxcallurl, {
method: "POST",
body: "action=restpack_ajax",
headers: {
"Content-Type": "application/x-www-form-urlencoded;"
}
})
.then(function(data) {
document.body.style.cursor = "default";
return data.json();
})
.then(function(data) {
if (data.error) return alert(data.error);
window.open(data.image);
})
.catch(function(error) {
alert(error);
});
try {
JSON.parse(props);
} catch (e) {}
console.log("clicked");
}
});