-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (59 loc) · 2.44 KB
/
Copy pathscript.js
File metadata and controls
63 lines (59 loc) · 2.44 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
document.addEventListener('DOMContentLoaded', () => {
const checkButton = document.getElementById('checkButton');
const sendButton = document.getElementById('sendButton');
const messageGroup = document.getElementById('messageGroup');
const webhookUrlInput = document.getElementById('webhookUrl');
const messageInput = document.getElementById('message');
let sending = false;
checkButton.addEventListener('click', async () => {
const webhookUrl = webhookUrlInput.value.trim();
if (webhookUrl) {
try {
const response = await fetch(webhookUrl, { method: 'GET' });
if (response.ok) {
checkButton.classList.add('valid');
checkButton.textContent = 'Valid!';
messageGroup.classList.remove('hidden');
} else {
checkButton.classList.remove('valid');
checkButton.textContent = 'Invalid!';
alert('Invalid Webhook URL');
}
} catch (error) {
checkButton.classList.remove('valid');
checkButton.textContent = 'Invalid!';
alert('Error: ' + error.message);
}
}
});
sendButton.addEventListener('click', async () => {
if (sending) {
sending = false;
sendButton.textContent = 'Send';
sendButton.classList.remove('stop');
return;
}
const webhookUrl = webhookUrlInput.value.trim();
const message = messageInput.value.trim();
if (webhookUrl && message) {
sending = true;
sendButton.textContent = 'Stop';
sendButton.classList.add('stop');
while (sending) {
try {
await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: message })
});
await new Promise(resolve => setTimeout(resolve, 10));
} catch (error) {
alert('Error: ' + error.message);
sending = false;
sendButton.textContent = 'Send';
sendButton.classList.remove('stop');
}
}
}
});
});