-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (247 loc) · 8.61 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Question Code Generator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 95%;
margin: 20px auto;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
display: flex;
flex-wrap: wrap;
gap: 20px;
overflow: auto;
}
.header {
width: 100%;
padding: 5px;
background-color: #007bff;
color: #fff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
text-align: center;
box-sizing: border-box;
}
.content-left {
flex: 1;
padding: 20px;
margin: 10px;
background-color: #aa84845b;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.content-right {
flex: 1;
padding: 20px;
margin: 10px;
background-color: #aa84845b;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(122, 89, 89, 0.1);
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
textarea {
width: 90%;
height: 300px;
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
resize: none;
}
button {
width: 92%;
padding: 10px;
margin-top: 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.error-message {
color: red;
margin-top: 5px;
}
#generatedCodeTextTextarea {
width: 90%;
height: 300px;
resize: none;
padding: 5px;
border: 1px solid #ccc;
border-radius: 3px;
}
@media (max-width: 767px) {
.container {
flex-direction: column;
}
.content-left,
.content-right {
width: 85%;
margin-bottom: 20px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Question Code Generator < / ></h1>
</div>
<div class="content-left">
<label for="questionTextarea">Paste your questions, options, and correct answers:</label>
<textarea id="questionTextarea" placeholder="Paste your questions, options, and correct answers here in following format
1. What is your favourite food?
Pizza
Burgers
Pasta
Salad
4"></textarea>
<button onclick="generateCode()">Generate HTML Code</button>
<div id="errorMessage" class="error-message"></div>
</div>
<div class="content-right">
<label for="generatedText">Generated Text</label>
<textarea id="generatedCodeTextTextarea" readonly></textarea>
<div>
<button id="copyCodeButton" onclick="copyCode()" disabled>Copy Code</button>
<button id="beautifyCodeButton" onclick="beautifyCode()">Beautify Code</button>
<button id="minifyCodeButton" onclick="minifyCode()">Minify Code</button>
</div>
</div>
</div>
<script>
function generateCode() {
const questionTextarea = document.getElementById("questionTextarea");
const questions = questionTextarea.value.trim().split(/\d+\./).slice(1);
if (!validateFields(questions)) {
return;
}
let code = "";
let adCount = 0;
for (let i = 0; i < questions.length; i++) {
const lines = questions[i].trim().split("\n");
const question = lines[0].trim();
const options = lines.slice(1, 5).map((option, index) => {
const alphabetLetter = String.fromCharCode(97 + index); // Get alphabet letter (a, b, c, d)
return `<div class="options ${alphabetLetter}">${alphabetLetter}. ${option.trim()}</div>`;
}).join("");
const correctOptionIndex = parseInt(lines[5].trim()) - 1;
const correctOptionLetter = String.fromCharCode(97 + correctOptionIndex); // Get alphabet letter for correct option
code += `<div class="wrapper">
<div class="question"><p>${i + 1}. ${question}</p></div>
<div class="options-group">
${options.replace(`<div class="options ${correctOptionLetter}">`, `<div class="options ${correctOptionLetter} correct">`)}
</div>
</div>`;
if ((i + 1) % 5 === 0 && i !== 0 && adCount < Math.floor(questions.length / 5)) {
code += `<div class="ads-wrapper"><div class="ads"></div></div>`;
adCount++;
}
}
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.value = code;
document.getElementById("copyCodeButton").disabled = false;
}
function generateCode() {
const questionTextarea = document.getElementById("questionTextarea");
const questions = questionTextarea.value.trim().split(/\d+\./).slice(1);
if (!validateFields(questions)) {
return;
}
let code = "";
let adCount = 0;
for (let i = 0; i < questions.length; i++) {
const lines = questions[i].trim().split("\n");
const question = lines[0].trim();
const options = lines.slice(1, 5).map((option, index) => {
const alphabetLetter = String.fromCharCode(97 + index);
return `<div class="options ${alphabetLetter}">${alphabetLetter}. ${option.trim()}</div>`;
}).join("");
let correctOptionLetter;
const correctOption = lines[5].trim();
if (isNaN(correctOption)) {
correctOptionLetter = correctOption.toLowerCase();
} else {
const correctOptionIndex = parseInt(correctOption) - 1;
correctOptionLetter = String.fromCharCode(97 + correctOptionIndex);
}
code += `<div class="wrapper">
<div class="question"><p>${i + 1}. ${question}</p></div>
<div class="options-group">
${options.replace(`<div class="options ${correctOptionLetter}">`, `<div class="options ${correctOptionLetter} correct">`)}
</div>
</div>`;
if ((i + 1) % 5 === 0 && i !== 0 && adCount < Math.floor(questions.length / 5)) {
code += `<div class="ads-wrapper"><div class="ads"></div></div>`;
adCount++;
}
}
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.value = code;
document.getElementById("copyCodeButton").disabled = false;
}
function copyCode() {
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.select();
document.execCommand("copy");
alert("Code copied to clipboard!");
}
function beautifyCode() {
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
let code = generatedCodeTextTextarea.value;
const isMinified = code.includes("<div") && code.includes("</div>");
if (isMinified) {
code = code.replace(/><(?=[^\s/])/g, ">\n<");
}
generatedCodeTextTextarea.value = code;
}
function minifyCode() {
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
let code = generatedCodeTextTextarea.value;
code = code.replace(/\s+/g, "");
generatedCodeTextTextarea.value = code;
}
function validateFields(questions) {
const errorMessage = document.getElementById("errorMessage");
errorMessage.textContent = "";
if (questions.length === 0) {
errorMessage.textContent = "Please provide questions and options.";
return false;
}
for (let i = 0; i < questions.length; i++) {
const lines = questions[i].trim().split("\n");
if (lines.length < 6) {
errorMessage.innerHTML = "Please provide all required information for each question and in the following format:<br><br>" +
"1. What is your favorite food?<br>" +
"Pizza<br>" +
"Burgers<br>" +
"Pasta<br>" +
"Salad<br>" +
"4";
return false;
}
}
return true;
}
</script>
</body>
</html>