-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (68 loc) · 2.01 KB
/
Copy pathindex.js
File metadata and controls
88 lines (68 loc) · 2.01 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
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
const spinner = document.getElementById("spinner");
const imgEle = document.getElementById("image-output");
function init() {
let select = document.getElementById("category");
fetch("https://cataas.com/api/tags")
.then(resp => resp.json())
.then(data => {
for (var i=1; i<data.length; i++) {
let option = document.createElement("option");
option.value = data[i];
option.innerHTML = data[i];
select.appendChild(option);
}
console.log()
})
};
init();
function handleSubmission(event) {
event.preventDefault();
spinner.classList.remove('hidden');
imgEle.classList.add('hidden');
const type = document.getElementById("category").value;
const text = document.getElementById("text").value;
const rotate = document.getElementById("rotate").value;
const flip = document.getElementById("flip").value;
const random = document.getElementById("random").checked;
const params = {
type,
text,
rotate,
flip,
random
}
console.log(type)
console.log(text)
console.log(rotate)
console.log(flip)
console.log(random)
getImg(params)
}
function getImg(params) {
console.log(params)
const endpoint = "https://yfpc1dcdda.execute-api.us-east-1.amazonaws.com/Prod/?";
const jP = jQuery.param({
category: params.type,
text: params.text,
rotate: params.rotate,
flip: params.flip,
random: params.random,
});
console.log(endpoint + jP)
fetch(endpoint + jP, {
headers: {
"Content-Type": 'text/plain'
},
})
.then(resp => resp.json())
.then(data => {
console.log(data)
setImg(data.base64Str)
})
}
function setImg(bs4) {
const base = `data:image/png;base64, `
imgEle.src = base + bs4
imgEle.classList.remove("hidden");
spinner.classList.add('hidden');
}