-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
364 lines (321 loc) · 12.2 KB
/
index.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html>
<head>
<title>Hooooker</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<style>
body {
font-family: sans-serif;
font-size: 20px;
}
code {
background-color: lightgray;
padding: 0.1rem;
border-radius: 2px;
}
.bord {
border: 1px solid lightgray;
border-radius: 0.2rem;
}
div.bord {
padding-left: 1rem;
padding-right: 1rem;
margin-bottom: 1rem;
}
h2::before {
content: '# ';
font-style: italic;
font-family: monospace;
}
button,
.btn {
font-size: 1.5rem;
padding: 0.5rem;
background-color: darkslategray;
color: white;
border: none;
border-radius: 0.3rem;
}
button:active,
.btn:active {
background-color: lightgray;
color: black;
}
input {
font-size: 1.5rem;
border: none;
background-color: lightgray;
padding: 0.5rem;
border-radius: 0.3rem;
}
input:focus {
background-color: rgb(230, 230, 230);
}
.counter {
padding: 0.2rem;
font-size: 1.2rem;
}
.flx-hor-stretch {
display: flex;
flex-direction: row;
width: 100%;
gap: 1rem;
justify-content: space-evenly;
}
.flx-hor-stretch>* {
flex-grow: 1;
}
#fireimg {
width: 600px;
}
#samplescont {
overflow-x: scroll;
display: flex;
flex-direction: row;
gap: 1rem;
flex-wrap: nowrap;
}
#samplescont img {
height: 20rem;
}
.charizard-anim {
background-image: url('char.png');
background-size: 50px 50px;
background-repeat: repeat;
animation: 1s tilelol infinite linear;
cursor: copy;
}
@keyframes tilelol {
0% {
background-position: 0px 0px;
background-size: 50px 50px;
}
100% {
background-position: 50px 50px;
background-size: 50px 50px;
}
}
@media screen and (max-width: 800px) {
.flx-hor-stretch {
flex-direction: column;
}
#fireimg {
width: 100%;
}
}
</style>
</head>
<body>
<h1><span class="bord">e621-to-webhook</span> artillery</h1>
<!-- <img src="https://static1.e926.net/data/3b/06/3b067024c234ccde483c0445af0c85fc.png"> -->
<div class="bord">
<h2>Ammo collection</h2>
<label for="tags">Put e621 tags here:</label>
<input name="tags" id="tags" value="order:score -animated">
<br>
<small>
It's a good idea to add <code>-animated</code> since videos won't play automatically and their
content might be obscured by the title screen.
Things to experiment with: <code>order:score_asc</code> (extra devilish), <code>gay</code>
(self-explanatory), <code>rating:explicit</code> (to force explicit posts).
<br>
Paging and <code>order:random</code> probably doesn't work well together, so don't ask for more than 320
posts at a time when using it.
</small>
<br>
<label for="postcount">Number of posts to fetch (and choose randomly from):</label>
<input name="postcount" id="postcount" type="number" value="320">
<br>
<small>
320 is the maximum that can be fetched in a single query to the e621 API.
</small>
<div class="flx-hor-stretch">
<button id="loadbtn" onclick="loadImages()">Load it</button>
<button onclick="clearImages()">Clear it</button>
<button onclick="toggleSamples()">
<span id="showsamplestext">Show sample of 5 images <br><small>(do you <em>really</em> wanna do
that?)</small></span>
<span style="display: none;" id="hidesamplestext">OH GOD IT BURNS <br><small>(close it)</small></span>
</button>
<button id="filedrop" ondrop="dropTxt(event)" ondragover="event.stopPropagation(); event.preventDefault();" ondragenter="event.currentTarget.classList.add('charizard-anim')"
ondragleave="event.currentTarget.classList.remove('charizard-anim')">Drop .txt list here <br><small>click-to-open is not implemented</small></button>
</div>
<div id="samplescont" style="display:none;">
</div>
<p style="text-align: center;">
<code id="imgcount" class="counter">0</code> posts in ammo rack.
<button onclick="downloadImages()">Download ammo rack as .txt file</button>
</p>
</div>
<div class="bord">
<h2>Shot config</h2>
<p>
<label for="messagecontent">Message content (apart from embed):</label>
<br>
<input id="messagecontent" style="width: 100%; margin-right: 1rem;" value="@everyone">
</p>
<p>
<label for="embedtitle">Embed title:</label>
<input id="embedtitle" value=":thumbsup:">
</p>
</div>
<div class="bord">
<h2>Target setup</h2>
<p><input id="webhook" style="width: 100%; margin-right: 1rem;"
placeholder="https://discord.com/api/webhooks/…"></p>
</div>
<div class="bord">
<h2>Fire control</h2>
<div class="flx-hor-stretch">
<button onclick="fireAuto()">Fire (full auto) <br><small>click again to stop</small></button>
<button onclick="fire()">Fire (manual)</button>
<button onclick="erase()">Delete the webhook (sneaky)</button>
</div>
<p style="text-align: center;">Fired <code id="firecount" class="counter">0</code> rounds in total.</p>
<p><small>If it doesn't work (the tank thing should fire), and you're using some kind of tracker blocker (Privacy Badger did it for me specifically), turn it off as they might block Discord webhooks.</small></p>
</div>
<div style="text-align: center;">
<img src="tank0.png" id="fireimg">
</div>
<script>
const fireimg = document.getElementById('fireimg');
const loadbtn = document.getElementById('loadbtn');
const imgcount = document.getElementById('imgcount');
const intags = document.getElementById('tags');
const inpostcount = document.getElementById('postcount');
const showsamplestext = document.getElementById('showsamplestext');
const hidesamplestext = document.getElementById('hidesamplestext');
const samplescont = document.getElementById('samplescont');
const filedrop = document.getElementById('filedrop');
const inwebhook = document.getElementById('webhook');
const incontent = document.getElementById('messagecontent');
const inembedtitle = document.getElementById('embedtitle');
const outfirecount = document.getElementById('firecount');
const images = new Set();
async function dropTxt(ev) {
ev.preventDefault();
for (f of ev.dataTransfer.items) {
if (f.kind == 'file') {
(await f.getAsFile().text()).split('\n').forEach(i => images.add(i.trim()));
}
}
filedrop.classList.remove('charizard-anim');
imgcount.textContent = images.size;
}
async function fire() {
const img = [...images][Math.floor(Math.random() * images.size)];
try {
const resp = await sendWebhookMessage(inwebhook.value, incontent.value, inembedtitle.value, img);
if (resp.status == 204 || resp.status == 200) {
fireimg.src = 'tank.gif';
}
return true;
} catch (e) {
if (e.response?.status == 429) {
await new Promise(r => setTimeout(r, e.response.data.retry_after * 1000))
console.log(`Gun jammed. Try again ${e.response.data.retry_after} seconds later.`);
} else if (e.response?.status == 404) {
alert("The webhook doesn't exist.");
firing = false;
} else {
console.log('Uh oh');
console.log(e);
}
return false;
}
}
var firing = false;
var roundcount = 0;
async function fireAuto() {
if (firing) {
firing = false;
return;
}
firing = true;
while (firing) {
if (await fire()) {
roundcount++;
outfirecount.textContent = roundcount;
}
}
}
async function erase() {
axios.delete(inwebhook.value);
alert('goodbye little webhook');
}
async function loadImages() {
loadbtn.textContent = 'Loading...';
(await fetchE6(intags.value, inpostcount.value)).forEach(img => images.add(img));
loadbtn.textContent = 'Load it';
imgcount.textContent = images.size;
}
function clearImages() {
images.clear();
imgcount.textContent = 0;
}
var samplesShown = false;
function toggleSamples() {
samplesShown = !samplesShown;
if (samplesShown) {
showsamplestext.style.display = 'none';
hidesamplestext.style.display = 'inline';
samplescont.innerHTML = '';
samplescont.style.display = 'block';
const samples = [...images].sort(() => .5 - Math.random()).slice(0, 5);
samples.forEach(s => {
const img = document.createElement('img');
img.src = s;
samplescont.appendChild(img);
});
} else {
showsamplestext.style.display = 'inline';
hidesamplestext.style.display = 'none';
samplescont.style.display = 'none';
}
}
function downloadImages() {
// i hate this oh my god
const a = document.createElement('a');
a.href = 'data:text/plain,' + encodeURIComponent([...images].join('\n'));
a.download = 'images.txt';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
const E621_MAXLIMIT = 320;
async function fetchE6(tags, count) {
let posts = [];
let lastpost = null;
while (posts.length < count) {
const postsThisRound = Math.min(E621_MAXLIMIT, count - posts.length);
let url = `https://e621.net/posts.json?limit=${postsThisRound}&tags=${encodeURIComponent(tags)}`;
if (lastpost) {
url += `&page=b${lastpost}`;
}
const resp = await axios.get(url);
const fetchedPosts = resp.data.posts;
if (fetchedPosts.length == 0) {
break;
}
lastpost = fetchedPosts[fetchedPosts.length - 1].id;
posts.push(...fetchedPosts.filter(p => p.file.url).map(p => p.file.url));
}
return posts;
}
async function sendWebhookMessage(webhook, content, embedTitle, imageUrl) {
return await axios.post(webhook, {
content,
embeds: [{
title: embedTitle,
image: {
url: imageUrl
}
}]
});
}
</script>
</body>
</html>