-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
201 lines (168 loc) · 5.73 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question Code Generator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 900px;
margin: 20px auto;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.header {
padding: 20px;
background-color: #007bff;
color: #fff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
padding: 20px;
}
h2 {
margin-top: 0;
text-align: center;
font-size: x-large;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
input, select {
width: calc(100% - 12px);
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
width: 100%;
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;
}
#generatedCodeTextTextarea {
width: 100%;
height: 300px;
resize: none;
padding: 5px;
border: 1px solid #ccc;
border-radius: 3px;
}
#copyCodeButton {
background-color: #28a745;
color: #fff;
}
#minifyCodeButton {
background-color: #6c757d;
color: #fff;
}
@media (max-width: 767px) {
.content {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Question Code Generator < / ></h2>
</div>
<div class="content">
<div>
<label for="question">Question:</label>
<input type="text" id="question" placeholder="Enter your question">
<label for="option1">Option 1:</label>
<input type="text" id="option1" placeholder="Enter option 1">
<label for="option2">Option 2:</label>
<input type="text" id="option2" placeholder="Enter option 2">
<label for="option3">Option 3:</label>
<input type="text" id="option3" placeholder="Enter option 3">
<label for="option4">Option 4:</label>
<input type="text" id="option4" placeholder="Enter option 4">
<label for="correctOption">Correct Option:</label>
<select id="correctOption">
<option value="a">Option 1</option>
<option value="b">Option 2</option>
<option value="c">Option 3</option>
<option value="d">Option 4</option>
</select>
<button onclick="generateCode()">Generate Code</button>
</div>
<div>
<h2>Generated Code</h2>
<textarea id="generatedCodeTextTextarea" readonly></textarea>
<button id="copyCodeButton" onclick="copyCode()" disabled>Copy Code</button>
<button id="minifyCodeButton" onclick="minifyCode()">Minify Code</button>
</div>
</div>
</div>
<script>
let questionCounter = 0;
function generateCode() {
const question = document.getElementById("question").value.trim();
const option1 = document.getElementById("option1").value.trim();
const option2 = document.getElementById("option2").value.trim();
const option3 = document.getElementById("option3").value.trim();
const option4 = document.getElementById("option4").value.trim();
const correctOption = document.getElementById("correctOption").value;
if (!question || !option1 || !option2 || !option3 || !option4) {
alert("Please fill in all fields.");
return;
}
questionCounter++;
const code = `<div class="generatedCodeItem">
<div class="wrapper">
<div class="question">
<p>${questionCounter}. ${question}</p>
</div>
<div class="options-group">
<div class="options a${correctOption === 'a' ? ' correct' : ''}"><p>1. ${option1}</p></div>
<div class="options b${correctOption === 'b' ? ' correct' : ''}"><p>2. ${option2}</p></div>
<div class="options c${correctOption === 'c' ? ' correct' : ''}"><p>3. ${option3}</p></div>
<div class="options d${correctOption === 'd' ? ' correct' : ''}"><p>4. ${option4}</p></div>
</div>
</div>
</div>`;
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.value += code + "\n";
document.getElementById("copyCodeButton").disabled = false;
}
function copyCode() {
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.select();
document.execCommand("copy");
alert("Code copied to clipboard!");
}
function minifyCode() {
const generatedCodeTextTextarea = document.getElementById("generatedCodeTextTextarea");
generatedCodeTextTextarea.value = minifyHTML(generatedCodeTextTextarea.value);
}
function minifyHTML(html) {
return html.replace(/<!--[\s\S]*?-->/g, "").replace(/[ \t]+/g, " ").replace(/>\s+</g, "><").trim();
}
</script>
</body>
</html>