ya_sir commited on
Commit
6cdf17b
·
verified ·
1 Parent(s): 70146b6

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +224 -0
script.js ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.getElementById('jd').onclick = ()=>{
2
+ window.open('https://discord.gg/ju4yQBfQ7p')
3
+ }
4
+
5
+
6
+
7
+ /*document.getElementById('ow').onclick = ()=>{
8
+ window.open('https://www.buymeacoffee.com/mygx')
9
+ }*/
10
+
11
+
12
+ let dialog = document.getElementById('dialog')
13
+ let openbtn = document.getElementById('Advance Setting')
14
+ let closebtn = document.getElementById('close')
15
+ openbtn.onclick = ()=>{
16
+ dialog.show()
17
+ document.getElementById('imshow').style.border = '0px solid black transparent'
18
+ }
19
+ closebtn.onclick= ()=>{
20
+ dialog.close()
21
+ document.getElementById('imshow').style.background = 'linear-gradient(black, black) padding-box,linear-gradient(to right, red, blue) border-box'
22
+ }
23
+ let inp = document.getElementById('inp') //user prompt
24
+ let np = document.getElementById('np') // negative pr3
25
+ let gd = document.getElementById('gds') // guidence_scale value
26
+ let step = document.getElementById('step') // steps value
27
+ let seed = document.getElementById('seed') // seed value
28
+ let seedp = document.getElementById('seedp') // seed innerText
29
+ let stepp = document.getElementById('stepp') // step innerText
30
+ let gdsp = document.getElementById('gdsp') // guidence_scale innerText
31
+ let btn = document.getElementById('create') // Create button
32
+ let heightp = 1024 // height of photo
33
+ let widthp = 1024 // width of photo
34
+ let cn = false
35
+ gd.addEventListener('input',()=>{
36
+ gdsp.innerText = gd.value
37
+ })
38
+ step.addEventListener('input',()=>{
39
+ stepp.innerText = step.value
40
+ })
41
+ seed.addEventListener('input',()=>{
42
+ seedp.innerText = seed.value
43
+ })
44
+ isFumes = true
45
+ let prompt = 'CINEMATIC'
46
+ let nps = ' ,(bad hands, bad anatomy, bad body, bad face, bad teeth, bad arms, bad legs, deformities:1.3),poorly drawn,deformed hands,deformed fingers,deformed faces,deformed eyes,mutated fingers,deformedbody parts,mutated body parts,mutated hands, disfigured,oversaturated,bad anatom,cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, deformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck,deformed eyes'
47
+ let reload = false
48
+
49
+ document.getElementById('styles').onchange = ()=>{
50
+ const selectedStyle = document.querySelector('input[name="style"]:checked');
51
+ if(selectedStyle.value =='photo'){
52
+
53
+ prompt = 'PHOTOGRAPHY'
54
+
55
+
56
+ }
57
+ if(selectedStyle.value == 'cinema'){
58
+
59
+ prompt = "CINEMATIC"}
60
+ if(selectedStyle.value == 'fantasy'){
61
+
62
+ prompt = "CREATIVE"
63
+ }
64
+
65
+ if(selectedStyle.value == 'fumes'){
66
+
67
+ prompt = 'FILM'
68
+ }
69
+
70
+
71
+ if(selectedStyle.value == 'no'){
72
+ prompt = 'LEONARDO'
73
+
74
+ }
75
+ }
76
+
77
+ document.getElementById('ratio').onchange = ()=>{
78
+ const selectedStyle = document.querySelector('input[name="ratio"]:checked');
79
+ if(selectedStyle.value =='1:1'){
80
+
81
+ widthp = 1024
82
+ heightp = 1024
83
+
84
+
85
+ }
86
+ if(selectedStyle.value == '16:9'){
87
+
88
+ widthp = 1024
89
+ heightp = 576
90
+ document.getElementById("img1").style.marginTop = "30%";
91
+
92
+ }
93
+ if(selectedStyle.value == '9:16'){
94
+
95
+ widthp = 576
96
+ heightp = 1024
97
+ }
98
+
99
+
100
+
101
+ if(selectedStyle.value == '1:2'){
102
+
103
+ widthp = 544
104
+ heightp = 1088
105
+ }
106
+
107
+
108
+
109
+
110
+ if(selectedStyle.value == '4:3'){
111
+ widthp = 896
112
+ heightp = 672
113
+
114
+ }
115
+
116
+ }
117
+
118
+
119
+
120
+ btn.onclick = async () => {
121
+ grecaptcha.ready(function () {
122
+ grecaptcha.execute('6Leqa5cpAAAAABVhh6FGouusHKaPjYz65-0Yy8kS', { action: 'submit' }).then(async function (token) {
123
+ if(cn == true){
124
+ window.location.reload()
125
+ }
126
+ btn.innerText = "CANCEL";
127
+ cn = true;
128
+ let div = document.getElementById('imshow');
129
+
130
+
131
+
132
+
133
+ div.innerHTML = '';
134
+ document.getElementById('imshow').innerHTML = '';
135
+ let pi = document.createElement('h5');
136
+
137
+
138
+
139
+ let progress = document.createElement('progress');
140
+ progress.value = 1;
141
+ progress.max = 100;
142
+
143
+ div.appendChild(progress);
144
+ setInterval(() => {
145
+ progress.value += 3;
146
+ }, 1100);
147
+
148
+ async function generate() {
149
+ cookie = localStorage.getItem("cookie");
150
+ u = localStorage.getItem("u");
151
+ sub = localStorage.getItem("sub");
152
+ if (cookie == null) {
153
+ cookie = '';
154
+ }
155
+ if (cookie == "undefined") {
156
+ cookie = '';
157
+ }
158
+ params = {
159
+ 'prompt': inp.value,
160
+ 'nprompt': np.value,
161
+ "steps": Number(step.value),
162
+ 'guidenceScale': Number(gd.value),
163
+ "style": prompt,
164
+ "width": Number(widthp),
165
+ "height": Number(heightp),
166
+ "alchemy": true,
167
+ "pr": true,
168
+ token: token
169
+ };
170
+
171
+ try {
172
+ const response = await fetch('https://fumes-api.onrender.com/leonardo', {
173
+ method: 'POST',
174
+ headers: {
175
+ 'Content-Type': 'application/json',
176
+ 'Connection': 'keep-alive',
177
+ },
178
+ body: JSON.stringify(params)
179
+ });
180
+ if (response.status == 400) {
181
+ pi.innerText = 'reCaptcha human validation failed ⭕ user is suspected to be bot ';
182
+ div.append(pi)
183
+ alert('human verification failed ')
184
+ console.log(pi)
185
+ }
186
+
187
+ cn = false
188
+ btn.innerText = "CREATE"
189
+ const data = await response.json();
190
+ localStorage.setItem("cookie", data.token);
191
+ localStorage.setItem("sub", data.sub);
192
+ localStorage.setItem("u", data.u);
193
+ console.log(data.result)
194
+ progress.innerHTML = ''
195
+ progress.style.display = 'none';
196
+ const img = document.createElement('img');
197
+ a = "1"
198
+ img.id = "hehe"
199
+ pi.innerHTML = ''
200
+ pi.innerText = ''
201
+ img.src = data.img[1];
202
+ if(window.innerWidth<600){
203
+ img.id = "img1"
204
+ }
205
+ div.appendChild(img);
206
+ console.log(widthp.innerText)
207
+ const img2 = document.createElement('img');
208
+ img2.src = data.img[2];
209
+ div.appendChild(img2);
210
+ btn.disabled = false
211
+ isimg = true
212
+ } catch (error) {
213
+ btn.disabled = false;
214
+ console.error('An error occurred:', error);
215
+ pi.innerText = 'reCaptcha human verification failed ❌ user is suspected to be bot ';
216
+ pi.style.color = "white"
217
+ }
218
+ }
219
+
220
+ await Promise.all([generate()]);
221
+ });
222
+ });
223
+ };
224
+