-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
160 lines (138 loc) · 4.63 KB
/
script.js
File metadata and controls
160 lines (138 loc) · 4.63 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
document.addEventListener('DOMContentLoaded', () => {
console.log('CS Practical Questions App Initialized');
// Apply saved theme on page load
const savedTheme = localStorage.getItem('theme') || 'light';
applyTheme(savedTheme);
// Update toggle button icon if it exists
updateToggleButton(savedTheme);
});
// Apply theme to the document
function applyTheme(theme) {
if (theme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
} else {
document.documentElement.removeAttribute('data-theme');
}
}
// Update the toggle button icon
function updateToggleButton(theme) {
const toggleBtn = document.querySelector('.theme-toggle');
if (toggleBtn) {
toggleBtn.textContent = theme === 'dark' ? '☀️' : '🌙';
}
}
// Toggle between light and dark theme
function toggleTheme() {
const currentTheme = localStorage.getItem('theme') || 'light';
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', newTheme);
applyTheme(newTheme);
updateToggleButton(newTheme);
}
// Report Problem Modal Functions
function openReportModal() {
const modal = document.getElementById('reportModal');
if (modal) {
modal.classList.add('active');
}
}
function closeReportModal() {
const modal = document.getElementById('reportModal');
if (modal) {
modal.classList.remove('active');
// Reset form
document.getElementById('reportForm').reset();
}
}
// Close modal when clicking outside
document.addEventListener('click', (e) => {
const modal = document.getElementById('reportModal');
if (modal && e.target === modal) {
closeReportModal();
}
});
// Close modal with Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeReportModal();
}
});
// Submit report to Discord webhook
async function submitReport(event) {
event.preventDefault();
const subject = document.getElementById('reportSubject').value.trim();
const message = document.getElementById('reportMessage').value.trim();
const imageInput = document.getElementById('reportImage');
const submitBtn = document.getElementById('submitBtn');
if (!subject || !message) {
alert('Please fill in all fields.');
return;
}
// Check file size (max 8MB)
const imageFile = imageInput.files[0];
if (imageFile && imageFile.size > 8 * 1024 * 1024) {
alert('Image file is too large. Maximum size is 8MB.');
return;
}
// Disable button during submission
submitBtn.disabled = true;
submitBtn.textContent = 'Sending...';
const webhookUrl = 'https://discord.com/api/webhooks/1469972554344300608/A-XEXdQLFH9yhS6vIskrV9Fc-7dSICBMkBaEoSdeaJ_RDhBAjAhryMUxRLMnhN4SR3yU';
const payload = {
embeds: [{
title: '🐛 Problem Report',
color: 0xff6b6b,
fields: [
{
name: 'Subject',
value: subject,
inline: false
},
{
name: 'Message',
value: message,
inline: false
}
],
timestamp: new Date().toISOString()
}]
};
// If there's an image, add it to the embed
if (imageFile) {
payload.embeds[0].image = { url: 'attachment://image.' + imageFile.name.split('.').pop() };
}
try {
let response;
if (imageFile) {
// Use FormData for file upload
const formData = new FormData();
formData.append('payload_json', JSON.stringify(payload));
formData.append('file', imageFile, 'image.' + imageFile.name.split('.').pop());
response = await fetch(webhookUrl, {
method: 'POST',
body: formData
});
} else {
// No image, just send JSON
response = await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
}
if (response.ok) {
alert('Thank you! Your report has been submitted.');
closeReportModal();
} else {
throw new Error('Failed to send report');
}
} catch (error) {
console.error('Error submitting report:', error);
alert('Failed to submit report. Please try again later.');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Submit';
}
}