-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
717 lines (659 loc) · 26.9 KB
/
script.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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const selectFileBtn = document.getElementById('selectFileBtn');
const editorContainer = document.getElementById('editorContainer');
const previewImage = document.getElementById('previewImage');
const originalSizeEl = document.getElementById('originalSize');
const newSizeEl = document.getElementById('newSize');
const fileSizeEl = document.getElementById('fileSize');
const widthInput = document.getElementById('widthInput');
const heightInput = document.getElementById('heightInput');
const maintainAspectRatio = document.getElementById('maintainAspectRatio');
const formatSelect = document.getElementById('formatSelect');
const qualitySlider = document.getElementById('qualitySlider');
const qualityValue = document.getElementById('qualityValue');
const processBtn = document.getElementById('processBtn');
const downloadBtn = document.getElementById('downloadBtn');
const resetBtn = document.getElementById('resetBtn');
const presetButtons = document.querySelectorAll('.preset-buttons button'); // Keep this declaration
const showGuideBtn = document.getElementById('showGuideBtn');
const closeGuideBtn = document.getElementById('closeGuideBtn');
const userGuide = document.getElementById('userGuide');
const rotateLeft = document.getElementById('rotateLeft');
const rotateRight = document.getElementById('rotateRight');
const enableCropUI = document.getElementById('enableCropUI');
const cropPreviewContainer = document.getElementById('cropPreviewContainer');
const cropPreview = document.getElementById('cropPreview');
const flipHorizontalBtn = document.getElementById('flipHorizontal');
const flipVerticalBtn = document.getElementById('flipVertical');
const darkModeToggle = document.getElementById('darkModeToggle');
const tabBtns = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');
let cropper = null;
// Add loading indicator elements
const loadingIndicator = document.createElement('div');
loadingIndicator.className = 'loading';
loadingIndicator.innerHTML = '<div class="loading-spinner"></div>';
document.body.appendChild(loadingIndicator);
// Add error message container
const errorMessage = document.createElement('div');
errorMessage.className = 'error-message';
editorContainer.appendChild(errorMessage);
// Initialize crop-related elements
if (cropPreviewContainer && cropPreview) {
cropPreviewContainer.style.display = 'none';
cropPreview.style.display = 'none';
}
// Variables
let historyIndex = 0;
let originalImage = null;
let processedImage = null;
let originalWidth = 0;
let originalHeight = 0;
let aspectRatio = 0;
let processedBlob = null;
let imageHistory = []; // Store image processing history for undo/redo
let rotationAngle = 0; // Track image rotation in degrees
let flipHorizontal = false; // Track horizontal flip state
let flipVertical = false; // Track vertical flip state
let isCropEnabled = false; // Track crop mode state
// Initialize crop functionality
if (enableCropUI) {
enableCropUI.addEventListener('click', () => {
isCropEnabled = !isCropEnabled;
if (isCropEnabled && previewImage.src) {
if (!cropper) {
cropper = new Cropper(previewImage, {
viewMode: 1,
dragMode: 'move',
autoCropArea: 0.8,
restore: false,
guides: true,
center: true,
highlight: false,
cropBoxMovable: true,
cropBoxResizable: true,
toggleDragModeOnDblclick: false
});
}
enableCropUI.classList.add('active');
} else {
if (cropper) {
cropper.destroy();
cropper = null;
}
enableCropUI.classList.remove('active');
}
redrawPreview();
});
}
// Event Listeners
uploadArea.addEventListener('click', () => fileInput.click());
selectFileBtn.addEventListener('click', (e) => {
e.stopPropagation();
fileInput.click();
});
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.style.backgroundColor = 'rgba(74, 108, 247, 0.2)';
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.style.backgroundColor = 'rgba(74, 108, 247, 0.05)';
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.style.backgroundColor = 'rgba(74, 108, 247, 0.05)';
if (e.dataTransfer.files.length) {
handleFileUpload(e.dataTransfer.files[0]);
}
});
fileInput.addEventListener('change', () => {
if (fileInput.files.length) {
handleFileUpload(fileInput.files[0]);
}
});
widthInput.addEventListener('input', () => {
if (maintainAspectRatio.checked && aspectRatio > 0) {
heightInput.value = Math.round(widthInput.value / aspectRatio);
}
updateNewSize();
redrawPreview();
});
heightInput.addEventListener('input', () => {
if (maintainAspectRatio.checked && aspectRatio > 0) {
widthInput.value = Math.round(heightInput.value * aspectRatio);
}
updateNewSize();
redrawPreview();
});
// Undo/Redo Button Selection start
document.addEventListener("DOMContentLoaded", function () {
const undoBtn = document.getElementById("undoBtn");
const redoBtn = document.getElementById("redoBtn");
const widthInput = document.getElementById("widthInput");
const heightInput = document.getElementById("heightInput");
const processBtn = document.getElementById("processBtn");
const presetButtons = document.querySelectorAll(".preset-buttons button");
const previewImage = document.getElementById("previewImage");
let history = [];
let redoStack = [];
function saveState() {
if (previewImage.src) {
history.push({
imageSrc: previewImage.src,
width: widthInput.value,
height: heightInput.value,
});
redoStack = []; // Clear redo stack after new change
updateUndoRedoButtons();
}
}
function updateUndoRedoButtons() {
undoBtn.disabled = history.length <= 1;
redoBtn.disabled = redoStack.length === 0;
undoBtn.classList.toggle("disabled", history.length <= 1);
redoBtn.classList.toggle("disabled", redoStack.length === 0);
}
undoBtn.addEventListener("click", function () {
if (history.length > 1) {
redoStack.push(history.pop()); // Move last state to redo
const lastState = history[history.length - 1];
previewImage.src = lastState.imageSrc;
widthInput.value = lastState.width;
heightInput.value = lastState.height;
updateUndoRedoButtons();
}
});
redoBtn.addEventListener("click", function () {
if (redoStack.length > 0) {
const nextState = redoStack.pop();
history.push(nextState);
previewImage.src = nextState.imageSrc;
widthInput.value = nextState.width;
heightInput.value = nextState.height;
updateUndoRedoButtons();
}
});
// Save state when image is processed
processBtn.addEventListener("click", function () {
setTimeout(() => {
saveState();
}, 100);
});
// Save state when preset size is clicked
presetButtons.forEach(button => {
button.addEventListener("click", function () {
saveState();
});
});
// Save state when width/height is manually changed
widthInput.addEventListener("input", saveState);
heightInput.addEventListener("input", saveState);
});
// Undo/Redo Button Selection end
qualitySlider.addEventListener('input', () => {
qualityValue.textContent = `${qualitySlider.value}%`;
redrawPreview();
});
// Handle preset button selection
presetButtons.forEach(button => {
button.addEventListener('click', function() {
presetButtons.forEach(btn => btn.classList.remove('selected'));
this.classList.add('selected');
// Get dimensions from the button's data attributes
const presetWidth = parseInt(this.getAttribute('data-width'));
const presetHeight = parseInt(this.getAttribute('data-height'));
// Update input fields
widthInput.value = presetWidth;
heightInput.value = presetHeight;
// Update preview immediately
redrawPreview();
updateNewSize();
});
});
processBtn.addEventListener('click', processImage);
downloadBtn.addEventListener('click', downloadImage);
resetBtn.addEventListener('click', resetEditor);
// Add rotation button event listeners with immediate preview
rotateLeft.addEventListener('click', () => {
rotationAngle = (rotationAngle - 90) % 360;
redrawPreview();
updateNewSize();
});
rotateRight.addEventListener('click', () => {
rotationAngle = (rotationAngle + 90) % 360;
redrawPreview();
updateNewSize();
});
flipHorizontalBtn.addEventListener('click', () => {
flipHorizontal = !flipHorizontal;
redrawPreview();
updateNewSize();
});
flipVerticalBtn.addEventListener('click', () => {
flipVertical = !flipVertical;
redrawPreview();
updateNewSize();
});
// Dark mode toggle
darkModeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', document.body.classList.contains('dark-mode'));
});
// Tab switching for resize options
tabBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class from all buttons
tabBtns.forEach(b => b.classList.remove('active'));
// Add active class to clicked button
btn.classList.add('active');
// Hide all tab contents
tabContents.forEach(content => {
content.style.display = 'none';
});
// Show the selected tab content
const tabId = btn.getAttribute('data-tab');
document.getElementById(`${tabId}-tab`).style.display = 'block';
});
});
// Sync unit selectors
const widthUnit = document.getElementById('widthUnit');
const heightUnit = document.getElementById('heightUnit');
widthUnit.addEventListener('change', function() {
heightUnit.value = this.value;
});
heightUnit.addEventListener('change', function() {
widthUnit.value = this.value;
});
// Guide buttons
showGuideBtn.addEventListener('click', (e) => {
e.preventDefault();
userGuide.style.display = 'block';
});
closeGuideBtn.addEventListener('click', () => {
userGuide.style.display = 'none';
});
// Add keyboard shortcuts
document.addEventListener('keydown', function(e) {
// Ctrl+O to open file
if (e.ctrlKey && e.key === 'o') {
e.preventDefault();
fileInput.click();
}
// Ctrl+S to save/download
if (e.ctrlKey && e.key === 's' && !downloadBtn.disabled) {
e.preventDefault();
downloadImage();
}
// Ctrl+P to process image
if (e.ctrlKey && e.key === 'p' && originalImage) {
e.preventDefault();
processImage();
}
});
// Initialize on load
document.body.classList.toggle('dark-mode', localStorage.getItem('darkMode') === 'true');
// Functions
function handleFileUpload(file) {
if (!file.type.startsWith('image/')) {
showError('Please upload an image file');
return;
}
// Cleanup existing cropper instance
if (cropper) {
cropper.destroy();
cropper = null;
}
isCropEnabled = false;
if (enableCropUI) {
enableCropUI.classList.remove('active');
}
showLoading(true);
const reader = new FileReader();
reader.onload = function(e) {
originalImage = new Image();
originalImage.onload = function() {
originalWidth = originalImage.width;
originalHeight = originalImage.height;
aspectRatio = originalWidth / originalHeight;
// Set initial dimensions
widthInput.value = originalWidth;
heightInput.value = originalHeight;
// Display image and show editor
previewImage.src = e.target.result;
editorContainer.style.display = 'flex';
uploadArea.style.display = 'none';
// Update info
originalSizeEl.textContent = `${originalWidth}×${originalHeight}px`;
updateNewSize();
// Display file size
const fileSizeMB = (file.size / (1024 * 1024)).toFixed(2);
fileSizeEl.textContent = `${fileSizeMB} MB`;
showLoading(false);
};
originalImage.onerror = function() {
showError('Failed to load image. Please try another file.');
showLoading(false);
};
originalImage.src = e.target.result;
};
reader.onerror = function() {
showError('Failed to read file. Please try again.');
showLoading(false);
};
reader.readAsDataURL(file);
}
function processImage() {
if (!originalImage) return;
showLoading(true);
processBtn.disabled = true;
setTimeout(() => {
try {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
let sourceX = 0;
let sourceY = 0;
let sourceWidth = originalImage.width;
let sourceHeight = originalImage.height;
// Handle cropping if active
if (cropper) {
const cropData = cropper.getData();
sourceX = cropData.x;
sourceY = cropData.y;
sourceWidth = cropData.width;
sourceHeight = cropData.height;
}
const newWidth = parseInt(widthInput.value);
const newHeight = parseInt(heightInput.value);
if (isNaN(newWidth) || isNaN(newHeight) || newWidth <= 0 || newHeight <= 0) {
throw new Error('Please enter valid dimensions.');
}
canvas.width = newWidth;
canvas.height = newHeight;
// Apply transformations
ctx.save();
// Adjust canvas dimensions for rotation
if (Math.abs(rotationAngle) === 90 || Math.abs(rotationAngle) === 270) {
[canvas.width, canvas.height] = [canvas.height, canvas.width];
[newWidth, newHeight] = [newHeight, newWidth];
}
// Center and rotate
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.rotate((rotationAngle * Math.PI) / 180);
// Handle flips
if (flipHorizontal || flipVertical) {
ctx.scale(flipHorizontal ? -1 : 1, flipVertical ? -1 : 1);
if (flipHorizontal) {
ctx.translate(-canvas.width, 0);
}
if (flipVertical) {
ctx.translate(0, -canvas.height);
}
}
// Draw the image with all transformations
ctx.drawImage(
originalImage,
sourceX, sourceY,
sourceWidth, sourceHeight,
-newWidth / 2, -newHeight / 2,
newWidth, newHeight
);
ctx.restore();
const format = formatSelect.value;
const quality = parseInt(qualitySlider.value) / 100;
let mimeType;
switch(format) {
case 'jpeg': mimeType = 'image/jpeg'; break;
case 'png': mimeType = 'image/png'; break;
case 'webp': mimeType = 'image/webp'; break;
case 'gif': mimeType = 'image/gif'; break;
default: mimeType = 'image/jpeg';
}
canvas.toBlob(blob => {
processedBlob = blob;
const url = URL.createObjectURL(blob);
// Clear future history if we're not at the end
if (historyIndex < imageHistory.length - 1) {
imageHistory = imageHistory.slice(0, historyIndex + 1);
}
imageHistory.push({
blob: blob,
width: newWidth,
height: newHeight,
format: format,
quality: quality,
rotation: rotationAngle,
flipX: flipHorizontal,
flipY: flipVertical
});
previewImage.src = url;
const fileSizeMB = (blob.size / (1024 * 1024)).toFixed(2);
fileSizeEl.textContent = `${fileSizeMB} MB`;
downloadBtn.disabled = false;
historyIndex = imageHistory.length - 1;
showLoading(false);
}, mimeType, quality);
} catch (error) {
showError(error.message || 'An error occurred during processing.');
showLoading(false);
}
}, 100);
}
function downloadImage() {
if (!processedBlob) return;
showLoading(true);
// Create a canvas to apply the current transformations
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Get current state from the latest history entry
const currentState = imageHistory[historyIndex];
const newWidth = currentState.width;
const newHeight = currentState.height;
// Set canvas dimensions based on rotation from current state
if (Math.abs(currentState.rotation) === 90 || Math.abs(currentState.rotation) === 270) {
canvas.width = newHeight;
canvas.height = newWidth;
} else {
canvas.width = newWidth;
canvas.height = newHeight;
}
// Apply transformations
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.rotate((currentState.rotation * Math.PI) / 180);
// Handle flips
if (currentState.flipX || currentState.flipY) {
ctx.scale(currentState.flipX ? -1 : 1, currentState.flipY ? -1 : 1);
}
// Create a temporary image from the current preview
const img = new Image();
img.src = previewImage.src;
img.onload = function() {
// Draw the image with all transformations
ctx.drawImage(
img,
-newWidth / 2, -newHeight / 2,
newWidth, newHeight
);
ctx.restore();
// Convert to blob with current format and quality
const format = formatSelect.value;
const quality = parseInt(qualitySlider.value) / 100;
let mimeType;
switch(format) {
case 'jpeg': mimeType = 'image/jpeg'; break;
case 'png': mimeType = 'image/png'; break;
case 'webp': mimeType = 'image/webp'; break;
case 'gif': mimeType = 'image/gif'; break;
default: mimeType = 'image/jpeg';
}
canvas.toBlob(blob => {
const filename = `resized_image_${new Date().getTime()}.${format}`;
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
showLoading(false);
// Show success message
showMessage('Image downloaded successfully!', 'success');
}, mimeType, quality);
};
}
function undo() {
if (historyIndex > 0) {
historyIndex--;
const state = imageHistory[historyIndex];
processedBlob = state.blob;
// Update UI with previous state
previewImage.src = URL.createObjectURL(state.blob);
widthInput.value = state.width;
heightInput.value = state.height;
formatSelect.value = state.format;
qualitySlider.value = state.quality * 100;
qualityValue.textContent = `${state.quality * 100}%`;
rotationAngle = state.rotation;
flipHorizontal = state.flipX;
flipVertical = state.flipY;
// Update display size and file size
updateNewSize();
const fileSizeMB = (state.blob.size / (1024 * 1024)).toFixed(2);
fileSizeEl.textContent = `${fileSizeMB} MB`;
updateUndoRedoState();
// Enable/disable buttons appropriately
downloadBtn.disabled = false;
processBtn.disabled = false;
}
}
function redo() {
if (historyIndex < imageHistory.length - 1) {
historyIndex++;
const state = imageHistory[historyIndex];
processedBlob = state.blob;
// Update UI with next state
previewImage.src = URL.createObjectURL(state.blob);
widthInput.value = state.width;
heightInput.value = state.height;
formatSelect.value = state.format;
qualitySlider.value = state.quality * 100;
qualityValue.textContent = `${state.quality * 100}%`;
rotationAngle = state.rotation;
flipHorizontal = state.flipX;
flipVertical = state.flipY;
// Update display size and file size
updateNewSize();
const fileSizeMB = (state.blob.size / (1024 * 1024)).toFixed(2);
fileSizeEl.textContent = `${fileSizeMB} MB`;
updateUndoRedoState();
// Enable/disable buttons appropriately
downloadBtn.disabled = false;
processBtn.disabled = false;
}
}
function redrawPreview() {
if (!originalImage) return;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
let width = parseInt(widthInput.value) || originalImage.width;
let height = parseInt(heightInput.value) || originalImage.height;
// Adjust canvas dimensions based on rotation
if (Math.abs(rotationAngle) === 90 || Math.abs(rotationAngle) === 270) {
canvas.width = height;
canvas.height = width;
// Swap width and height for drawing
[width, height] = [height, width];
} else {
canvas.width = width;
canvas.height = height;
}
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Save the current state
ctx.save();
// Move to center of canvas
ctx.translate(canvas.width / 2, canvas.height / 2);
// Apply rotation
ctx.rotate((rotationAngle * Math.PI) / 180);
// Apply flips
ctx.scale(flipHorizontal ? -1 : 1, flipVertical ? -1 : 1);
// Draw image centered
let sourceImage = originalImage;
if (cropper && cropper.getCroppedCanvas()) {
sourceImage = cropper.getCroppedCanvas();
}
ctx.drawImage(
sourceImage,
-width / 2,
-height / 2,
width,
height
);
// Restore context
ctx.restore();
// Update preview with correct format and quality
canvas.toBlob(blob => {
previewImage.src = URL.createObjectURL(blob);
updateNewSize();
}, formatSelect.value, qualitySlider.value / 100);
}
function updateNewSize() {
if (widthInput.value && heightInput.value) {
newSizeEl.textContent = `${widthInput.value}×${heightInput.value}px`;
}
}
function updateUndoRedoState() {
const undoBtn = document.getElementById("undoBtn");
const redoBtn = document.getElementById("redoBtn");
undoBtn.disabled = historyIndex <= 0;
redoBtn.disabled = historyIndex >= imageHistory.length - 1;
undoBtn.classList.toggle("disabled", historyIndex <= 0);
redoBtn.classList.toggle("disabled", historyIndex >= imageHistory.length - 1);
}
function resetEditor() {
if (confirm('Are you sure you want to reset? This will clear your current image.')) {
editorContainer.style.display = 'none';
uploadArea.style.display = 'block';
previewImage.src = '';
fileInput.value = '';
originalImage = null;
processedBlob = null;
downloadBtn.disabled = true;
imageHistory = [];
historyIndex = 0;
updateUndoRedoState();
}
}
function showLoading(show) {
loadingIndicator.style.display = show ? 'flex' : 'none';
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
// Hide error after 5 seconds
setTimeout(() => {
errorMessage.style.display = 'none';
}, 5000);
}
function showMessage(message, type) {
const messageEl = document.createElement('div');
messageEl.className = `message ${type}`;
messageEl.textContent = message;
document.body.appendChild(messageEl);
// Animate in
setTimeout(() => {
messageEl.style.opacity = '1';
messageEl.style.transform = 'translateY(0)';
}, 10);
// Remove after 3 seconds
setTimeout(() => {
messageEl.style.opacity = '0';
messageEl.style.transform = 'translateY(-20px)';
setTimeout(() => {
document.body.removeChild(messageEl);
}, 300);
}, 3000);
}
});