-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
920 lines (898 loc) · 28.2 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
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="Version" content="21.12.06" />
<meta name="Author" content="CyberMajeed" />
<link rel="shortcut icon" href="src/WebPad.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Web Pad</title>
<style>
/*code*/
/*#00192e*/
@import url("https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap");
:root {
--dark-theme: #161616;
--button-hover-bg: #8e00fd;
}
body {
font-family: calibri;
height: 100vh;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
min-width: fit-content;
overflow: hidden;
}
::selection {
color: black;
background: #fff;
}
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: dodgerblue;
border-radius: 50px;
}
::-webkit-scrollbar-thumb {
background: black;
border-radius: 50px;
}
/*loader*/
#onLoader {
user-select: none;
height: 100%;
width: 100%;
position: absolute;
z-index: 400;
text-align: center;
background-color: #181818;
}
#onLoader span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%) scale(3);
color: #000;
font-family: "Syne Mono", monospace;
font-weight: 800;
text-transform: uppercase;
border-bottom: 4px solid #000;
}
#onLoader span:before {
border-bottom: 4px solid #6f00ff;
position: absolute;
content: attr(data-text);
text-shadow: 0px 0px 4px #6f00ff;
color: #6f00ff;
overflow: hidden;
width: 0;
}
@keyframes load {
0% {
width: 0;
}
100% {
width: 100%;
}
}
/*loader ends*/
.tools {
user-select: none;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
flex-direction: row;
box-shadow: 0px 0px 5px #505050;
z-index: 3;
}
.tools .toolPin {
text-align: center;
width: 20%;
padding: 10px 30px;
cursor: pointer;
transition: 0.3s;
}
/*tooltips*/
.toolTipDiv {
position: absolute;
top: 3.5em;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
flex-direction: row;
transform: scale(0);
}
.toolPin:hover ~ .toolTipDiv {
transform: scale(1);
}
.toolTipDiv .toolTip {
font-weight: bold;
width: 20%;
min-width: fit-content;
text-transform: capitalize;
text-align: center;
background: #424242;
padding: 8px 1px;
border-radius: 5px;
color: #fff;
z-index: 7;
transition: all 0.3s;
opacity: 0;
visibility: hidden;
}
/*1*/
.saveFile:hover ~ div.toolTipDiv span.tipsaveFile {
visibility: visible;
opacity: 1;
}
/*2*/
.copyCodes:hover ~ div.toolTipDiv span.tipCopyCodes {
visibility: visible;
opacity: 1;
}
/*3*/
.runCode:hover ~ div.toolTipDiv span.tipRunCode {
visibility: visible;
opacity: 1;
}
/*4*/
.swapView:hover ~ div.toolTipDiv span.tipSwapView {
visibility: visible;
opacity: 1;
}
/*5*/
.theme:hover ~ div.toolTipDiv span.tipTheme {
visibility: visible;
opacity: 1;
}
/*tool tip ends*/
.toolPin svg {
transition: all 0.1s;
}
.toolPin:hover svg {
fill: #fff;
transform: scale(1.5);
}
.toolPin:active svg {
transform: scale(1);
}
.tools .toolPin:hover {
background: var(--button-hover-bg);
}
.runCode.autoRunEnabled {
background: #7900fd;
}
.workArea {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.workArea .editor {
height: 100%;
width: 50%;
border-right: 2px solid;
overflow: hidden;
}
.workArea .preview {
height: 100%;
border-right: 2px solid;
width: 50%;
}
.editor textarea#editorArea {
padding: 15px 10px;
line-height: 22.5px;
font-family: cursive;
font-size: medium;
color: #000;
font-weight: 500;
border: none;
outline: none;
height: calc(100% - 1.5em);
width: 100%;
background: #fff;
resize: none;
overflow-y: auto;
overflow-x: hidden;
}
/*swap*/
.workArea.swapFlex {
flex-direction: column;
}
.workArea .editor.swap,
.preview.swap {
height: 50%;
width: 100%;
}
.preview.swap {
border-top: 2px solid;
}
/*swapped ends*/
/*dark theme*/
.tools.darkTools {
background: var(--dark-theme);
}
svg.darkSvg {
fill: #fff;
}
.darkPin:hover {
background: #fff;
}
.darkPin:hover .darkSvg {
fill: var(--dark-theme);
filter: drop-shadow(0px 0px 3px #fff);
}
.editor textarea.darkEditorArea {
background: var(--dark-theme) !important;
color: #fff !important;
}
.editor.darkEditor {
background: #161616 !important;
}
/*dark theme ends*/
iframe.previewFrame {
height: 100%;
width: 100%;
}
/*popup*/
.helpBox {
height: fit-content;
width: 40em;
max-width: 90%;
min-width: 30em;
overflow: hidden;
background: #fff;
color: black;
box-shadow: 0px 0px 20px dodgerblue;
z-index: 9;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
align-items: flex-start;
justify-content: left;
flex-direction: column;
text-transform: capitalize;
border-radius: 10px;
transition: all 0.3s;
animation: flyin 0.2s linear;
}
@keyframes flyin {
from {
opacity: 0;
top: 100%;
}
}
.backgroundBox {
position: absolute;
height: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 8;
}
.helpBox div.keyShortcuts {
display: flex;
align-items: flex-start;
justify-content: left;
flex-direction: column;
padding: 10px 0;
}
.helpBox div.keyShortcuts header {
font-weight: 900;
width: calc(100% - 20px);
padding: 2px 10px;
}
.helpBox div.aboutWebPad {
font-family: cursive;
padding: 10px 10px;
text-align: justify;
width: calc(100% - 20px);
line-height: 25px;
}
.helpBox div span {
margin: 10px 10px;
}
.helpBox span code {
user-select: none;
background: #cfcfcf;
padding: 5px;
border-radius: 4px;
font-family: monospace !important;
}
.helpBox .close {
user-select: none;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
margin: 0;
padding: 5px 8px;
width: calc(100% - 16px);
font-size: xx-large;
font-weight: 900;
background: dodgerblue;
color: white;
border-radius: 10px 10px 0 0;
box-shadow: 0px 1px 1px;
}
.helpBox .close em {
transition: all 0.2s;
}
.helpBox .close em:hover {
text-shadow: 0px 0px 3px red, 0px 0px 3px red, 0px 0px 3px red;
transform: scale(1.4);
}
.helpBox span.close b {
cursor: default;
font-size: x-large;
width: 100%;
}
/*popup ends*/
/*user visit*/
.helpBox div {
box-shadow: 0px 0px 1px;
width: 100%;
display: flex;
justify-content: right;
align-items: center;
}
.helpBox div:last-child {
font-weight: 800;
font-size: large;
justify-content: flex-end !important;
background: dodgerblue;
color: #fff;
}
label.userVisit {
user-select: none;
margin: 3px 8px;
cursor: pointer;
height: 1em;
width: 2em;
background: #c0c0c0;
border-radius: 3em;
transition: all 0.3s;
display: flex;
align-items: center;
box-shadow: inset 0px 0px 2px #000;
}
label.userVisit u.slider {
box-shadow: 0px 0px 2px #000;
background: #fff;
height: 0.8em;
width: 0.8em;
border-radius: 1em;
position: absolute;
transition: all 0.3s;
transform: translateX(0.1em);
}
#userVisit:checked ~ label.userVisit u.slider {
transform: translateX(1.1em);
}
#userVisit:checked ~ label.userVisit {
background: #8300fd;
}
/*user visit ends*/
/*Confirm Box*/
div.confirmBox {
z-index: 100;
background: #ffffff;
box-shadow: 0px 0px 8px rgb(65, 65, 65);
border-radius: 10px;
min-height: 180px;
min-width: 430px;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
position: absolute;
top: -50%;
left: 50%;
transform: translate(-50%, -50%);
transition: all 0.3s;
visibility: hidden;
opacity: 0;
}
.confirmBox.showConfirmBox {
top: 50%;
opacity: 1;
visibility: visible;
}
.confirmBox input.inFileName {
outline: none;
border: 2px solid #bcbbbb;
border-radius: 3px;
width: 90%;
transition: all 0.2s;
padding: 8px 5px;
}
.confirmBox .fileLabel {
font-size: large;
font-weight: 800;
color: #6f00ff;
}
input.inFileName:focus {
border: 2px solid dodgerblue;
box-shadow: 0px 0px 3px dodgerblue;
}
.fileNameButtons {
width: calc(90% + 10px);
display: flex;
justify-content: end;
}
.confirmBox span {
user-select: none;
}
.confirmBox .fileNameButtons span {
cursor: pointer;
margin: 0 0 0 10px;
padding: 5px 10px;
text-align: center;
background: dodgerblue;
border-radius: 5px;
width: 20%;
transition: all 0.3s;
font-weight: 600;
}
.fileNameButtons span:hover {
transform: scale(1.1);
}
.confirmBox span.errorFileName {
display: none;
text-transform: capitalize;
color: red;
text-align: left;
width: calc(90% + 10px);
transition: all 0.5s;
}
/*Confirm Box ends*/
/*alert box*/
.alertBox {
user-select: none;
height: fit-content;
width: fit-content;
padding: 12px 24px;
background: #383838;
position: absolute;
bottom: -100%;
left: 50%;
transform: translateX(-50%);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
border-radius: 10px;
z-index: 100;
visibility: hidden;
opacity: 0;
transition: all 0.3s;
}
.alertBox.showAlertBox {
bottom: 50%;
left: 50%;
transform: translate(-50%, -50%);
visibility: visible;
opacity: 1;
}
/*alert box ends*/ ;
</style>
</head>
<body>
<div id="onLoader">
<span data-text="Loading...">Loading...</span>
</div>
<!--loader ends-->
<span class="backgroundBox"></span>
<div class="helpBox">
<span class="close">
<img src="src/WebPad.png" style="margin-right: 5px; height: 30px" />
<b>Web Pad</b>
<em>×</em>
</span>
<div class="aboutWebPad">
<p>
<b>Web Pad</b> is a suitable html compiler created for students who
are willing to practice HTML by writing html codes in notepad >>
saving it as '.html' >> going to the saved location >> opening in
browsers to preview the output. But this application let you write
HTML codes and run it on-time, without saving or opening the file in
browser.
</p>
</div>
<div class="keyShortcuts">
<header>Keyboard Shortcuts</header>
<span>
Click [ <code>Ctrl</code> + <code>Enter</code> ] to run the code</span
>
<span>
Click [ <code>Ctrl</code> + <code>Shift</code> + <code>S</code> ] to
save the codes
</span>
<span>
DoubleClick the run code button to toggle <b>Auto Code-Runner</b>
</span>
</div>
<!--input check-->
<div>
<input type="checkbox" name="userVisit" id="userVisit" hidden />
<span>Don't Show Again</span>
<label for="userVisit" class="userVisit">
<u class="slider"></u>
</label>
</div>
</div>
<div class="tools">
<div class="saveFile toolPin">
<!--SVG-->
<svg
xmlns="http://www.w3.org/2000/svg"
height="25px"
viewBox="0 0 24 24"
width="25px"
fill="#000000"
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M17.59 3.59c-.38-.38-.89-.59-1.42-.59H5c-1.11 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7.83c0-.53-.21-1.04-.59-1.41l-2.82-2.83zM12 19c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm1-10H7c-1.1 0-2-.9-2-2s.9-2 2-2h6c1.1 0 2 .9 2 2s-.9 2-2 2z"
/>
</svg>
<!--SVG ENDS-->
</div>
<div class="copyCodes toolPin">
<!--SVG-->
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
height="25px"
viewBox="0 0 24 24"
width="25px"
fill="#000000"
>
<g>
<rect fill="none" height="25" width="25" />
</g>
<g>
<path
d="M15,20H5V7c0-0.55-0.45-1-1-1h0C3.45,6,3,6.45,3,7v13c0,1.1,0.9,2,2,2h10c0.55,0,1-0.45,1-1v0C16,20.45,15.55,20,15,20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"
/>
</g>
</svg>
<!--SVG ENDS-->
</div>
<div class="runCode toolPin">
<!--SVG-->
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
height="25px"
viewBox="0 0 24 24"
width="25px"
fill="#000000"
>
<g>
<rect fill="none" height="25" width="25" />
</g>
<g>
<path
d="M12,2C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,2z M9.5,14.67V9.33c0-0.79,0.88-1.27,1.54-0.84 l4.15,2.67c0.61,0.39,0.61,1.29,0,1.68l-4.15,2.67C10.38,15.94,9.5,15.46,9.5,14.67z"
/>
</g>
</svg>
<!--SVG ENDS-->
</div>
<div class="swapView toolPin">
<!--SVG-->
<svg
xmlns="http://www.w3.org/2000/svg"
height="25px"
viewBox="0 0 24 24"
width="25px"
fill="#000000"
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M10.23 1.75c-.59-.59-1.54-.59-2.12 0L1.75 8.11c-.59.59-.59 1.54 0 2.12l12.02 12.02c.59.59 1.54.59 2.12 0l6.36-6.36c.59-.59.59-1.54 0-2.12L10.23 1.75zm3.89 18.73L3.52 9.88c-.39-.39-.39-1.02 0-1.41l4.95-4.95c.39-.39 1.02-.39 1.41 0l10.61 10.61c.39.39.39 1.02 0 1.41l-4.95 4.95c-.39.38-1.03.38-1.42-.01zM17.61 1.4C16.04.57 14.06-.03 11.81.02c-.18 0-.26.22-.14.35l3.48 3.48 1.33-1.33c3.09 1.46 5.34 4.37 5.89 7.86.06.41.44.69.86.62.41-.06.69-.45.62-.86-.6-3.8-2.96-7-6.24-8.74zM8.85 20.16l-1.33 1.33c-3.09-1.46-5.34-4.37-5.89-7.86-.06-.41-.44-.69-.86-.62-.41.06-.69.45-.62.86.6 3.81 2.96 7.01 6.24 8.75 1.57.83 3.55 1.43 5.8 1.38.18 0 .26-.22.14-.35l-3.48-3.49z"
/>
</svg>
<!--SVG ENDS-->
</div>
<div class="theme toolPin">
<!--SVG-->
<svg
xmlns="http://www.w3.org/2000/svg"
height="25px"
viewBox="0 0 24 24"
width="25px"
fill="#000000"
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M20 15.31l1.9-1.9c.78-.78.78-2.05 0-2.83L20 8.69V6c0-1.1-.9-2-2-2h-2.69l-1.9-1.9c-.78-.78-2.05-.78-2.83 0L8.69 4H6c-1.1 0-2 .9-2 2v2.69l-1.9 1.9c-.78.78-.78 2.05 0 2.83l1.9 1.9V18c0 1.1.9 2 2 2h2.69l1.9 1.9c.78.78 2.05.78 2.83 0l1.9-1.9H18c1.1 0 2-.9 2-2v-2.69zm-8 1.59V7.1c0-.61.55-1.11 1.15-.99C15.91 6.65 18 9.08 18 12s-2.09 5.35-4.85 5.89c-.6.12-1.15-.38-1.15-.99z"
/>
</svg>
<!--SVG ENDS-->
</div>
<div class="toolTipDiv">
<span class="tipsaveFile toolTip">save Codes</span>
<span class="tipCopyCodes toolTip">Copy codes</span>
<span class="tipRunCode toolTip">Run code</span>
<span class="tipSwapView toolTip">Swap view</span>
<span class="tipTheme toolTip">Switch theme</span>
</div>
</div>
<div class="workArea">
<div class="editor">
<textarea
name="editor"
class="lined"
id="editorArea"
spellcheck="false"
placeholder="Code Here"
></textarea>
</div>
<div class="preview">
<iframe class="previewFrame" frameborder="0"></iframe>
</div>
</div>
<!--save popup-->
<div class="confirmBox">
<span class="fileLabel">Your File Name:</span>
<input
type="text"
name="fileName"
class="inFileName"
value="Html-Program.html"
/>
<span class="errorFileName">*File name is invalid</span>
<div class="fileNameButtons">
<span class="saveButton">Save</span>
<span class="cancelButton">Cancel</span>
</div>
</div>
<!--save popup ends-->
<!--alert box-->
<div class="alertBox"></div>
<!--alert box ends-->
<!--script.js-->
<script>
let swapper = document.querySelector(".swapView"),
theme = document.querySelector(".theme"),
runCode = document.querySelector(".runCode"),
copyCode = document.querySelector(".copyCodes"),
tipCopyCodes = document.querySelector(".tipCopyCodes"),
saveFile = document.querySelector(".saveFile"),
tools = document.querySelector(".tools"),
toolPin = document.querySelectorAll(".toolPin"),
toolSvg = document.querySelectorAll(".toolPin svg"),
codeArea = document.querySelector(".editor textarea#editorArea"),
editor = document.querySelector(".workArea .editor"),
worker = document.querySelector(".workArea"),
previewFrame = document.querySelector(".preview .previewFrame"),
alertBox = document.querySelector(".alertBox"),
closeHelpBox = document.querySelector(".helpBox span.close em"),
helpBox = document.querySelector(".helpBox"),
showHelpBox = document.querySelector(".helpBox div input#userVisit"),
confirmBox = document.querySelector(".confirmBox"),
saveButton = document.querySelector(".saveButton"),
cancelButton = document.querySelector(".cancelButton"),
inFileName = document.querySelector(".inFileName"),
preview = document.querySelector(".workArea .preview");
//===================Help Box====================
closeHelpBox.onclick = () => {
helpBox.style.top = "90%";
helpBox.style.opacity = "0";
setTimeout(() => {
helpBox.style.display = "none";
document.querySelector(".backgroundBox").style.display = "none";
}, 150);
};
//don't show again
showHelpBox.onchange = function helpBoxState() {
if (showHelpBox.checked == true) {
localStorage.setItem("showHelpBox", "true");
} else if (showHelpBox.checked == false) {
localStorage.setItem("showHelpBox", "false");
}
};
//===================save As====================
//===================show confirm box====================
saveFile.onclick = () => {
closeHelpBox.click();
setTimeout(() => {
confirmBox.classList.add("showConfirmBox");
document.querySelector(".backgroundBox").style.display = "block";
}, 150);
};
//===================Cancel confirm box====================
cancelButton.onclick = () => {
confirmBox.classList.remove("showConfirmBox");
document.querySelector(".backgroundBox").style.display = "none";
};
inFileName.oninput = function checkvalidity() {
const format = /^([A-Za-z0-9_\-\.])+\.[a-zA-Z]{1,5}$/;
if (inFileName.value.match(format)) {
document.querySelector(".errorFileName").style.display = "none";
} else {
document.querySelector(".errorFileName").style.display = "block";
}
/*
if (inFileName.value == "") {
document.querySelector(".errorFileName").style.display = "block";
} else {
document.querySelector(".errorFileName").style.display = "none";
}*/
};
saveButton.onclick = function savingFile() {
var format = /^([A-Za-z0-9_\-])+\.[a-zA-Z]{1,5}$/;
let fileName = inFileName.value;
if (inFileName.value.match(format)) {
let fileType = new Blob([codeArea.value], { type: "text/html" });
let anchor = document.createElement("a");
anchor.download = `${fileName}`;
anchor.href = window.URL.createObjectURL(fileType);
anchor.target = "_blank";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
confirmBox.classList.remove("showConfirmBox");
document.querySelector(".backgroundBox").style.display = "none";
document.querySelector(".errorFileName").style.display = "none";
} else {
document.querySelector(".errorFileName").style.display = "block";
}
};
//===================showPreview====================
runCode.onclick = showPreview;
function showPreview() {
var frame = previewFrame.contentWindow.document;
frame.open();
frame.write(codeArea.value);
frame.close();
let hyphen = frame.title !== "" ? "-" : "";
document.title = `${frame.title} ${hyphen} Web Pad`;
}
//autoRun
runCode.ondblclick = () => {
runCode.classList.toggle("autoRunEnabled");
alertBox.classList.add("showAlertBox");
if (runCode.classList.contains("autoRunEnabled")) {
alertBox.innerText = "Auto Code-Runner Enabled";
localStorage.setItem("autoCodeRunner", "Enabled");
} else {
alertBox.innerText = "Auto Code-Runner Disabled";
localStorage.setItem("autoCodeRunner", "Disabled");
}
setTimeout(() => {
alertBox.classList.remove("showAlertBox");
}, 2000);
};
//Run-Func()
codeArea.oninput = () => {
if (runCode.classList.contains("autoRunEnabled")) {
showPreview();
}
//storage
localStorage.setItem("codes", codeArea.value);
};
//ends preview
//================copy codes====================================
copyCode.onclick = () => {
codeArea.select();
document.execCommand("copy");
window.getSelection().removeAllRanges();
tipCopyCodes.innerText = "Codes Copied!";
copyCode.onmouseleave = () => {
setTimeout(() => {
tipCopyCodes.innerText = "Copy codes";
}, 2000);
};
};
//====================view===============
swapper.onclick = function changeView() {
worker.classList.toggle("swapFlex");
editor.classList.toggle("swap");
preview.classList.toggle("swap");
//local
if (worker.classList.contains("swapFlex")) {
localStorage.setItem("userView", "horizontal");
} else {
localStorage.setItem("userView", "vertical");
}
};
//================theme====================================
theme.onclick = function changeTheme() {
theme.classList.toggle("darkTheme");
codeArea.classList.toggle("darkEditorArea");
editor.classList.toggle("darkEditor");
tools.classList.toggle("darkTools");
for (i = 0; i < toolSvg.length; i++) {
toolSvg[i].classList.toggle("darkSvg");
}
for (i = 0; i < toolPin.length; i++) {
toolPin[i].classList.toggle("darkPin");
}
//local
if (theme.classList.contains("darkTheme")) {
localStorage.setItem("userTheme", "dark");
} else {
localStorage.setItem("userTheme", "light");
}
};
//localStorage Get Items
//userTheme
if (localStorage.userTheme == "dark") {
theme.click();
}
//userView
if (localStorage.userView == "horizontal") {
swapper.click();
}
//userCode
if (localStorage.codes) {
codeArea.textContent = localStorage.getItem("codes", codeArea.value);
} else {
let defaultCodes = `
<html>
<head>
<title> </title>
<style> </style>
</head>
<body>
</body>
</html>`;
codeArea.textContent = defaultCodes;
}
//shortcuts================================================
window.onkeyup = (e) => {
if (e.ctrlKey && e.keyCode === 13) {
runCode.click();
} else if (e.ctrlKey && e.altKey && e.keyCode === 83) {
saveFile.click();
} else if (e.keyCode === 27) {
cancelButton.click();
closeHelpBox.click();
}
};
//===================window.onload===================
window.onload = () => {
let loadDelayArray = [500, 1000, 1500, 2000, 2500];
let loadDelay =
loadDelayArray[Math.floor(Math.random() * loadDelayArray.length)];
document.head.innerHTML += `<style>
#onLoader span:before {
animation: load ${loadDelay}ms linear forwards;
}
</style>`;
setTimeout(() => {
let onLoad = document.getElementById("onLoader");
onLoad.style.display = "none";
//other Func
runCode.click();
//dblclick?
if (localStorage.autoCodeRunner == "Enabled") {
var clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent("dblclick", true, true);
runCode.dispatchEvent(clickEvent);
}
//show helpbox?=======================
if (localStorage.showHelpBox == "true") {
helpBox.style.display = "none";
document.querySelector(".backgroundBox").style.display = "none";
}
//end=======================
}, loadDelay);
};
</script>
</body>
</html>