-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1976 lines (1712 loc) · 70.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
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, width=device-width">
<title>Snapsort</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/5.3.7/photoswipe.min.css"
integrity="sha512-LFWtdAXHQuwUGH9cImO9blA3a3GfQNkpF2uRlhaOpSbDevNyK1rmAjs13mtpjvWyi+flP7zYWboqY+8Mkd42xA=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<link href="https://fonts.googleapis.com/css?family=Merriweather:300&display=swap" rel="stylesheet">
<base target="_blank">
</head>
<body>
<!--i once had the problem of all the styles not fitting the allowed head size, so i put style here-->
<style>
:root {
--theme-color: #388e3c;
--background-color: white;
--theme-color-green: #388e3c;
--theme-color-yellow: #F4B400;
--theme-color-grey: #9e9e9e;
--theme-color-light-grey: lightgrey;
--shake-distance: 0.5rem;
}
html {
font-family: 'Merriweather', serif;
}
body, html {
margin: 0; /*100vh creates scrollbar otherwise*/
}
/*CENTERING//////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*dont apply these to body*/
/*the container in which the child containers should be centered */
.center-parent {
display: grid;
place-items: center;
height: 100vh;
/*padding: 0 1em 0 1em; !*prevent text to touch border on smaller screens*!*/
}
/*the childs to be centered (not needed)*/
.center-child {
/*in chrome mobile, makes page take up whole space*/
min-width: 90vw;
/*also setting this width somehow prevents the unreachable left side problem induced by indented class*/
width: 90vw;
}
@media screen and (min-width: 50rem) {
.center-child {
/*prevents some page jumping when collapsing items*/
min-width: 30rem;
max-width: 30rem;
}
}
.title {
font-size: 3em;
/*font-style: italic;*/
}
/*subtitle under h1 header*/
.subtitle {
font-size: 0.8rem;
margin-top: -2rem;
font-style: italic;
}
.title-big {
font-size: 1.8rem;
font-weight: bold;
}
.title-medium {
font-size: 1.4rem;
font-weight: bold;
}
.title-small {
font-size: 1rem;
font-weight: bold;
}
/*all links on the site*/
.link {
color: var(--theme-color);
text-decoration: none;
cursor: pointer;
}
/*when a link is hovered*/
.link:hover {
text-decoration: underline;
}
.hidden-link {
text-decoration: none;
color: inherit;
cursor: pointer;
}
/*button with a link*/
.link-button {
border: 0.15rem solid var(--theme-color);
background-color: var(--theme-color);
color: var(--background-color);
text-decoration: none;
font-weight: bold;
padding: 0.4rem 0.5rem;
text-align: center;
display: inline-block;
/*margin-right: 5px;*/
cursor: pointer;
margin: 0.5em;
border-radius: 0.4rem;
}
.invisible-button {
background-color: transparent;
border: none;
color: #000; /* Set the desired color for the text */
cursor: pointer;
padding: 0;
font-weight: bold;
}
.invisible-button:hover {
/*box shadow is basically a border which does not move adjoining elements*/
box-shadow: 0 0 0 0.05rem lightgrey;
}
.c-section-button:hover {
box-shadow: 0 0 0 0.05rem lightgrey;
}
/*button with a link with inverse colors (apply link-button first)*/
.link-button-inverse {
color: var(--theme-color);
background-color: var(--background-color);
}
/*upload button*/
.upload-btn-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
margin: 0.5rem;
}
.upload-btn-wrapper input[type=file] {
font-size: 10rem;
position: absolute;
left: 0;
top: 0;
opacity: 0;
}
/*flex table*/
.flex-table {
display: flex;
flex-direction: column;
margin-bottom: 0.8rem;
}
.flex-table-row {
display: flex;
align-items: center;
margin: 0.5rem 0 0.5rem 0;
}
.flex-table-first-row {
font-weight: bold;
border-bottom: 0.2rem solid black;
padding-bottom: 0.4rem;
}
.flex-table-cell {
flex: 1;
margin-right: 0.6rem;
padding: 0.3rem;
}
.flex-table-big-cell {
flex: 4;
}
.flex-table-small-cell {
text-align: center;
min-width: 3em;
flex: 1;
}
.flex-table-small-cell:first-child {
border-right: 0.15rem solid black;
}
.flex-table-small-cell:last-child {
border-left: 0.15rem solid black;
}
@keyframes jello {
from, 11.1%, to {
transform: none;
}
22.2% {
transform: skewX(-5deg) skewY(-5deg);
}
33.3% {
transform: skewX(2.5deg) skewY(2.5deg);
}
44.4% {
transform: skewX(-1.25deg) skewY(-1.25deg);
}
55.5% {
transform: skewX(0.625deg) skewY(0.625deg);
}
66.6% {
transform: skewX(-0.3125deg) skewY(-0.3125deg);
}
77.7% {
transform: skewX(0.15625deg) skewY(0.15625deg);
}
88.8% {
transform: skewX(-0.078125deg) skewY(-0.078125deg);
}
}
.shake-jello {
animation: jello 0.5s;
}
/*shake animation*/
.shake {
animation: shake 0.3s;
}
@keyframes shake {
0% {
transform: translateY(0);
}
20% {
transform: translateY(calc(var(--shake-distance) * -1));
}
40% {
transform: translateY(var(--shake-distance));
}
60% {
transform: translateY(calc(var(--shake-distance) * -1));
}
80% {
transform: translateY(var(--shake-distance));
}
100% {
transform: translateY(0);
}
}
/*vertical*/
.vertical {
display: flex;
flex-direction: column;
}
/*collapsable section*/
/*hold everything about the section*/
.c-section {
display: flex;
flex-direction: column;
}
/*hold the title and the collapse image button*/
.c-section-title-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.6rem;
cursor: pointer;
}
.c-section-button {
transition: transform 200ms ease;
margin-right: 1rem;
font-size: 1.0em; /*em, i want to inherit the font size from the title row*/
}
.c-section-title {
flex-grow: 1;
margin: 0;
}
/*the content to hide / show*/
.c-section-content {
/*show by default if javascript is disabled*/
display: block;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/*photoswipe slide markup for items which cannot be displayed*/
.custom-html-slide {
font-size: 3rem;
line-height: 3rem;
max-width: 25rem;
width: 100%;
padding: 0 1.5rem;
margin: 5rem auto 0;
color: #fff;
}
/*footer visible when sorting */
.footer {
background: var(--background-color);
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 8rem;
z-index: 888888; /* what the hell is the z index of photoswipe */
display: flex;
flex-direction: column;
visibility: hidden;
/*flex-basis: auto;*/
place-items: center;
}
.footer-info-row {
height: 1.5rem;
}
.footer-keybindings {
display: flex;
white-space: nowrap;
flex-wrap: wrap;
height: 5rem;
/*if i hide overflow the buttons center instead of cut off*/
overflow-y: auto;
}
.footer-keybinding {
display: flex;
margin: 0.1rem;
border: 0.1rem solid black;
/*box-shadow: 0 0 0 0.1rem black;*/
font-family: monospace;
background-color: var(--theme-color-light-grey);
cursor: pointer;
height: 2rem;
align-items: center;
justify-content: center;
}
.footer-keybinding > div {
background-color: var(--background-color);
margin: 0.2rem;
border: 0.1rem solid black;
padding: 0.1rem 0.3rem 0.2rem 0.3rem;
/*height conflicts with margin*/
height: 1rem;
}
.footer-keybinding-selected {
background-color: var(--theme-color-green);
}
.footer-keybinding-selected > div {
background-color: var(--theme-color-yellow);
}
.footer-keybinding-key {
font-weight: bold;
}
.footer-keybinding-folder {
}
.selected-footer-keybinding {
background-color: var(--theme-color);
}
.selected-footer-keybinding-item {
background-color: greenyellow;
}
/*drag and drop markup*/
#drag-target {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999999999999;
pointer-events: none;
}
#drag-target.show {
display: flex;
align-items: center;
justify-content: center;
}
#drag-text {
font-size: 2rem;
color: #fff;
background-color: #333;
padding: 1.4rem;
border-radius: 0.2rem;
}
/* The snackbar - position it at the bottom and in the middle of the screen */
/*hehe chatgpt*/
#snackbar {
visibility: hidden;
min-width: 10rem;
margin-left: -5rem; /* Divide value of min-width by 2 */
background-color: #333;
color: #fff;
text-align: center;
border-radius: 0.1rem;
padding: 1rem;
position: fixed;
z-index: 999999;
left: 50%;
bottom: 2rem;
}
@keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 2rem;
opacity: 1;
}
}
@keyframes fadeout {
from {
bottom: 2rem;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
/*progress bar*/
.progress-bar {
width: 15rem;
height: 1.8rem;
border: 0.1rem solid lightgrey;
position: relative;
border-radius: 1000px;
display: none;
white-space: nowrap;
}
.progress {
width: 0;
transition: width 0.2s ease-out; /*smooth the progress bar*/
height: 100%;
background-color: var(--theme-color-yellow);
border-radius: 1000px;
}
.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-weight: bold;
font-size: 0.8em;
}
.indented {
margin-left: 2.5rem;
position: relative;
}
.indented::before {
content: "";
position: absolute;
top: 0;
left: -3rem;
width: 3rem;
height: 100%;
background-color: transparent;
}
pre {
white-space: pre-wrap;
}
.spinner {
animation: spin 3s infinite linear;
display: inline-block;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.floater {
animation: float 3s infinite ease-in-out; /* Animation properties */
display: inline-block;
}
@keyframes float {
0% {
transform: translateY(0); /* Start position */
}
50% {
transform: translateY(-0.2rem); /* Mid position (upward movement) */
}
100% {
transform: translateY(0); /* End position (return to original position) */
}
}
.code {
background-color: #f4f4f4;
border: 0.1rem solid #ccc;
border-radius: 0.4rem;
}
.code-navbar {
display: flex;
justify-content: space-between;
padding: 0.3rem;
border-bottom: 1px solid #ccc;
}
.code-navbar-buttons {
display: flex;
}
.code-content {
font-family: Consolas, monospace;
font-size: 0.75rem;
line-height: 1.5;
padding: 0.8rem;
white-space: pre-wrap;
}
.code-content.collapsed {
max-height: 4rem;
overflow: hidden;
background-image: linear-gradient(to bottom, #000000, #ffffff);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
/*-webkit-text-fill-color: transparent;*/
}
.code-button {
/*width: 2em;*/
/*height: 1em;*/
/*border: 1px solid black;*/
/*border-radius: 0.4rem;*/
margin-left: 0.3rem;
}
</style>
<div id="drag-target">
<span id="drag-text">Drop to upload</span>
</div>
<div id="snackbar"></div>
<div class="center-parent">
<div class="center-child">
<h1 class="title hidden-link" id="title">Snapsort</h1>
<p class="subtitle">
Sort photos within your browser!
</p>
<div id="log-bar">
</div>
<section class="c-section" id="upload-section">
<div class="c-section-title-row title-big">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">1: Upload files</p>
</div>
<div class="c-section-content indented">
Upload or drop files to sort.
<br>
<div class="upload-btn-wrapper">
<button class="link-button" id="folder-upload-btn">Upload folder</button>
<input type="file" id="folder-upload" webkitdirectory directory multiple>
</div>
<div class="upload-btn-wrapper">
<button class="link-button" id="upload-btn">Upload files</button>
<input id="file-upload" type="file" name="myfile" multiple/>
</div>
<div class="upload-btn-wrapper">
<button class="link-button link-button-inverse" id="upload-example-button">Load example</button>
</div>
<br>
<div id="upload-info"></div>
<div id="previous-upload-info"></div>
</div>
</section>
<section class="c-section" id="keybinding-section">
<div class="c-section-title-row title-big">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">2: Folders</p>
</div>
<div class="c-section-content">
Enter the names of the folders to sort to.
<div class="flex-table" id="keybindings-table">
<div class="flex-table-row flex-table-first-row">
<div class="flex-table-cell flex-table-small-cell"><span class="">🔑</span></div>
<div class="flex-table-cell flex-table-big-cell">Folder</div>
<!--hehe-->
<button class="flex-table-cell flex-table-small-cell invisible-button"
id="add-keybinding-button"><span title="Add"
style="color: transparent; text-shadow: 0 0 0 var(--theme-color-green); transform: rotate(45deg); display: inline-block">❌</span>
</button>
</div>
</div>
Optionally, add hotkeys to sort quickly to that folder.
<br>
<a class="link" id="example-upload-link">Example</a>
</div>
</section>
<section class="c-section" id="sort-section">
<div class="c-section-title-row title-big">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">3: Sort</p>
</div>
<div class="c-section-content indented">
<div class="progress-bar" id="upload-progress">
<div class="progress"></div>
<div class="progress-text">Upload progress bar</div>
</div>
Click to open the gallery to start sorting!<br>
<button class="link-button link-button-inverse" id="open-gallery-button">Start sorting</button>
</div>
</section>
<section class="c-section" id="apply-sort-section">
<div class="c-section-title-row title-big">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">4: Apply sorting</p>
</div>
<div class="c-section-content indented">
These commands create your folders, and move the files to them.
<br>
You can always undo this, see the 'Other' section.
<section class="c-section" id="apply-windows">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Windows</p>
</div>
<div class="c-section-content indented" id="windows-export"></div>
</section>
<section class="c-section" id="apply-linux">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Linux / MacOS</p>
</div>
<div class="c-section-content indented" id="linux-export"></div>
</section>
<section class="c-section" id="apply-universal">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Universal (zip)</p>
</div>
<div class="c-section-content indented">
Download a .zip file with your sorted items.
<br>
<div class="progress-bar" id="zip-progress">
<div class="progress"></div>
<div class="progress-text">Zip progress bar</div>
</div>
<button id="download-universal-sort" class="link-button link-button-inverse">Download .zip
</button>
<br>
This is slower and takes more space compared to applying the sort with commands.<br>
Creating the download will take a long time.<br>
The zip will contain all the files you just uploaded.
</div>
</section>
</div>
</section>
<section class="c-section" id="additional-options-section">
<div class="c-section-title-row title-big">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Other</p>
</div>
<div class="c-section-content indented">
<section class="c-section" id="undo-sort-section">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Undo sorting</p>
</div>
<div class="c-section-content indented">
These commands move the sorted items from their folders back to the main folder.
<section class="c-section" id="undo-windows">
<div class="c-section-title-row title-small">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Windows</p>
</div>
<div class="c-section-content indented" id="windows-undo"></div>
</section>
<section class="c-section" id="undo-linux">
<div class="c-section-title-row title-small">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Linux / MacOS</p>
</div>
<div class="c-section-content indented" id="linux-undo"></div>
</section>
</div>
</section>
<section class="c-section" id="about-section">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">About</p>
</div>
<div class="c-section-content indented">
Developed by <a class="link" href="https://t.me/JortDeveloper">Jort</a>.
<br>
GitHub: <a class="link" href="https://github.com/jort-dev/snapsort">Snapsort</a>.
<br>
<br>
The reason I developed this app is simply because I could not find an existing program which
allows you to manually sort images with hotkeys.
<br>
<br>
However, I have found a similar tool which sorts your files automatically with AI!
<br>
<ul>
<li>
<a class="link" href="https://ai-photo-sorter.vercel.app/">AI photo sorter</a> created
by <a class="link" href="https://github.com/visheratin/ai-photo-sorter">Visheratin</a>.
</li>
</ul>
I was inspired by the command line export method his work has.
<br>
<br>
<br>
If you have more money than you need,
and appreciate this tool, a donation would really excite me!
<ul>
<li>BTC: <code
style="word-wrap: break-word">bc1q8q9pt8c5uz92t7r0ltjmzzft9eulvey5cqghxx</code></li>
<li>Paypal:
<form action="https://www.paypal.com/donate" method="post">
<input type="hidden" name="hosted_button_id" value="Y7XZETS3RPWW6"/>
<input type="image"
src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif"
border="0" name="submit" title="PayPal - Donate to this dude"
alt="Donate with PayPal button"/>
<img alt="" border="0" src="https://www.paypal.com/en_NL/i/scr/pixel.gif" width="1"
height="1"/>
</form>
</li>
<li>Ko-fi: <br><a href="https://ko-fi.com/jort_dev" class="link">Donate a 'coffee'</a></li>
</ul>
</div>
</section>
<section class="c-section" id="advanced-options-section">
<div class="c-section-title-row title-medium">
<span class="c-section-button" title="Open section">></span>
<p class="c-section-title">Advanced options</p>
</div>
<div class="c-section-content">
Below are some options I mainly used for testing whilst developing this tool.
<br>
<br>
Simulate the uploading of files, using example images:
<br>
<button class="link-button link-button-inverse" id="example-images-button">Load example images
</button>
<button class="link-button link-button-inverse" id="example-images-fast-button">Load example
images (fast)
</button>
<br>
Clear all your sorted items:
<br>
<button class="link-button link-button-inverse" id="clear-mappings-button">Clear sorts</button>
<br>
Load example keybindings, as an example how the program can be used:
<br>
<button class="link-button link-button-inverse" id="example-keybindings-button">Load example
keybindings
</button>
<br>
Clear all the saved data. This includes defined folders and hotkeys, sorted items, opened
sections and
more:
<br>
<button class="link-button link-button-inverse" id="clear-storage-button">Clear all website data
</button>
</div>
</section>
</div>
</section>
<div class="footer" id="sort-footer">
<div class="footer-info-row" id="filename-display" style="font-weight: bold">Filename</div>
<div class="footer-info-row" id="mapped-folder-display" style="font-style: italic">Unsorted</div>
<div class="footer-keybindings" id="footer-keybindings"></div>
</div>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<script type="module">
import PhotoSwipeLightbox
from 'https://cdnjs.cloudflare.com/ajax/libs/photoswipe/5.3.7/photoswipe-lightbox.esm.min.js';
import PhotoSwipeVideoPlugin from 'https://cdn.jsdelivr.net/npm/[email protected]/src/index.min.js';
let pswp = null; // photoswipe instance, it is non-null if open
let lastTimeoutId = null; // used to log to user with a timeout
let loadedCount = 0; // keep track of how many uploaded items are loaded for gallery
let dragCounter = 0; // file drop: keep count of drag events to identify fake dragleave events
function logToUser(msg, timeout = 3000) {
clearTimeout(lastTimeoutId);
if (timeout > 0) {
let toastElement = document.getElementById("snackbar");
toastElement.textContent = msg
console.log(toastElement.textContent)
toastElement.classList.add("show")
toastElement.style.visibility = "visible"
let duration = timeout / 1000 - 0.5
toastElement.style.animation = `fadein 0.5s, fadeout 0.5s ${duration}s`
lastTimeoutId = setTimeout(function () {
toastElement.classList.remove("show");
toastElement.style.visibility = "hidden"
}, timeout);
}
}
function shakeElement(element) {
element.classList.add("shake-jello");
setTimeout(function () {
element.classList.remove("shake-jello");
}, 400);
}
function fileObjectToGalleryInputItem(file) {
let item = {}
const itemHtml = `<div class="custom-html-slide">${file.name}</div>`; // fallback if file can't be displayed
const fileType = file['type'];
// load image
const urlObj = URL.createObjectURL(file);
let loadVideos = true;
if (fileType.includes("image")) {
item.src = urlObj;
let img = new Image();
img.onload = function () {
++loadedCount
item.width = img.width;
item.height = img.height;
};
img.src = urlObj; //this loads the image, triggering the above event
}
// load video (takes long)
else if (fileType.includes("video") && loadVideos) {
let video = document.createElement("video");
video.addEventListener("loadeddata", function () {
if (video.videoWidth === 0 || video.videoHeight === 0) {
// if 0x0: browser does not support the video type, just show filename
item.html = itemHtml;
++loadedCount
}
else {
++loadedCount
item.width = video.videoWidth;
item.height = video.videoHeight;
item.videoSrc = urlObj;
item.type = "video";
item.msrc = urlObj; // not needed but prevents error showing
item.src = urlObj; // not needed but added for item check and cleanliness
}
});
video.src = urlObj; // this loads the video, triggering the above event
}
// fallback for remaining file types
else {
item.html = itemHtml;
++loadedCount
}
item.alt = file.name;
return item;
}
async function urlToImageFile(filename, url, fast = false) {
if (fast) {
const width = 2400
const height = 1600
url = `https://dummyimage.com/${width}x${height}/000000/ffffff&text=${filename}`
}
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const blob = new Blob([arrayBuffer]);
let file = new File([blob], filename);
file = new File([file], file.name, {type: "image/jpeg"}); //cant set it directly
return file;
}
async function getMockUploadEvent(fast = false) {
let urls = {
i1queen1: `https://images.pexels.com/photos/260024/pexels-photo-260024.jpeg?cs=srgb&dl=pexels-pixabay-260024.jpg&fm=jpg&w=3089&h=2114`,
i8queen2: `https://images.pexels.com/photos/3863802/pexels-photo-3863802.jpeg?cs=srgb&dl=pexels-john-ray-ebora-3863802.jpg&fm=jpg&w=4000&h=6000`,
i5queen3: `https://images.pexels.com/photos/2062542/pexels-photo-2062542.jpeg?cs=srgb&dl=pexels-bestbe-models-2062542.jpg&fm=jpg&w=4000&h=6000`,
i3water1: `https://images.pexels.com/photos/1556381/pexels-photo-1556381.jpeg?cs=srgb&dl=pexels-ray-piedra-1556381.jpg&fm=jpg&w=1728&h=2592`,
i9water2: `https://images.pexels.com/photos/4035587/pexels-photo-4035587.jpeg?cs=srgb&dl=pexels-g%C3%BCl-i%C5%9F%C4%B1k-4035587.jpg&fm=jpg&w=3264&h=4928`,
i3elephant1: `https://images.pexels.com/photos/1054655/pexels-photo-1054655.jpeg?cs=srgb&dl=pexels-harvey-sapir-1054655.jpg&fm=jpg&w=3461&h=2150`,
i5elephant2: `https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg?cs=srgb&dl=pexels-anthony-%29-133394.jpg&fm=jpg&w=4293&h=2975`,
i7elephant3: `https://images.pexels.com/photos/982021/pexels-photo-982021.jpeg?cs=srgb&dl=pexels-venkat-ragavan-982021.jpg&fm=jpg&w=5472&h=3648`,
i6rainbow1: `https://images.pexels.com/photos/1685503/pexels-photo-1685503.jpeg?cs=srgb&dl=pexels-egor-kamelev-1685503.jpg&fm=jpg&w=2548&h=3383`,
i4rainbow2: `https://images.pexels.com/photos/2279334/pexels-photo-2279334.jpeg?cs=srgb&dl=pexels-vlad-che%C8%9Ban-2279334.jpg&fm=jpg&w=3807&h=5711`,
i12rainbow3: `https://images.pexels.com/photos/6390455/pexels-photo-6390455.jpeg?cs=srgb&dl=pexels-jess-loiterton-6390455.jpg&fm=jpg&w=7200&h=9000`,
}
const width = 600
const height = 400
let files = []
for (let key of Object.keys(urls)) {
let url = urls[key]
url = url.replace(/(h=)\d+/, "$1" + height);
url = url.replace(/(w=)\d+/, "$1" + width);
console.log(`Downloading ${key}: ${url}`)
let imageFile = await urlToImageFile(key + ".jpg", url, fast);
files.push(imageFile)
}
// insert normal files (append prefix to maintain position after sorting)
const file1 = new File(["Yes, sorting normal files is also possible"], "i2not-an-image.txt", {type: "text/plain"});
const file2 = new File(["But the program is not optimized for it."], "i8file.pdf", {type: "text/plain"});
files.splice(2, 0, file1);
files.splice(5, 0, file2);