-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditor.html
More file actions
365 lines (314 loc) · 11.8 KB
/
Editor.html
File metadata and controls
365 lines (314 loc) · 11.8 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: column;
}
.editor-container {
width: 95%;
max-width: 1400px;
height: max-content;
background-color: #fff;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
border-radius: 10px;
padding: 30px;
display: flex;
flex-direction: column;
gap: 30px;
position: relative;
}
.editor-section-wrapper {
display: flex;
gap: 20px;
width: 100%;
}
.editor-section {
background: #1e1e1e;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 20px;
color: #ddd;
width: 32%;
height: 400px;
overflow: hidden;
}
.editor-section textarea {
width: 100%;
height: 100%;
background: #222;
color: #fff;
border: 2px solid #333;
border-radius: 8px;
font-family: 'Courier New', monospace;
font-size: 16px;
padding: 10px;
outline: none;
resize: none;
}
.editor-section textarea:focus {
border-color: #00d4ff;
box-shadow: 0 0 10px rgba(0, 212, 255, 0.7);
}
.output-section {
background: #222;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 15px;
color: #fff;
height: 500px;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
.out {
width: 100%;
height: 100%;
}
.button-container {
display: flex;
justify-content: flex-end;
position: absolute;
top:1px;
right: 30px;
}
.run-button,
.stop-button {
background: #00d4ff;
color: white;
border: none;
padding: 12px 24px;
font-size: 18px;
border-radius: 8px;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: background 0.3s ease;
}
.run-button:hover,
.stop-button:hover {
background: #00a3b8;
}
.run-button:focus,
.stop-button:focus {
outline: none;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
#timer {
position: absolute;
top: 3px;
left: 10px;
font-size: 24px;
color: #333;
font-weight: bold;
}
/* Create a scrolling effect using CSS */
.scrolling-text {
white-space: nowrap; /* Prevent text from wrapping */
overflow: hidden; /* Hide anything outside the container */
width: 100%;
box-sizing: border-box;
}
.scrolling-text span {
display: inline-block;
animation: scroll-left 20s linear infinite; /* Adjust speed with the duration */
}
/* Define the scrolling animation */
@keyframes scroll-left {
from {
transform: translateX(100%); /* Start off-screen to the right */
}
to {
transform: translateX(-100%); /* Move to off-screen to the left */
}
}
.logo {
color: black;
font-size: 2rem;
font-weight: bold;
}
.logo span {
color: #00c3ff;
text-shadow:10 0 0 11px #000000;
}
</style>
<script>
// Display a confirmation prompt when the user tries to refresh or leave the page
window.addEventListener('beforeunload', function (event) {
// Standard message for the confirmation dialog
const message = "Are you sure you want to leave? Any unsaved changes will be lost.";
// Display the confirmation dialog
event.returnValue = message; // For most browsers
return message; // For legacy browsers
});
</script>
</head>
<body>
<div class="logo" data-aos="zoom-in" data-aos-duration="1500">
Play with<span> Code</span>
</div>
<div class="scrolling-text" >
<span style="color: red;">1. Do not switch between tab, it may caues to disqualify from the event,
2. Do not refresh the page, it may caues to lose the whole content. </span>
</div>
<div class="editor-container">
<div class="editor-section-wrapper">
<!-- HTML Editor -->
<div class="editor-section">
<h3 style="color: #fff;">HTML</h3>
<textarea id="htmlCode" placeholder="Write your HTML code here" spellcheck="false"></textarea>
</div>
<!-- CSS Editor -->
<div class="editor-section">
<h3 style="color: #fff;">CSS</h3>
<textarea id="cssCode" placeholder="Write your CSS code here" spellcheck="false"></textarea>
</div>
<!-- JavaScript Editor -->
<div class="editor-section">
<h3 style="color: #fff;">JavaScript</h3>
<textarea id="jsCode" placeholder="Write your JavaScript code here" spellcheck="false"></textarea>
</div>
</div>
<!-- Output Section -->
<div class="out">
<div class="output-section">
<iframe id="output"></iframe>
</div>
</div>
<!-- Timer Display -->
<div id="timer">Time remaining: 70m 0s</div>
<!-- Button Container -->
<div class="button-container">
<button class="stop-button" onclick="stopTimer()">Stop Timer</button>
</div>
</div>
<script>
let timerDuration = 70; // Set timer duration to 2 hours (120 minutes)
let timerInterval;
let timeLeft = timerDuration * 60; // Convert minutes to seconds
// Function to start the timer
function startTimer() {
const timerDisplay = document.getElementById('timer');
timerInterval = setInterval(function () {
if (timeLeft <= 0) {
clearInterval(timerInterval);
disableTextareas();
timerDisplay.textContent = "Time's up!";
} else {
// Format the timer to display minutes and seconds
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timerDisplay.textContent = `Time remaining: ${minutes}m ${seconds}s`;
timeLeft--;
}
}, 1000);
}
// Function to stop the timer and disable textareas
function stopTimer() {
clearInterval(timerInterval);
disableTextareas();
const timerDisplay = document.getElementById('timer');
timerDisplay.textContent = `Time remaining: ${minutes}m ${seconds}s`;
}
// Function to disable textareas
function disableTextareas() {
document.getElementById('htmlCode').disabled = true;
document.getElementById('cssCode').disabled = true;
document.getElementById('jsCode').disabled = true;
}
// Function to run the code
function runCode() {
// Get HTML, CSS, and JS from the textareas
const html = document.getElementById('htmlCode').value;
const css = document.getElementById('cssCode').value;
const js = document.getElementById('jsCode').value;
// Create an iframe to display the output
const iframe = document.getElementById('output');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// Write the combined code into the iframe
iframeDoc.open();
iframeDoc.write(`
<html lang="en">
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>${js}<\/script>
</body>
</html>
`);
iframeDoc.close();
}
// Function to handle the visibility change event
function handleVisibilityChange() {
if (document.hidden) {
// Save current content of the textareas to localStorage when the tab is switched
localStorage.setItem('htmlCode', document.getElementById('htmlCode').value);
localStorage.setItem('cssCode', document.getElementById('cssCode').value);
localStorage.setItem('jsCode', document.getElementById('jsCode').value);
} else {
// Clear the content when the user revisits the page but keep the output intact
// localStorage.removeItem('htmlCode');
// localStorage.removeItem('cssCode');
// localStorage.removeItem('jsCode');
document.getElementById('htmlCode').disabled = true;
document.getElementById('cssCode').disabled = true;
document.getElementById('jsCode').disabled = true;
stopTimer()
// document.getElementById('htmlCode').value = '';
// document.getElementById('cssCode').value = '';
// document.getElementById('jsCode').value = '';
}
}
// Start the timer automatically as soon as the page loads
window.onload = function() {
startTimer();
// Handle visibility change
document.addEventListener('visibilitychange', handleVisibilityChange);
// Load the saved code from localStorage when the page loads (without clearing the output)
const savedHtml = localStorage.getItem('htmlCode');
const savedCss = localStorage.getItem('cssCode');
const savedJs = localStorage.getItem('jsCode');
if (savedHtml !== null) document.getElementById('htmlCode').value = savedHtml;
if (savedCss !== null) document.getElementById('cssCode').value = savedCss;
if (savedJs !== null) document.getElementById('jsCode').value = savedJs;
document.getElementById('htmlCode').value = '';
document.getElementById('cssCode').value = '';
document.getElementById('jsCode').value = '';
// Run the saved code
runCode();
};
// Add event listeners to automatically run the code when content changes in any of the editors
document.getElementById('htmlCode').addEventListener('input', runCode);
document.getElementById('cssCode').addEventListener('input', runCode);
document.getElementById('jsCode').addEventListener('input', runCode);
// Disable paste event on the textareas
function preventPaste(event) {
event.preventDefault();
}
// Attach the prevent paste event to all text areas
document.getElementById('htmlCode').addEventListener('paste', preventPaste);
document.getElementById('cssCode').addEventListener('paste', preventPaste);
document.getElementById('jsCode').addEventListener('paste', preventPaste);
</script>
</body>
</html>