-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (23 loc) · 873 Bytes
/
script.js
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
document.getElementById('messageForm').addEventListener('submit', function(event) {
event.preventDefault();
const webhook = document.getElementById('webhook').value;
const message = document.getElementById('message').value;
const xhr = new XMLHttpRequest();
xhr.open('POST', webhook, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
alert('Message sent successfully!');
document.getElementById('message').value = '';
} else {
alert('Message failed to send. Please try again later.');
}
};
xhr.onerror = function () {
alert('An error occurred while sending the message.');
};
const data = JSON.stringify({
content: message
});
xhr.send(data);
});