-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.js
100 lines (83 loc) · 2.73 KB
/
feedback.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
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
var feedbackButton = document.getElementById('feedback-button')
while (!feedbackButton) {
feedbackButton = document.getElementById('feedback-button')
}
console.log(feedbackButton)
const webhookUrl = "https://discord.com/api/webhooks/1134137918483599411/r_Sq-PsDWvEsRmrB0YjXNPx6bpHNjDCdcZoVr45UBu4do0V7j-6XvhsdH7pi8Ng_LPmD";
var modal = document.createElement('dialog')
modal.className = 'feedbackModal'
var xButton = document.createElement('span')
xButton.className = 'xButtonModal material-symbols-outlined'
xButton.innerText = 'close'
var title = document.createElement('h1')
title.innerText = 'Tool Ideas'
var label1 = document.createElement('label')
var span1 = document.createElement('span')
span1.innerText = 'Idea '
var box1 = document.createElement('input')
box1.type = 'text'
var submit = document.createElement('div')
submit.className = "feedbackSubmitButton"
submit.innerHTML = "Submit"
var br = document.createElement('br')
var feedbackText = document.createElement('span')
feedbackText.id = "feedbackText"
document.body.appendChild(modal)
modal.appendChild(xButton)
modal.appendChild(title)
modal.appendChild(label1)
label1.appendChild(span1)
label1.appendChild(box1)
modal.appendChild(br)
modal.appendChild(feedbackText)
modal.appendChild(submit)
// this code is so messy wtf
feedbackButton.addEventListener('click', function () {
modal.showModal();
})
xButton.addEventListener('click', function () {
modal.close()
})
submit.addEventListener('click', function () {
var input1Text = box1.value;
console.log(input1Text)
if (!input1Text) {
feedbackText.innerText = "Please fill in the box"
} else {
sendMessageToDiscord(input1Text)
}
})
// Function to send the message to the Discord webhook
function sendMessageToDiscord(message) {
const data = {
embeds: [
{
title: "Feedback has been recieved!",
fields: [
{
name: "Idea:",
value: message
}
]
}
]
};
fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((response) => {
if (response.ok) {
feedbackText.innerText = "Thank you for your feedback"
modal.close()
} else {
console.error('Failed to send message to Discord:', response.statusText);
}
})
.catch((error) => {
console.error('Error sending message to Discord:', error);
});
}