-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaifu-generator.html
250 lines (218 loc) · 9.02 KB
/
waifu-generator.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Waifu Generator</title>
<style>
body {
padding: 0;
margin: 0;
overflow: hidden;
}
textarea {
font-size:16px;
display: block;
margin-left: auto;
margin-right: auto;
}
.centerpoint {
display: flex;
justify-content: center;
}
input[type=text], select {
font-size:16px;
width: 150px;
padding: 12px 20px;
margin: 20px 8px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
img {
margin: 20px 8px;
}
button {
font-size:16px;
width: 300px;
background-color: rgb(77, 77, 77);
color: white;
padding: 14px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #686868;
}
.painted {
background-color: rgb(240, 240, 240);
}
.crop {
width: 400px;
height: 400px;
margin: 20px 8px;
overflow: hidden;
}
.crop img {
width: 512px;
height: 512px;
margin: -56px -56px -56px -56px;
}
</style>
</head>
<body>
<br><br>
<div class="painted">
<form id="generateByValue" onsubmit="generateByValue(); return false;" autocomplete="off"> <!-- Wrapping this in a form lets you hit enter to submit, return false; prevents the page from refreshing on submission -->
<div class="centerpoint">
<img src='images/pose_icon.png' title="pose">
<input type="text" id="pose" placeholder="Enter value...">
<img src='images/base_icon.png' title="base">
<input type="text" id="base" placeholder="Enter value...">
<img src='images/color_icon.png' title="color">
<input type="text" id="color" placeholder="Enter value...">
<button type="button" id="waifuGenByValue" onclick="generateByValue()" style="margin: 21px 8px; width: 200px">Generate from Values</button>
</div>
</form>
</div>
<br>
<div class="painted">
<form id="generateByName" onsubmit="generateByName(); return false;" autocomplete="off"> <!-- Wrapping this in a form lets you hit enter to submit, return false; prevents the page from refreshing on submission -->
<div class="centerpoint">
<img src='images/name_icon.png' title="name">
<input type="text" id="waifuName" placeholder="Enter waifu name..." style="width: 500px">
<button type="button" id="waifuGenByName" onclick="generateByName()" style="margin: 21px 8px; width: 200px">Generate from Name</button>
</div>
</form>
</div>
<!-- Apparently buttons need to be of the type button to not double-submit... -->
<br>
<div class="painted">
<div class="centerpoint">
<img id="waifu" src="images/0chan1.png" width=400 height=400 title="0, 0, 0">
<div class="crop">
<img id="poster" src="images/0chan2.png" title="0, 0, 0"> <!-- The poster isn't actually 400x400, we need to crop it -->
</div>
</div>
</div>
<div class="centerpoint">
<p style="color:rgb(150, 150, 150)">API created by Sizigi Studios and officially available at waifulabs.com</p>
</div>
<!-- JAVASCRIPT BEYOND THIS POINT, BE WARNED -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
function generateByValue()
{
base = document.getElementById("base").value;
color = document.getElementById("color").value;
pose = document.getElementById("pose").value;
if(base === "") { base = 0; }
if(color === "") { color = 0; }
if(pose === "") { pose = 0; }
// The API can only handle 9 digit positive integers, anything else we can hash
if (/[^$,\.\d]/.test(base) || base.toString().length > 9 || (base.length > 1 && base.charAt(0) == '0'))
{
baseHash = base.hashCode();
base = baseHash.toString().substr(0,8);
if(base.charAt(0) == '-')
{
base = base.substr(1);
}
}
if (/[^$,\.\d]/.test(color) || color.toString().length > 9 || (color.length > 1 && color.charAt(0) == '0'))
{
colorHash = color.hashCode();
color = colorHash.toString().substr(0,8);
if(color.charAt(0) == '-')
{
color = color.substr(1);
}
}
if (/[^$,\.\d]/.test(pose) || pose.toString().length > 9 || (pose.length > 1 && pose.charAt(0) == '0'))
{
poseHash = pose.hashCode();
pose = poseHash.toString().substr(0,8);
if(pose.charAt(0) == '-')
{
pose = pose.substr(1);
}
}
document.getElementById("waifu").title = document.getElementById("poster").title = "".concat(pose, ", ", base, ", ", color);
dna = '{"currentGirl":['.concat(pose, ',0,0,0,', base, ',0,0,0,0,0,0,0,', color, ',0,0,0,0,[0.0,0.0,0.0]],"step":4}');
poster = '{"currentGirl":['.concat(pose, ',0,0,0,', base, ',0,0,0,0,0,0,0,', color, ',0,0,0,0,[0.0,0.0,0.0]],"step":4,"product":"POSTER"}');
$.ajax
({
type: "POST",
url: 'https://api.waifulabs.com/generate_big',
contentType: 'application/json',
dataType: 'json',
data: dna,
success: function(data, textStatus, xhr) { waifu = 'data:image/png;charset=utf-8;base64,'.concat(JSON.stringify(data).substr(9).slice(0,-2)); document.getElementById("waifu").src = waifu;}
})
$.ajax
({
type: "POST",
url: 'https://api.waifulabs.com/generate_preview',
contentType: 'application/json',
dataType: 'json',
data: poster,
success: function(data, textStatus, xhr) { waifu = 'data:image/png;charset=utf-8;base64,'.concat(JSON.stringify(data).substr(9).slice(0,-2)); document.getElementById("poster").src = waifu;}
})
}
// "borrowed" from Stack Overflow
String.prototype.hashCode = function() // now we can do str.hashCode() to get a hashCode for a string
{
var hash = 0;
var i;
var chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
function generateByName()
{
waifuName = document.getElementById("waifuName").value;
seed = "";
if (!(waifuName.length > 1 && waifuName.charAt(0) == '0') && (/^\d+$/.test(waifuName) && waifuName.toString().length < 10)) // Makes it so "753" as the value matches "753" as the name
{
seed = waifuName;
}
else // Hash the value into a valid 1 to 9 digit positive integer
{
nameHash = waifuName.hashCode();
seed = nameHash.toString().substr(0,8);
if(seed.charAt(0) == '-')
{
seed = seed.substr(1);
}
}
document.getElementById("waifu").title = document.getElementById("poster").title = seed.concat(", ", seed, ", ", seed);
dna = '{"currentGirl":['.concat(seed, ',0,0,0,', seed, ',0,0,0,0,0,0,0,', seed, ',0,0,0,0,[0.0,0.0,0.0]],"step":4}');
poster = '{"currentGirl":['.concat(seed, ',0,0,0,', seed, ',0,0,0,0,0,0,0,', seed, ',0,0,0,0,[0.0,0.0,0.0]],"step":4,"product":"POSTER"}');
$.ajax
({
type: "POST",
url: 'https://api.waifulabs.com/generate_big',
contentType: 'application/json',
dataType: 'json',
data: dna,
success: function(data, textStatus, xhr) { waifu = 'data:image/png;charset=utf-8;base64,'.concat(JSON.stringify(data).substr(9).slice(0,-2)); document.getElementById("waifu").src = waifu;}
})
$.ajax
({
type: "POST",
url: 'https://api.waifulabs.com/generate_preview',
contentType: 'application/json',
dataType: 'json',
data: poster,
success: function(data, textStatus, xhr) { waifu = 'data:image/png;charset=utf-8;base64,'.concat(JSON.stringify(data).substr(9).slice(0,-2)); document.getElementById("poster").src = waifu;}
})
}
</script>
</body>
</html>