-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
2165 lines (1843 loc) · 83.9 KB
/
Copy pathscript.js
File metadata and controls
2165 lines (1843 loc) · 83.9 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Webook - Discord Webhook Interface
// Main application state and functionality
class WebookApp {
constructor() {
this.webhooks = [];
this.savedMessages = [];
this.embeds = [];
this.currentWebhook = null;
this.currentEmbedIndex = null;
// Message pool state
this.messagePoolIndex = 0;
this.init();
}
init() {
this.loadFromStorage();
this.bindEvents();
this.renderWebhooks();
this.renderSavedMessages();
this.updatePreview();
this.renderWebhookCheckboxes();
// Loop state
this.isLooping = false;
this.currentLoop = null;
this.loopIteration = 0;
this.totalLoops = 0;
}
// Storage management
loadFromStorage() {
const savedWebhooks = localStorage.getItem('webook_webhooks');
const savedMessages = localStorage.getItem('webook_messages');
if (savedWebhooks) {
this.webhooks = JSON.parse(savedWebhooks);
}
if (savedMessages) {
this.savedMessages = JSON.parse(savedMessages);
}
}
saveToStorage() {
localStorage.setItem('webook_webhooks', JSON.stringify(this.webhooks));
localStorage.setItem('webook_messages', JSON.stringify(this.savedMessages));
}
// Event binding
bindEvents() {
// Webhook management
document.getElementById('addWebhookBtn').addEventListener('click', () => this.showWebhookModal());
document.getElementById('saveWebhookBtn').addEventListener('click', () => this.saveWebhook());
document.getElementById('cancelBtn').addEventListener('click', () => this.hideWebhookModal());
// Embed management
document.getElementById('addEmbedBtn').addEventListener('click', () => this.showEmbedModal());
document.getElementById('clearEmbedsBtn').addEventListener('click', () => this.clearEmbeds());
document.getElementById('saveEmbedBtn').addEventListener('click', () => this.saveEmbed());
document.getElementById('cancelEmbedBtn').addEventListener('click', () => this.hideEmbedModal());
// Message actions
document.getElementById('sendBtn').addEventListener('click', () => this.sendMessage());
document.getElementById('previewBtn').addEventListener('click', () => this.updatePreview());
document.getElementById('saveMessageBtn').addEventListener('click', () => this.saveCurrentMessage());
document.getElementById('clearBtn').addEventListener('click', () => this.clearEditor());
// Real-time preview updates
['username', 'avatarUrl', 'content'].forEach(id => {
document.getElementById(id).addEventListener('input', () => this.updatePreview());
});
// Footer actions
document.getElementById('exportBtn').addEventListener('click', (e) => {
e.preventDefault();
this.exportConfig();
});
document.getElementById('importBtn').addEventListener('click', (e) => {
e.preventDefault();
this.importConfig();
});
document.getElementById('helpBtn').addEventListener('click', (e) => {
e.preventDefault();
this.showHelp();
});
document.getElementById('githubBtn').addEventListener('click', (e) => {
e.preventDefault();
this.openGitHub();
});
// Close modals on outside click
document.querySelectorAll('.modal').forEach(modal => {
modal.addEventListener('click', (e) => {
if (e.target === modal) {
modal.classList.remove('active');
}
});
});
// Advanced controls events
document.getElementById('loopSendBtn').addEventListener('click', () => this.startLoop());
document.getElementById('stopLoopBtn').addEventListener('click', () => this.stopLoop());
document.getElementById('selectAllBtn').addEventListener('click', () => this.selectAllWebhooks());
document.getElementById('deselectAllBtn').addEventListener('click', () => this.deselectAllWebhooks());
// Update webhook checkboxes when webhooks change
this.updateWebhookCheckboxes();
// New feature event listeners
document.getElementById('useMessagePool').addEventListener('change', (e) => {
document.getElementById('messagePoolControls').style.display = e.target.checked ? 'block' : 'none';
this.updatePoolInfo();
});
document.getElementById('useRandomIdentity').addEventListener('change', (e) => {
document.getElementById('randomIdentityControls').style.display = e.target.checked ? 'block' : 'none';
this.loadRandomIdentityData();
});
document.getElementById('addToPoolBtn').addEventListener('click', () => this.addCurrentToPool());
document.getElementById('managePoolBtn').addEventListener('click', () => this.manageMessagePool());
// Load saved data
this.loadMessagePool();
this.loadRandomIdentityData();
this.updatePoolInfo();
}
// Webhook management
showWebhookModal(webhook = null) {
const modal = document.getElementById('webhookModal');
const nameInput = document.getElementById('webhookName');
const urlInput = document.getElementById('webhookUrl');
if (webhook) {
nameInput.value = webhook.name;
urlInput.value = webhook.url;
this.currentWebhook = webhook;
} else {
nameInput.value = '';
urlInput.value = '';
this.currentWebhook = null;
}
modal.classList.add('active');
nameInput.focus();
}
hideWebhookModal() {
document.getElementById('webhookModal').classList.remove('active');
this.currentWebhook = null;
}
saveWebhook() {
const name = document.getElementById('webhookName').value.trim();
const url = document.getElementById('webhookUrl').value.trim();
if (!name || !url) {
this.showAlert('Please fill in all fields', 'error');
return;
}
if (!this.isValidWebhookUrl(url)) {
this.showAlert('Please enter a valid Discord webhook URL', 'error');
return;
}
if (this.currentWebhook) {
// Update existing webhook
this.currentWebhook.name = name;
this.currentWebhook.url = url;
} else {
// Add new webhook
const webhook = {
id: Date.now().toString(),
name,
url,
createdAt: new Date().toISOString()
};
this.webhooks.push(webhook);
}
this.saveToStorage();
this.renderWebhooks();
this.hideWebhookModal();
this.showAlert('Webhook saved successfully!', 'success');
}
isValidWebhookUrl(url) {
return url.startsWith('https://discord.com/api/webhooks/') ||
url.startsWith('https://discordapp.com/api/webhooks/');
}
deleteWebhook(id) {
if (confirm('Are you sure you want to delete this webhook?')) {
this.webhooks = this.webhooks.filter(wh => wh.id !== id);
this.saveToStorage();
this.renderWebhooks();
this.showAlert('Webhook deleted', 'info');
}
}
selectWebhook(webhook) {
// Remove active class from all webhooks
document.querySelectorAll('.webhook-item').forEach(item => {
item.classList.remove('active');
});
// Add active class to selected webhook
const element = document.querySelector(`[data-webhook-id="${webhook.id}"]`);
if (element) {
element.classList.add('active');
}
this.currentWebhook = webhook;
this.showAlert(`Selected webhook: ${webhook.name}`, 'info');
}
renderWebhooks() {
const container = document.getElementById('webhookList');
if (this.webhooks.length === 0) {
container.innerHTML = `
<div class="empty-state">
<i class="fas fa-plus-circle"></i>
<p>No webhooks added yet</p>
<p class="small">Click "Add Webhook" to get started</p>
</div>
`;
return;
}
container.innerHTML = this.webhooks.map(webhook => `
<div class="webhook-item" data-webhook-id="${webhook.id}">
<div class="webhook-name">${this.escapeHtml(webhook.name)}</div>
<div class="webhook-url">${this.escapeHtml(webhook.url)}</div>
<div class="webhook-actions">
<button class="edit-btn" onclick="app.editWebhook('${webhook.id}')">
<i class="fas fa-edit"></i>
</button>
<button class="delete-btn" onclick="app.deleteWebhook('${webhook.id}')">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
`).join('');
// Add click event to select webhook
container.querySelectorAll('.webhook-item').forEach(item => {
item.addEventListener('click', (e) => {
if (!e.target.closest('.webhook-actions')) {
const id = item.dataset.webhookId;
const webhook = this.webhooks.find(wh => wh.id === id);
if (webhook) this.selectWebhook(webhook);
}
});
});
}
editWebhook(id) {
const webhook = this.webhooks.find(wh => wh.id === id);
if (webhook) {
this.showWebhookModal(webhook);
}
}
// Embed management
showEmbedModal(embedIndex = null) {
const modal = document.getElementById('embedModal');
const titleInput = document.getElementById('embedTitle');
const descInput = document.getElementById('embedDescription');
const colorInput = document.getElementById('embedColor');
const footerInput = document.getElementById('embedFooter');
if (embedIndex !== null && this.embeds[embedIndex]) {
const embed = this.embeds[embedIndex];
titleInput.value = embed.title || '';
descInput.value = embed.description || '';
colorInput.value = embed.color || '#5865F2';
footerInput.value = embed.footer || '';
this.currentEmbedIndex = embedIndex;
} else {
titleInput.value = '';
descInput.value = '';
colorInput.value = '#5865F2';
footerInput.value = '';
this.currentEmbedIndex = null;
}
modal.classList.add('active');
titleInput.focus();
}
hideEmbedModal() {
document.getElementById('embedModal').classList.remove('active');
this.currentEmbedIndex = null;
}
saveEmbed() {
const title = document.getElementById('embedTitle').value.trim();
const description = document.getElementById('embedDescription').value.trim();
const color = document.getElementById('embedColor').value;
const footer = document.getElementById('embedFooter').value.trim();
const embed = {
title: title || null,
description: description || null,
color,
footer: footer || null,
timestamp: new Date().toISOString()
};
if (this.currentEmbedIndex !== null) {
// Update existing embed
this.embeds[this.currentEmbedIndex] = embed;
} else {
// Add new embed
this.embeds.push(embed);
}
this.renderEmbeds();
this.hideEmbedModal();
this.updatePreview();
this.showAlert('Embed saved successfully!', 'success');
}
deleteEmbed(index) {
this.embeds.splice(index, 1);
this.renderEmbeds();
this.updatePreview();
this.showAlert('Embed deleted', 'info');
}
clearEmbeds() {
if (this.embeds.length > 0 && confirm('Clear all embeds?')) {
this.embeds = [];
this.renderEmbeds();
this.updatePreview();
this.showAlert('All embeds cleared', 'info');
}
}
renderEmbeds() {
const container = document.getElementById('embedList');
if (this.embeds.length === 0) {
container.innerHTML = '<div class="empty-state"><i class="fas fa-layer-group"></i><p>No embeds added</p></div>';
return;
}
container.innerHTML = this.embeds.map((embed, index) => `
<div class="embed-item" style="border-left-color: ${embed.color}">
<div class="embed-item-header">
<div style="display: flex; align-items: center;">
<div class="embed-color" style="background-color: ${embed.color}"></div>
<div class="embed-title">${embed.title || 'Untitled Embed'}</div>
</div>
<div class="embed-actions">
<button class="edit-btn" onclick="app.showEmbedModal(${index})">
<i class="fas fa-edit"></i>
</button>
<button class="delete-btn" onclick="app.deleteEmbed(${index})">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
${embed.description ? `<div class="embed-description">${this.escapeHtml(embed.description.substring(0, 100))}${embed.description.length > 100 ? '...' : ''}</div>` : ''}
${embed.footer ? `<div class="embed-footer">${this.escapeHtml(embed.footer)}</div>` : ''}
</div>
`).join('');
}
// Message sending
async sendMessage() {
if (!this.currentWebhook) {
this.showAlert('Please select a webhook first', 'error');
return;
}
const username = document.getElementById('username').value.trim();
const avatarUrl = document.getElementById('avatarUrl').value.trim();
const content = document.getElementById('content').value.trim();
if (!content && this.embeds.length === 0) {
this.showAlert('Please enter message content or add an embed', 'error');
return;
}
const payload = {
username: username || undefined,
avatar_url: avatarUrl || undefined,
content: content || undefined,
embeds: this.embeds.length > 0 ? this.embeds.map(embed => ({
title: embed.title,
description: embed.description,
color: parseInt(embed.color.replace('#', ''), 16),
footer: embed.footer ? { text: embed.footer } : undefined,
timestamp: embed.timestamp
})) : undefined
};
// Remove undefined values
Object.keys(payload).forEach(key => {
if (payload[key] === undefined) {
delete payload[key];
}
});
if (payload.embeds) {
payload.embeds.forEach(embed => {
Object.keys(embed).forEach(key => {
if (embed[key] === undefined) {
delete embed[key];
}
});
});
}
const sendBtn = document.getElementById('sendBtn');
const originalText = sendBtn.innerHTML;
sendBtn.innerHTML = '<span class="loading"></span> Sending...';
sendBtn.disabled = true;
try {
const response = await fetch(this.currentWebhook.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (response.ok) {
this.showAlert('Message sent successfully!', 'success');
// Add to recent messages
this.addToRecentMessages(payload);
} else {
const errorText = await response.text();
throw new Error(`HTTP ${response.status}: ${errorText}`);
}
} catch (error) {
console.error('Error sending message:', error);
this.showAlert(`Failed to send message: ${error.message}`, 'error');
} finally {
sendBtn.innerHTML = originalText;
sendBtn.disabled = false;
}
}
addToRecentMessages(payload) {
const message = {
id: Date.now().toString(),
username: payload.username || 'Webhook',
content: payload.content || '(Embed only)',
embeds: payload.embeds || [],
sentAt: new Date().toISOString()
};
this.savedMessages.unshift(message);
if (this.savedMessages.length > 10) {
this.savedMessages = this.savedMessages.slice(0, 10);
}
this.saveToStorage();
this.renderSavedMessages();
}
// Message management
saveCurrentMessage() {
const username = document.getElementById('username').value.trim();
const avatarUrl = document.getElementById('avatarUrl').value.trim();
const content = document.getElementById('content').value.trim();
if (!content && this.embeds.length === 0) {
this.showAlert('Please enter message content or add an embed', 'error');
return;
}
const name = prompt('Enter a name for this message:');
if (!name) return;
const message = {
id: Date.now().toString(),
name,
username: username || undefined,
avatarUrl: avatarUrl || undefined,
content: content || undefined,
embeds: [...this.embeds],
savedAt: new Date().toISOString()
};
this.savedMessages.unshift(message);
this.saveToStorage();
this.renderSavedMessages();
this.showAlert('Message saved successfully!', 'success');
}
loadMessage(message) {
document.getElementById('username').value = message.username || '';
document.getElementById('avatarUrl').value = message.avatarUrl || '';
document.getElementById('content').value = message.content || '';
this.embeds = message.embeds ? [...message.embeds] : [];
this.renderEmbeds();
this.updatePreview();
this.showAlert(`Loaded message: ${message.name}`, 'info');
}
deleteMessage(id) {
if (confirm('Are you sure you want to delete this saved message?')) {
this.savedMessages = this.savedMessages.filter(msg => msg.id !== id);
this.saveToStorage();
this.renderSavedMessages();
this.showAlert('Message deleted', 'info');
}
}
renderSavedMessages() {
const container = document.getElementById('savedMessages');
if (this.savedMessages.length === 0) {
container.innerHTML = `
<div class="empty-state">
<i class="fas fa-comment-alt"></i>
<p>No saved messages</p>
</div>
`;
return;
}
container.innerHTML = this.savedMessages.map(message => `
<div class="message-item" data-message-id="${message.id}">
<div class="webhook-name">${this.escapeHtml(message.name)}</div>
<div class="webhook-url">${message.content ? this.escapeHtml(message.content.substring(0, 50)) + (message.content.length > 50 ? '...' : '') : '(Embed only)'}</div>
<div class="webhook-actions">
<button class="edit-btn" onclick="app.loadMessageFromSaved('${message.id}')">
<i class="fas fa-upload"></i>
</button>
<button class="delete-btn" onclick="app.deleteMessage('${message.id}')">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
`).join('');
}
loadMessageFromSaved(id) {
const message = this.savedMessages.find(msg => msg.id === id);
if (message) {
this.loadMessage(message);
}
}
clearEditor() {
if (confirm('Clear all message content?')) {
document.getElementById('username').value = '';
document.getElementById('avatarUrl').value = '';
document.getElementById('content').value = '';
this.embeds = [];
this.renderEmbeds();
this.updatePreview();
this.showAlert('Editor cleared', 'info');
}
}
// Preview
updatePreview() {
const container = document.getElementById('previewContainer');
const username = document.getElementById('username').value.trim();
const avatarUrl = document.getElementById('avatarUrl').value.trim();
const content = document.getElementById('content').value.trim();
if (!username && !content && this.embeds.length === 0) {
container.innerHTML = `
<div class="preview-placeholder">
<i class="fas fa-comment-slash"></i>
<p>Message preview will appear here</p>
<p class="small">Edit the message to see a preview</p>
</div>
`;
return;
}
let previewHtml = `
<div class="preview-message">
<div class="preview-header">
<div class="preview-avatar" style="background: ${avatarUrl ? `url('${this.escapeHtml(avatarUrl)}') center/cover` : '#7289da'}"></div>
<div class="preview-username">${this.escapeHtml(username || 'Webhook')}</div>
</div>
`;
if (content) {
previewHtml += `
<div class="preview-content">${this.escapeHtml(content).replace(/\n/g, '<br>')}</div>
`;
}
if (this.embeds.length > 0) {
this.embeds.forEach(embed => {
previewHtml += `
<div class="preview-embed" style="border-left-color: ${embed.color}">
${embed.title ? `<div class="embed-preview-title">${this.escapeHtml(embed.title)}</div>` : ''}
${embed.description ? `<div class="embed-preview-description">${this.escapeHtml(embed.description).replace(/\n/g, '<br>')}</div>` : ''}
${embed.footer ? `<div class="embed-preview-footer">${this.escapeHtml(embed.footer)}</div>` : ''}
</div>
`;
});
}
previewHtml += '</div>';
container.innerHTML = previewHtml;
}
// Utility methods
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
showAlert(message, type = 'info') {
// Remove existing alerts
document.querySelectorAll('.alert').forEach(alert => alert.remove());
const alert = document.createElement('div');
alert.className = `alert alert-${type}`;
alert.innerHTML = `
<i class="fas fa-${type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-circle' : 'info-circle'}"></i>
<span>${this.escapeHtml(message)}</span>
`;
document.querySelector('.container').insertBefore(alert, document.querySelector('footer'));
// Auto-remove after 5 seconds
setTimeout(() => {
if (alert.parentNode) {
alert.remove();
}
}, 5000);
}
// Import/Export
exportConfig() {
const config = {
webhooks: this.webhooks,
savedMessages: this.savedMessages,
version: '1.0',
exportedAt: new Date().toISOString()
};
const dataStr = JSON.stringify(config, null, 2);
const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
const exportFileDefaultName = `webook-config-${new Date().toISOString().split('T')[0]}.json`;
const linkElement = document.createElement('a');
linkElement.setAttribute('href', dataUri);
linkElement.setAttribute('download', exportFileDefaultName);
linkElement.click();
this.showAlert('Configuration exported successfully!', 'success');
}
importConfig() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = (e) => {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (event) => {
try {
const config = JSON.parse(event.target.result);
if (!config.webhooks || !config.savedMessages) {
throw new Error('Invalid configuration file');
}
if (confirm('This will replace your current webhooks and saved messages. Continue?')) {
this.webhooks = config.webhooks;
this.savedMessages = config.savedMessages;
this.saveToStorage();
this.renderWebhooks();
this.renderSavedMessages();
this.showAlert('Configuration imported successfully!', 'success');
}
} catch (error) {
this.showAlert(`Failed to import configuration: ${error.message}`, 'error');
}
};
reader.readAsText(file);
};
input.click();
}
showHelp() {
const helpMessage = `
<h3>Webook Help</h3>
<p><strong>Getting Started:</strong></p>
<ol>
<li>Click "Add Webhook" to add your Discord webhook URL</li>
<li>Select a webhook from the list to use it</li>
<li>Compose your message in the editor</li>
<li>Use the embed builder for rich embeds</li>
<li>Click "Send Message" to send</li>
</ol>
<p><strong>Advanced Features:</strong></p>
<ul>
<li><strong>Multiple Webhook Selection:</strong> Check multiple webhooks to send to all at once</li>
<li><strong>Message Looping:</strong> Send messages repeatedly with configurable delay</li>
<li><strong>Loop Count:</strong> Set how many times to send the message</li>
<li><strong>Delay Control:</strong> Set delay between sends in milliseconds</li>
<li><strong>Select All/Deselect All:</strong> Quickly select or deselect all webhooks</li>
</ul>
<p><strong>Note:</strong> All data is stored locally in your browser.</p>
`;
alert(helpMessage.replace(/<[^>]*>/g, ''));
}
openGitHub() {
window.open('https://github.com/VERAS1508/DiscordWebhookSender', '_blank');
}
showWelcomeModal() {
const modal = document.createElement('div');
modal.className = 'modal active';
modal.innerHTML = `
<div class="modal-content" style="max-width: 600px;">
<h2><i class="fas fa-robot"></i> Welcome to Webook!</h2>
<div style="margin: 20px 0;">
<p><strong>Webook is a powerful Discord webhook interface with these key features:</strong></p>
<ul style="margin: 15px 0; padding-left: 20px;">
<li>📝 <strong>Message Editor</strong> - Compose messages with custom username and avatar</li>
<li>🎨 <strong>Rich Embeds</strong> - Create beautiful Discord embeds with colors and footers</li>
<li>🔄 <strong>Message Looping</strong> - Send messages repeatedly with configurable delays</li>
<li>📊 <strong>Multiple Webhooks</strong> - Send to multiple Discord channels simultaneously</li>
<li>💾 <strong>Local Storage</strong> - All data stays on your computer</li>
<li>⏰ <strong>Scheduling</strong> - Schedule messages for future delivery</li>
</ul>
<div style="background: rgba(114, 137, 218, 0.1); padding: 15px; border-radius: 8px; margin: 15px 0;">
<h3 style="margin-top: 0; color: #7289da;">Quick Start Guide</h3>
<ol style="margin: 10px 0; padding-left: 20px;">
<li>Click <strong>"Add Webhook"</strong> to add your Discord webhook URL</li>
<li>Select a webhook from the sidebar</li>
<li>Compose your message in the editor</li>
<li>Use <strong>"Preview"</strong> to see how it will look</li>
<li>Click <strong>"Send Message"</strong> to send to Discord</li>
</ol>
</div>
<div style="font-size: 0.9rem; color: #888; margin-top: 20px;">
<p><strong>💡 Tip:</strong> All your data is stored locally in your browser. Use the <strong>"Export Config"</strong> button to backup your settings.</p>
<p><strong>🔒 Privacy:</strong> Webook only sends data to Discord - no third-party servers or tracking.</p>
</div>
</div>
<div class="modal-buttons">
<button class="btn btn-primary" id="getStartedBtn">Get Started</button>
<button class="btn btn-secondary" id="viewTutorialBtn">View Tutorial</button>
</div>
</div>
`;
document.body.appendChild(modal);
// Add event listeners
modal.querySelector('#getStartedBtn').addEventListener('click', () => {
document.body.removeChild(modal);
// Auto-open webhook modal for first-time users
setTimeout(() => {
app.showWebhookModal();
}, 300);
});
modal.querySelector('#viewTutorialBtn').addEventListener('click', () => {
document.body.removeChild(modal);
app.showHelp();
});
// Close on outside click
modal.addEventListener('click', (e) => {
if (e.target === modal) {
document.body.removeChild(modal);
}
});
}
// Multiple webhook selection
renderWebhookCheckboxes() {
const container = document.getElementById('webhookTargets');
if (this.webhooks.length === 0) {
container.innerHTML = `
<div class="empty-state small">
<i class="fas fa-link"></i>
<p>No webhooks added yet</p>
</div>
`;
return;
}
container.innerHTML = this.webhooks.map(webhook => `
<div class="checkbox-item">
<input type="checkbox" id="wh-${webhook.id}" value="${webhook.id}">
<label for="wh-${webhook.id}">
<div>${this.escapeHtml(webhook.name)}</div>
<div class="checkbox-url">${this.escapeHtml(webhook.url)}</div>
</label>
</div>
`).join('');
}
updateWebhookCheckboxes() {
this.renderWebhookCheckboxes();
}
getSelectedWebhooks() {
const selected = [];
this.webhooks.forEach(webhook => {
const checkbox = document.getElementById(`wh-${webhook.id}`);
if (checkbox && checkbox.checked) {
selected.push(webhook);
}
});
return selected;
}
selectAllWebhooks() {
this.webhooks.forEach(webhook => {
const checkbox = document.getElementById(`wh-${webhook.id}`);
if (checkbox) {
checkbox.checked = true;
}
});
this.showAlert('All webhooks selected', 'info');
}
deselectAllWebhooks() {
this.webhooks.forEach(webhook => {
const checkbox = document.getElementById(`wh-${webhook.id}`);
if (checkbox) {
checkbox.checked = false;
}
});
this.showAlert('All webhooks deselected', 'info');
}
// Message looping functionality - Enhanced to support message pool and random identity
async startLoop() {
const loopCount = parseInt(document.getElementById('loopCount').value);
const delayMs = parseInt(document.getElementById('delayMs').value);
const useRandomDelay = document.getElementById('randomDelay').checked;
if (isNaN(loopCount) || loopCount < 1 || loopCount > 100) {
this.showAlert('Please enter a valid loop count (1-100)', 'error');
return;
}
if (isNaN(delayMs) || delayMs < 0 || delayMs > 60000) {
this.showAlert('Please enter a valid delay (0-60000 ms)', 'error');
return;
}
const selectedWebhooks = this.getSelectedWebhooks();
if (selectedWebhooks.length === 0) {
this.showAlert('Please select at least one webhook', 'error');
return;
}
// Check if we should use message pool
const useMessagePool = document.getElementById('useMessagePool').checked;
const useRandomIdentity = document.getElementById('useRandomIdentity').checked;
// Validate that we have something to send
if (!useMessagePool) {
const username = document.getElementById('username').value.trim();
const avatarUrl = document.getElementById('avatarUrl').value.trim();
const content = document.getElementById('content').value.trim();
if (!content && this.embeds.length === 0) {
this.showAlert('Please enter message content or add an embed', 'error');
return;
}
} else {
// Check message pool
if (this.messagePool.length === 0) {
this.showAlert('Message pool is empty! Add messages to pool first.', 'error');
return;
}
}
// Start loop
this.isLooping = true;
this.loopIteration = 0;
this.totalLoops = loopCount;
// Update UI
document.getElementById('loopSendBtn').disabled = true;
document.getElementById('stopLoopBtn').disabled = false;
document.getElementById('sendBtn').disabled = true;
// Show loop status
this.showLoopStatus();
// Loop function
const loopFunction = async () => {
if (!this.isLooping || this.loopIteration >= this.totalLoops) {
this.stopLoop();
return;
}
this.loopIteration++;
this.updateLoopStatus();
// Get message for this iteration
let message;
if (useMessagePool) {
message = this.getNextMessageFromPool();
if (!message) {
this.showAlert(`Loop ${this.loopIteration}/${this.totalLoops}: No message available from pool`, 'error');
this.scheduleNextLoop(loopFunction, delayMs, useRandomDelay);
return;
}
} else {
const username = document.getElementById('username').value.trim();
const avatarUrl = document.getElementById('avatarUrl').value.trim();
const content = document.getElementById('content').value.trim();
message = {
username: username || undefined,
avatarUrl: avatarUrl || undefined,
content: content || undefined,
embeds: [...this.embeds]
};
}
// Get random identity if enabled
let randomIdentity = null;
if (useRandomIdentity) {
randomIdentity = this.getRandomIdentity();
}
// Process variables in content
const processedContent = message.content ? this.processVariables(message.content, randomIdentity) : undefined;
// Use random identity if available
const finalUsername = randomIdentity?.username || message.username;
const finalAvatarUrl = randomIdentity?.avatarUrl || message.avatarUrl;
const payload = {
username: finalUsername || undefined,
avatar_url: finalAvatarUrl || undefined,
content: processedContent || undefined,
embeds: message.embeds && message.embeds.length > 0 ? message.embeds.map(embed => ({
title: embed.title ? this.processVariables(embed.title, randomIdentity) : undefined,
description: embed.description ? this.processVariables(embed.description, randomIdentity) : undefined,
color: parseInt(embed.color?.replace('#', '') || '5865F2', 16),
footer: embed.footer ? { text: this.processVariables(embed.footer, randomIdentity) } : undefined,
timestamp: embed.timestamp
})) : undefined
};
// Remove undefined values
Object.keys(payload).forEach(key => {
if (payload[key] === undefined) {
delete payload[key];
}
});
if (payload.embeds) {
payload.embeds.forEach(embed => {
Object.keys(embed).forEach(key => {
if (embed[key] === undefined) {
delete embed[key];
}
});
});
}
// Final check: payload must have content or embeds
if (!payload.content && (!payload.embeds || payload.embeds.length === 0)) {
this.showAlert(`Loop ${this.loopIteration}/${this.totalLoops}: Message has no content or embeds`, 'error');
this.scheduleNextLoop(loopFunction, delayMs, useRandomDelay);
return;
}
// Send to all selected webhooks
const promises = selectedWebhooks.map(async (webhook) => {