-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
964 lines (813 loc) · 62.6 KB
/
Copy pathindex.html
File metadata and controls
964 lines (813 loc) · 62.6 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
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
<!DOCTYPE html>
<html lang="vi" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Snowboard" />
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png" />
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon.png" />
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="css/style.css" />
<title>Snowboard - Sentechtipvn</title>
</head>
<body>
<div id="toast">Thông báo</div>
<div class="app-container" id="mainAppContainer">
<div class="app-grid" id="appGrid"></div>
</div>
<button id="settingsBtn" aria-label="Cài đặt">
<img src="icons/icon_setting.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='⚙️'" />
<div class="mark-overlay" id="settingMarkOverlay"></div>
</button>
<div id="dockArea" class="dock-container" style="display:none;"></div>
<div id="drawerWrapper">
<div id="drawerContent">
<button class="drawer-btn" id="btnInfo"><img src="icons/icon_info.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='ℹ️'" /></button>
<button class="drawer-btn" id="btnReset"><img src="icons/icon_reset.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='🔄'" /></button>
<button class="drawer-btn" id="btnPlugin"><img src="icons/icon_plugin.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='🔌'" /></button>
<button class="drawer-btn" id="btnDelete"><img src="icons/icon_delete.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='🗑️'" /></button>
<button class="drawer-btn" id="btnSettings"><img src="icons/icon_setting.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='⚙️'" /></button>
<button id="drawerClose">✕</button>
</div>
</div>
<div id="deleteTrash">
<div class="icon-wrapper" id="trashIconWrapper" style="width: 110px !important; height: 110px !important; margin: 0;">
<img src="icons/icon_delete.png" id="trashIconImg" class="icon-img" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='🗑️'" />
<div class="mark-overlay" id="trashMarkOverlay"></div>
</div>
</div>
<div class="modal-overlay" id="onboardingModal">
<div class="modal-content" style="text-align: center;">
<h3 id="onboardingTitle" style="color: #0071e3; margin-bottom: 12px;">Hướng dẫn</h3>
<p id="onboardingDesc" style="font-size: 14px; margin-bottom: 16px; color: var(--color-channel-name);">Vui lòng thêm ứng dụng vào Màn hình chính (Add to Home Screen) để sử dụng đầy đủ tính năng!</p>
<video src="images/huong_dan.mp4" playsinline muted autoplay loop style="width: 100%; border-radius: 12px; box-shadow: var(--shadow-box);"></video>
</div>
</div>
<div class="modal-overlay" id="infoModal">
<div class="modal-content">
<h3 id="infoTitle" style="color: #0071e3;">Thông tin</h3>
<div id="infoDetails" style="font-size: 13px; color: var(--color-channel-name); text-align: center; margin-bottom: 12px; display: none;"></div>
<div style="display: flex; flex-direction: column; gap: 6px; margin-top: 10px;">
<button class="close-modal" id="btnMail" style="margin-top:0; font-weight:normal; font-size:15px;"></button>
<button class="close-modal" id="btnFollow" style="margin-top:0; font-weight:normal; font-size:15px;"></button>
<button class="close-modal" id="btnInfoDetails" style="margin-top:0; font-weight:normal; font-size:15px;"></button>
</div>
<button class="close-modal lang-close" id="closeInfoModal" style="color: #0071e3; font-weight: 600;"></button>
</div>
</div>
<div class="modal-overlay" id="settingsModal">
<div class="modal-content">
<h3 id="txtSettingTitle">Cài đặt</h3>
<button class="close-modal" id="openEffectsBtn"></button>
<button class="close-modal" id="openBgEffectsBtn"></button>
<button class="close-modal" id="openDockBtn"></button>
<button class="close-modal" id="openLabelsBtn"></button>
<div style="display: flex; gap: 10px; margin-top: 14px;">
<button class="close-modal" id="exportBtn" style="margin-top: 0; background: rgba(0, 188, 212, 0.15); color: #00bcd4;"></button>
<button class="close-modal" id="importBtn" style="margin-top: 0; background: rgba(52, 199, 89, 0.15); color: #34c759;"></button>
</div>
<button class="close-modal lang-close" id="closeSettingsBtn"></button>
</div>
</div>
<div class="modal-overlay" id="bgEffectModal">
<div class="modal-content">
<h3 id="txtBgEffectTitle" style="color: #0071e3;">Hiệu ứng nền</h3>
<div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(150,150,150,0.2); padding-bottom: 12px;">
<label id="lblColorMain" style="margin:0;">Màu nền chính:</label>
<input type="color" id="colorMain" class="color-picker-input">
</div>
<div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(150,150,150,0.2); padding-bottom: 12px;">
<label id="lblColorContainer" style="margin:0;">Màu khung App:</label>
<input type="color" id="colorContainer" class="color-picker-input">
</div>
<div style="margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(150,150,150,0.2); padding-bottom: 14px;">
<label id="lblColorDock" style="margin:0;">Màu nền Dock:</label>
<input type="color" id="colorDock" class="color-picker-input">
</div>
<div style="margin-bottom: 14px;">
<label id="lblBgShadowDirection">Hướng đổ bóng nền:</label>
<div class="direction-container">
<button class="dir-btn bg-dir-btn" data-dir="left">◀︎</button>
<button class="dir-btn bg-dir-btn" data-dir="right">►</button>
<button class="dir-btn bg-dir-btn" data-dir="center">❖</button>
<button class="dir-btn bg-dir-btn" data-dir="top">▲</button>
<button class="dir-btn bg-dir-btn" data-dir="bottom">▼</button>
</div>
</div>
<div style="margin-bottom: 14px;"><label id="lblBgShadowBlur">Độ rõ (Blur):</label><input type="number" id="bgShadowBlurInput" class="input-num" style="text-align:center;" value="60" min="0" max="200"></div>
<div style="margin-bottom: 14px;"><label id="lblBgShadowOffset">Khoảng cách (Offset):</label><input type="number" id="bgShadowOffsetInput" class="input-num" style="text-align:center;" value="30" min="-200" max="200"></div>
<div style="margin-bottom: 14px;"><label id="lblBgShadowOpacity">Độ đậm nhạt (Opacity 0-100):</label><input type="number" id="bgShadowOpacityInput" class="input-num" style="text-align:center;" value="8" min="0" max="100"></div>
<button class="close-modal" id="saveBgEffectBtn" style="color: #00bcd4;"></button>
<button class="close-modal lang-cancel" id="closeBgEffectBtn" style="color: #ff3b30;"></button>
</div>
</div>
<div class="modal-overlay" id="labelsModal"><div class="modal-content"><h3 id="lblLabelsTitle">Cài đặt ứng dụng</h3><div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center;"><span id="txtHideLabels"></span> <label class="switch"><input type="radio" name="labelToggle" id="hideLabelsToggle"><span class="slider"></span></label></div><div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center;"><span id="txtShowLabels"></span> <label class="switch"><input type="radio" name="labelToggle" id="showLabelsToggle" checked><span class="slider"></span></label></div><div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(150,150,150,0.2); padding-top: 12px;"><span id="txtFastRename"></span> <label class="switch"><input type="checkbox" id="fastRenameToggle"><span class="slider"></span></label></div><div style="margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(150,150,150,0.2); padding-top: 12px;"><span id="txtHapticSound">Âm thanh chạm (Haptic)</span> <label class="switch"><input type="checkbox" id="hapticSoundToggle" checked><span class="slider"></span></label></div><button class="close-modal" id="saveLabelsBtn" style="color: #00bcd4;"></button><button class="close-modal lang-cancel" id="closeLabelsBtn" style="color: #ff3b30;"></button></div></div>
<div class="modal-overlay" id="effectModal"><div class="modal-content"><h3 id="txtEffectTitle" style="color: #20b2aa;">Đổ bóng icon</h3><div style="margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; background: var(--color-input-bg); padding: 10px; border-radius: 14px;"><span style="font-weight: 600;" id="txtVisionStroke"></span> <label class="switch" style="margin: 0;"><input type="checkbox" id="strokeToggle"><span class="slider"></span></label></div><div style="margin-bottom: 14px;"><label id="lblMarkStyle"></label><select id="markStyle" class="input-num"><option value="0">Liquid Glass</option><option value="1">Crystal Shine</option><option value="2">Holographic</option><option value="3">Matte Dark</option><option value="4">Classic Glossy</option></select></div><div style="margin-bottom: 14px;"><label id="lblShadowDirection"></label><div class="direction-container"><button class="dir-btn" data-dir="left">◀︎</button><button class="dir-btn" data-dir="right">►</button><button class="dir-btn" data-dir="center">❖</button><button class="dir-btn" data-dir="top">▲</button><button class="dir-btn" data-dir="bottom">▼</button></div></div><div style="margin-bottom: 14px;"><label id="lblShadowBlur"></label><input type="number" id="shadowBlurInput" class="input-num" style="text-align:center;" value="10" min="0" max="200"></div><div style="margin-bottom: 14px;"><label id="lblShadowOffset"></label><input type="number" id="shadowOffsetInput" class="input-num" style="text-align:center;" value="10" min="-100" max="100"></div><div style="margin-bottom: 14px;"><label id="lblShadowOpacity"></label><input type="number" id="shadowOpacityInput" class="input-num" style="text-align:center;" value="30" min="0" max="100"></div><div style="margin-bottom: 14px;"><label id="lblRadiusStyle"></label><select id="radiusStyle" class="input-num"><option value="0">Squircle (Chuẩn Apple)</option><option value="1">Tròn hoàn toàn</option><option value="2">Vuông nhẹ</option></select></div><button class="close-modal" id="saveEffectBtn" style="color: #00bcd4;"></button><button class="close-modal lang-cancel" id="closeEffectBtn" style="color: #ff3b30;"></button></div></div>
<div class="modal-overlay" id="dockModal"><div class="modal-content"><h3 id="txtDockTitle">Cài đặt Dock</h3><div style="margin-bottom: 14px; display: flex; align-items: center;"><label class="switch" style="margin-right: 12px;"><input type="radio" name="dockSel" id="dockGlassToggle"><span class="slider"></span></label><span id="txtDockGlass"></span></div><div style="margin-bottom: 14px; display: flex; align-items: center;"><label class="switch" style="margin-right: 12px;"><input type="radio" name="dockSel" id="dockWoodToggle"><span class="slider"></span></label><span id="txtDockWood"></span></div><div style="margin-bottom: 14px; display: flex; align-items: center;"><label class="switch" style="margin-right: 12px;"><input type="radio" name="dockSel" id="dockBlurToggle"><span class="slider"></span></label><span id="txtDockBlur"></span></div><div style="margin-bottom: 20px; display: flex; align-items: center;"><label class="switch" style="margin-right: 12px;"><input type="radio" name="dockSel" id="dockNoneToggle" checked><span class="slider"></span></label><span id="txtDockDisable"></span></div><button class="close-modal" id="saveDockBtn" style="color: #00bcd4; margin-top: 6px;"></button><button class="close-modal lang-cancel" id="closeDockBtn" style="color: #ff3b30; margin-top: 8px;"></button></div></div>
<div class="modal-overlay" id="addAppModal">
<div class="modal-content">
<h3 id="txtAddAppTitle">Thêm ứng dụng</h3>
<div style="margin-top: 8px; margin-bottom: 10px; display: flex; gap: 8px;">
<input type="text" id="appSearchInput" class="search-box" placeholder="🔍 Tìm kiếm..." style="flex:1;" />
<button id="storeToggleBtn" style="width: 55px; border-radius: 12px; border: none; background: #0071e3; color: white; font-weight: bold; font-size: 14px; cursor: pointer;">VN</button>
</div>
<div class="modal-list" id="modalList"></div>
<button class="close-modal" id="btnLoadMoreOnline" style="background: rgba(0, 122, 255, 0.15); color: #007AFF; margin-top: 8px; display: none;"></button>
<button class="close-modal" id="btnLoadMoreLocal" style="background: rgba(52, 199, 89, 0.15); color: #34c759; margin-top: 8px; display: none;"></button>
<button class="close-modal lang-close" id="closeModalBtn" style="margin-top: 8px;"></button>
</div>
</div>
<script>
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./sw.js').then(reg => reg?.update()); }
const ST_KEYS = { app: 'myAppList', name: 'myAppNames', dock: 'myDockApps', mark: 'effectMarkStyle', radius: 'effectRadiusStyle', dir: 'effectShadowDirection', blur: 'effectShadowBlur', offset: 'effectShadowOffset', opacity: 'effectShadowOpacity', dockStyle: 'dockStyle', stroke: 'effectStroke', hideLab: 'hideLabels', bgDir: 'bgShadowDirection', bgBlur: 'bgShadowBlur', bgOffset: 'bgShadowOffset', bgOpacity: 'bgShadowOpacity', custom: 'customApps', haptic: 'hapticSound', cMain: 'colorMainBg', cCont: 'colorContainer', cDock: 'colorDock' };
const FALLBACK_DB = {
"com.apple.Preferences": { "Name": "Settings", "icon": "systemapp/settings.png" },
"com.apple.mobilesafari": { "Name": "Safari", "icon": "systemapp/safari.png" },
"com.apple.mobileslideshow": { "Name": "Photos", "icon": "systemapp/photos.png" },
"com.apple.AppStore": { "Name": "App Store", "icon": "systemapp/appstore.png" },
"com.apple.camera": { "Name": "Camera", "icon": "systemapp/camera.png" }
};
const supportedLangs = ['ar', 'bn-BD', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-GB', 'en-US', 'es-ES', 'es-MX', 'fa-IR', 'fi-FI', 'fil-PH', 'fr-CA', 'fr-FR', 'hi-IN', 'hu-HU', 'id-ID', 'it-IT', 'ja', 'ko-KR', 'ms-MY', 'nb-NO', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru', 'sv-SE', 'sw-KE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'];
const AudioContext = window.AudioContext || window.webkitAudioContext;
let audioCtx = null;
function playHapticSound() {
if (localStorage.getItem(ST_KEYS.haptic) === 'false') return;
if (!audioCtx) audioCtx = new AudioContext();
if (audioCtx.state === 'suspended') audioCtx.resume();
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.connect(gain);
gain.connect(audioCtx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(800, audioCtx.currentTime);
osc.frequency.exponentialRampToValueAtTime(100, audioCtx.currentTime + 0.05);
gain.gain.setValueAtTime(0.1, audioCtx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.05);
osc.start();
osc.stop(audioCtx.currentTime + 0.05);
}
function createRipple(event, button) {
if(!button.classList.contains('ripple-wrapper')) button.classList.add('ripple-wrapper');
const circle = document.createElement("span");
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
const rect = button.getBoundingClientRect();
let x, y;
if(event.touches && event.touches.length > 0) {
x = event.touches[0].clientX - rect.left;
y = event.touches[0].clientY - rect.top;
} else {
x = event.clientX - rect.left;
y = event.clientY - rect.top;
}
circle.style.width = circle.style.height = `${diameter}px`;
circle.style.left = `${x - radius}px`;
circle.style.top = `${y - radius}px`;
circle.classList.add("ripple");
const existing = button.querySelector('.ripple');
if (existing) { existing.remove(); }
button.appendChild(circle);
setTimeout(() => { if(circle.parentNode) circle.remove(); }, 600);
}
document.body.addEventListener('touchstart', function(e) {
let target = e.target.closest('button, .app-item, .drawer-btn, .close-modal, .dir-btn');
if(target) {
playHapticSound();
if(target.tagName === 'BUTTON' || target.classList.contains('close-modal')) {
createRipple(e, target);
}
}
}, {passive: true});
let appDatabase = {}, socialData = { links: { email: '', social_follow: '', plugin_shortcut: '' } }, langData = {};
const basePath = '.';
const MAX_APPS = 12, MAX_DOCK_APPS = 3;
let isDeleteMode = false, isAddingDock = false, isFastRenameMode = false;
let searchTimeout = null, currentSearchLimit = 12, currentLocalLimit = 12, currentStore = 'vn', currentQuery = '';
const grid = document.getElementById('appGrid'), dockArea = document.getElementById('dockArea'), drawerWrapper = document.getElementById('drawerWrapper'), drawerContent = document.getElementById('drawerContent'), mainAppContainer = document.getElementById('mainAppContainer');
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
async function resolveLanguage() {
let userLang = navigator.language || navigator.languages?.[0] || 'vi-VN';
let exactLang = supportedLangs.find(l => l.toLowerCase() === userLang.toLowerCase()) ||
supportedLangs.find(l => l.startsWith(userLang.split('-')[0])) || 'vi-VN';
document.documentElement.dir = (exactLang === 'ar' || exactLang === 'fa-IR') ? 'rtl' : 'ltr';
try {
const enRes = await fetch(`${basePath}/Language/en-US.json`);
const enData = enRes.ok ? await enRes.json() : {};
let targetData = {};
if (exactLang !== 'en-US') {
const targetRes = await fetch(`${basePath}/Language/${exactLang}.json`);
if (targetRes.ok) targetData = await targetRes.json();
}
langData = mergeDeep(enData, targetData);
} catch (error) {
console.error("i18n Load Error:", error);
langData = {};
}
}
function mergeDeep(target, source) {
let output = Object.assign({}, target);
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!(key in target)) Object.assign(output, { [key]: source[key] });
else output[key] = mergeDeep(target[key], source[key]);
} else {
Object.assign(output, { [key]: source[key] });
}
});
}
return output;
}
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
Promise.all([
fetch(basePath + '/db.json').then(res => res.json()).catch(() => ({})),
fetch(basePath + '/system-app.json').then(res => res.json()).catch(() => ({})),
fetch(basePath + '/social.json').then(res => res.json()).catch(() => ({})),
resolveLanguage()
]).then(([db, sysApp, social]) => {
let customApps = getVals(ST_KEYS.custom, {});
appDatabase = { ...FALLBACK_DB, ...db, ...sysApp, ...customApps };
socialData = social?.links ? social : socialData;
applySystemTheme(darkModeMediaQuery.matches);
applyLanguage();
applyBackgroundEffects();
applyGlobalIconEffectsToSettingsBtn();
initUI();
});
function setSafeText(id, text) { const el = document.getElementById(id); if(el) el.innerText = text; }
function applyLanguage() {
setSafeText('infoTitle', langData?.info_popup?.title || 'Thông tin');
const infoDetails = document.getElementById('infoDetails');
if (infoDetails && langData?.info_popup?.details) {
infoDetails.innerHTML = langData.info_popup.details;
infoDetails.style.display = 'block';
}
setSafeText('onboardingTitle', langData?.onboarding?.title || 'Hướng dẫn');
setSafeText('onboardingDesc', langData?.onboarding?.desc || 'Vui lòng thêm ứng dụng vào Màn hình chính (Add to Home Screen) để sử dụng đầy đủ tính năng!');
setSafeText('btnMail', langData?.info_popup?.contact || 'Liên hệ');
setSafeText('btnFollow', langData?.info_popup?.follow || 'Theo dõi');
setSafeText('btnInfoDetails', langData?.info_popup?.info || 'Thông tin ứng dụng');
const btnInfoDetails = document.getElementById('btnInfoDetails');
if (btnInfoDetails) {
btnInfoDetails.onclick = () => {
alert(langData?.dock_info?.app_version || "Snowboard v1.0");
};
}
setSafeText('txtSettingTitle', langData?.effects?.settings?.title || 'Cài đặt');
setSafeText('openEffectsBtn', langData?.effects?.settings?.effects_menu || 'Cài đặt icon');
setSafeText('openBgEffectsBtn', langData?.effects?.settings?.bg_menu || 'Cài đặt nền');
setSafeText('txtBgEffectTitle', langData?.effects?.title_bg || 'Hiệu ứng nền');
setSafeText('lblColorMain', langData?.effects?.color_main || 'Màu nền chính:');
setSafeText('lblColorContainer', langData?.effects?.color_container || 'Màu khung App:');
setSafeText('lblColorDock', langData?.effects?.color_dock || 'Màu nền Dock:');
setSafeText('lblBgShadowDirection', langData?.effects?.shadow_direction_label || 'Hướng đổ bóng:');
setSafeText('lblBgShadowBlur', langData?.effects?.shadow_blur_label || 'Độ rõ:');
setSafeText('lblBgShadowOffset', langData?.effects?.shadow_offset_label || 'Khoảng cách:');
setSafeText('lblBgShadowOpacity', langData?.effects?.shadow_opacity_label || 'Đậm nhạt 0-100:');
setSafeText('saveBgEffectBtn', langData?.effects?.save || 'Lưu hiệu ứng');
setSafeText('openDockBtn', langData?.effects?.settings?.dock_menu || 'Cài đặt Dock');
setSafeText('openLabelsBtn', langData?.app_menu?.manage_apps || 'Cài đặt ứng dụng');
setSafeText('exportBtn', langData?.common?.export_config || '📤 Xuất Cấu Hình');
setSafeText('importBtn', langData?.common?.import_config || '📥 Nhập');
setSafeText('lblLabelsTitle', langData?.app_menu?.manage_apps || 'Cài đặt ứng dụng');
setSafeText('txtHideLabels', langData?.common?.hide_app_name || 'Ẩn tên ứng dụng');
setSafeText('txtShowLabels', langData?.common?.show_app_name || 'Hiện tên ứng dụng');
setSafeText('txtFastRename', langData?.common?.fast_rename_mode || 'Chế độ Đổi tên nhanh');
setSafeText('txtHapticSound', langData?.common?.haptic_sound || 'Âm thanh chạm (Haptic)');
setSafeText('saveLabelsBtn', langData?.button?.save_config || 'Lưu cấu hình');
setSafeText('txtEffectTitle', langData?.effects?.title || 'Đổ bóng icon');
setSafeText('txtVisionStroke', langData?.effects?.vision_stroke || 'Viền VisionOS');
setSafeText('lblMarkStyle', langData?.effects?.mark_label || 'Kiểu Mark');
setSafeText('lblShadowDirection', langData?.effects?.shadow_direction_label || 'Hướng đổ bóng:');
setSafeText('lblShadowBlur', langData?.effects?.shadow_blur_label || 'Độ rõ:');
setSafeText('lblShadowOffset', langData?.effects?.shadow_offset_label || 'Khoảng cách:');
setSafeText('lblShadowOpacity', langData?.effects?.shadow_opacity_label || 'Đậm nhạt 0-100:');
setSafeText('lblRadiusStyle', langData?.effects?.radius_label || 'Kiểu Bo góc Icon');
setSafeText('saveEffectBtn', langData?.effects?.save || 'Lưu hiệu ứng');
setSafeText('txtDockTitle', langData?.effects?.dock?.title || 'Cài đặt Dock');
setSafeText('txtDockGlass', langData?.effects?.dock?.glass || 'Kính trong suốt');
setSafeText('txtDockWood', langData?.effects?.dock?.wood || 'Gỗ (iOS 6)');
setSafeText('txtDockBlur', langData?.effects?.dock?.blur || 'Mờ Đen');
setSafeText('txtDockDisable', langData?.effects?.dock?.disable || 'Tắt Dock');
setSafeText('saveDockBtn', langData?.effects?.dock?.save || 'Lưu cấu hình');
document.querySelectorAll('.lang-close').forEach(el => el.innerText = langData?.button?.close || 'Đóng');
document.querySelectorAll('.lang-cancel').forEach(el => el.innerText = langData?.button?.cancel || 'Huỷ');
setSafeText('txtAddAppTitle', langData?.modal?.title_add_app || 'Thêm ứng dụng');
let loadMoreText = langData?.button?.load_more || 'Xem thêm';
setSafeText('btnLoadMoreOnline', loadMoreText);
setSafeText('btnLoadMoreLocal', loadMoreText);
if (document.getElementById('appSearchInput')) document.getElementById('appSearchInput').placeholder = langData?.modal?.search_placeholder || '🔍 Tìm kiếm...';
}
function applySystemTheme(isDark) {
let cMain = localStorage.getItem(ST_KEYS.cMain);
let cCont = localStorage.getItem(ST_KEYS.cCont);
let cDock = localStorage.getItem(ST_KEYS.cDock);
if (!cMain && !cCont && !cDock) {
document.documentElement.style.setProperty('--bg-main', isDark ? '#121212' : '#d4bbfc');
document.documentElement.style.setProperty('--bg-container', isDark ? 'rgba(30, 30, 30, 0.8)' : 'rgba(255, 255, 255, 0.8)');
document.documentElement.style.setProperty('--bg-dock', isDark ? 'rgba(30, 30, 30, 0.8)' : 'rgba(255, 255, 255, 0.8)');
if (document.getElementById('colorMain')) document.getElementById('colorMain').value = isDark ? '#121212' : '#d4bbfc';
if (document.getElementById('colorContainer')) document.getElementById('colorContainer').value = isDark ? '#1e1e1e' : '#ffffff';
if (document.getElementById('colorDock')) document.getElementById('colorDock').value = isDark ? '#1e1e1e' : '#ffffff';
}
}
darkModeMediaQuery.addEventListener('change', (e) => applySystemTheme(e.matches));
function cleanIconPath(iconPath) {
/* Sửa lỗi mất icon: Giữ nguyên protocol http:// hoặc https:// để không bị hỏng cấu trúc link iTunes */
if (!iconPath) return '';
let cleaned = iconPath.replace(/\\/g, '/');
if (cleaned.startsWith('http')) return cleaned;
return cleaned.replace(/\/\//g, '/');
}
function sanitizeIconUrl(rawUrl) {
if (!rawUrl) return '';
let url = cleanIconPath(rawUrl);
if (url.startsWith('http://')) {
url = url.replace('http://', 'https://');
}
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('/')) {
url = `${basePath}/${url}`;
}
return url;
}
function showToast(msg) { const t = document.getElementById('toast'); t.innerText = msg; t.classList.add('show'); setTimeout(() => t.classList.remove('show'), 2500); }
function getVals(key, def) { try { return JSON.parse(localStorage.getItem(key)) || def; } catch(e) { return def; } }
function setVals(key, val) { localStorage.setItem(key, JSON.stringify(val)); }
function getIconStyles() {
const mark = localStorage.getItem(ST_KEYS.mark) || '0';
const sDir = localStorage.getItem(ST_KEYS.dir) || 'bottom';
const radius = localStorage.getItem(ST_KEYS.radius) || '0';
const sBlur = localStorage.getItem(ST_KEYS.blur) || '10';
const sOff = localStorage.getItem(ST_KEYS.offset) || '10';
let opRaw = parseFloat(localStorage.getItem(ST_KEYS.opacity));
if (isNaN(opRaw)) opRaw = 30;
const sOp = Math.max(0, Math.min(100, opRaw)) / 100;
const stroke = localStorage.getItem(ST_KEYS.stroke) === 'true';
let radCSS = radius === '1' ? '50%' : radius === '2' ? '12px' : '16px';
let ox = sDir==='left'? -sOff : sDir==='right'? sOff : 0;
let oy = sDir==='top'? -sOff : sDir==='bottom'? sOff : 0;
let markBg = mark==='0'?'linear-gradient(135deg, rgba(255,255,255,0.25), rgba(255,255,255,0.02))':mark==='1'?'linear-gradient(135deg, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.3) 100%)':'rgba(0,0,0,0.1)';
return { radCSS, stroke, boxShadow: `${ox}px ${oy}px ${sBlur}px rgba(0,0,0,${sOp})`, markBg };
}
function applyGlobalIconEffectsToSettingsBtn() {
const styles = getIconStyles();
const btn = document.getElementById('settingsBtn');
const overlay = document.getElementById('settingMarkOverlay');
if(btn) {
btn.style.boxShadow = styles.boxShadow;
btn.classList.toggle('vision-stroke', styles.stroke);
}
if(overlay) { overlay.style.borderRadius = styles.radCSS; overlay.style.background = styles.markBg; }
const trashWrapper = document.getElementById('trashIconWrapper');
const trashOverlay = document.getElementById('trashMarkOverlay');
const trashImg = document.getElementById('trashIconImg');
if (trashWrapper) {
trashWrapper.style.borderRadius = styles.radCSS;
trashWrapper.style.boxShadow = styles.boxShadow;
trashWrapper.classList.toggle('vision-stroke', styles.stroke);
}
if (trashImg) {
trashImg.style.borderRadius = styles.radCSS;
}
if (trashOverlay) {
trashOverlay.style.borderRadius = styles.radCSS;
trashOverlay.style.background = styles.markBg;
}
}
function applyBackgroundEffects() {
const sDir = localStorage.getItem(ST_KEYS.bgDir) || 'bottom';
const sBlur = localStorage.getItem(ST_KEYS.bgBlur) || '60';
const sOff = localStorage.getItem(ST_KEYS.bgOffset) || '30';
let bgOpRaw = parseFloat(localStorage.getItem(ST_KEYS.bgOpacity));
if (isNaN(bgOpRaw)) bgOpRaw = 8;
const sOp = Math.max(0, Math.min(100, bgOpRaw)) / 100;
let ox = sDir==='left'? -sOff : sDir==='right'? sOff : 0;
let oy = sDir==='top'? -sOff : sDir==='bottom'? sOff : 0;
let shadowValue = `${ox}px ${oy}px ${sBlur}px rgba(0,0,0,${sOp})`;
if (mainAppContainer) mainAppContainer.style.boxShadow = shadowValue;
if(document.body.classList.contains('dock-active') && dockArea?.className.indexOf('none') === -1) {
dockArea.style.boxShadow = shadowValue;
}
}
function handleScreenResize() {
const isStandalone = window.navigator.standalone === true || window.matchMedia('(display-mode: standalone)').matches;
let paddingTopVal = isStandalone ? 'env(safe-area-inset-top, 44px)' : 'env(safe-area-inset-top, 50px)';
document.body.style.paddingTop = `calc(${paddingTopVal} + 10px)`;
if (mainAppContainer) {
mainAppContainer.style.maxHeight = `calc(${window.innerHeight}px - ${paddingTopVal} - env(safe-area-inset-bottom, 20px) - 90px)`;
}
}
window.addEventListener('resize', handleScreenResize);
window.addEventListener('orientationchange', handleScreenResize);
function closeDrawerSecure() {
drawerWrapper?.classList.remove('open');
}
function createAppItem(id, data, isDockItem = false) {
const div = document.createElement('div');
div.className = 'app-item';
div.dataset.id = id;
div.dataset.zone = isDockItem ? 'dock' : 'grid';
let dName = getVals(ST_KEYS.name, {})[id] || data?.Name || 'App';
let firstLetter = dName.charAt(0).toUpperCase();
let iconSrc = sanitizeIconUrl(data?.icon);
const styles = getIconStyles();
div.innerHTML = `
<div class="icon-wrapper ${styles.stroke ? 'vision-stroke' : ''}" style="border-radius:${styles.radCSS}; box-shadow:${styles.boxShadow};">
<span class="fallback-text" style="display: none;">${firstLetter}</span>
<img class="icon-img" style="border-radius:${styles.radCSS};"
src="${iconSrc}"
crossorigin="anonymous"
referrerpolicy="no-referrer"
loading="lazy"
onerror="this.style.display='none'; this.previousElementSibling.style.display='block';">
<div class="mark-overlay" style="border-radius:${styles.radCSS}; background:${styles.markBg}"></div>
</div>
${!isDockItem ? `<div class="app-info"><span class="app-name">${dName}</span></div>` : ''}
`;
div.onclick = () => {
if (isDeleteMode) return;
if (isFastRenameMode) renameApp(id, dName);
else window.location.href = "shortcuts://run-shortcut?name=Open App Launcher&input=text&text=" + encodeURIComponent(id);
};
let startX = 0, startY = 0, isDragging = false, moved = false;
div.addEventListener('touchstart', e => {
if (!isDeleteMode) return;
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
isDragging = true;
moved = false;
div.style.transition = 'none';
div.style.zIndex = '1000';
}, {passive: true});
div.addEventListener('touchmove', e => {
if (!isDragging || !isDeleteMode) return;
let currentX = e.touches[0].clientX;
let currentY = e.touches[0].clientY;
let diffX = currentX - startX;
let diffY = currentY - startY;
if (Math.abs(diffX) > 10 || Math.abs(diffY) > 10) {
moved = true;
div.style.transform = `translate(${diffX}px, ${diffY}px) scale(0.85)`;
div.style.opacity = '0.8';
}
}, {passive: true});
div.addEventListener('touchend', e => {
if (!isDragging || !isDeleteMode) return;
isDragging = false;
if (moved) {
const trash = document.getElementById('deleteTrash');
if (trash) {
const trashRect = trash.getBoundingClientRect();
const divRect = div.getBoundingClientRect();
const divCenterX = divRect.left + divRect.width / 2;
const divCenterY = divRect.top + divRect.height / 2;
if (divCenterX >= trashRect.left && divCenterX <= trashRect.right &&
divCenterY >= trashRect.top && divCenterY <= trashRect.bottom) {
let arr = getVals(isDockItem ? ST_KEYS.dock : ST_KEYS.app, []);
arr = arr.filter(itemId => itemId !== id);
setVals(isDockItem ? ST_KEYS.dock : ST_KEYS.app, arr);
renderGrid();
return;
}
}
}
div.style.transition = 'transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s';
div.style.transform = '';
div.style.opacity = '';
div.style.zIndex = '';
});
return div;
}
function renderDock() {
if(!dockArea) return;
const style = localStorage.getItem(ST_KEYS.dockStyle) || 'none';
dockArea.innerHTML = '';
if (style === 'none') {
document.body.classList.remove('dock-active'); dockArea.style.display = 'none'; closeDrawerSecure(); return;
}
document.body.classList.add('dock-active'); dockArea.style.display = 'flex';
dockArea.className = 'dock-container dock-style-' + style;
applyBackgroundEffects();
const fragment = document.createDocumentFragment();
let arr = getVals(ST_KEYS.dock, []).filter(id => Boolean(id) && appDatabase[id]).slice(0, MAX_DOCK_APPS);
arr.forEach(id => { fragment.appendChild(createAppItem(id, appDatabase[id], true)); });
if (arr.length < MAX_DOCK_APPS) {
const addBtn = document.createElement('div'); addBtn.className = 'app-item';
addBtn.innerHTML = `<div class="icon-wrapper" style="display:flex; align-items:center; justify-content:center; background:rgba(255,255,255,0.2); border-radius:16px;"><span style="font-size:28px; color:#fff;">+</span></div>`;
addBtn.onclick = () => { isAddingDock = true; currentLocalLimit = 12; renderModal(); };
fragment.appendChild(addBtn);
}
const setBtn = document.createElement('div'); setBtn.className = 'app-item'; setBtn.dataset.id = 'sys_settings';
const styles = getIconStyles();
setBtn.innerHTML = `
<div class="icon-wrapper ${styles.stroke ? 'vision-stroke' : ''}" style="border-radius:${styles.radCSS}; box-shadow:${styles.boxShadow}; background:transparent;" id="dockSetInner">
<div class="mark-overlay" style="border-radius:${styles.radCSS}; background:${styles.markBg}"></div>
<img src="icons/icon_setting.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML='⚙️'" style="width:100%; height:100%; object-fit:contain; position:relative; z-index:2; border-radius:${styles.radCSS};">
</div>
`;
setBtn.onclick = () => {
if(isDeleteMode) { toggleDeleteMode(); return; }
if(drawerWrapper?.classList.contains('open')) closeDrawerSecure();
else if(drawerWrapper && drawerContent) {
const rect = setBtn.getBoundingClientRect();
drawerWrapper.style.flexDirection = 'column-reverse';
drawerContent.style.flexDirection = 'column-reverse';
drawerWrapper.className = 'drawer-vertical';
drawerWrapper.style.bottom = (window.innerHeight - rect.top + 8) + 'px';
drawerWrapper.style.left = (rect.left + rect.width / 2) + 'px';
drawerWrapper.style.right = 'auto';
drawerWrapper.style.transformOrigin = 'bottom center';
drawerWrapper.style.transform = 'translateX(-50%) scale(0.5)';
void drawerWrapper.offsetWidth;
drawerWrapper.classList.add('open');
}
};
fragment.appendChild(setBtn);
dockArea.appendChild(fragment);
}
function renderGrid() {
if(!grid) return;
grid.innerHTML = '';
document.body.classList.toggle('hide-labels', localStorage.getItem(ST_KEYS.hideLab) === 'true');
let rawList = getVals(ST_KEYS.app, []).filter(Boolean);
let appList = rawList.filter(id => appDatabase[id]).slice(0, MAX_APPS);
const fragment = document.createDocumentFragment();
appList.forEach(id => { fragment.appendChild(createAppItem(id, appDatabase[id])); });
if (appList.length < MAX_APPS) {
let isEmpty = appList.length === 0;
let addLabel = isEmpty ? (langData?.button?.add_first_app || 'Thêm ứng dụng') : (langData?.button?.add || 'Thêm');
const addBtn = document.createElement('div'); addBtn.className = 'app-item';
addBtn.innerHTML = `
<div class="icon-wrapper ${isEmpty ? 'wiggle-effect' : ''}" style="display:flex; align-items:center; justify-content:center; border:2px dashed rgba(255,255,255,0.6); border-radius:16px; background:rgba(255,255,255,0.15);">
<span style="font-size:32px; color:#4f46e5; font-weight:300;">+</span>
</div>
<div class="app-info"><span class="app-name">${addLabel}</span></div>
`;
addBtn.onclick = () => { isAddingDock = false; currentLocalLimit = 12; renderModal(); };
fragment.appendChild(addBtn);
}
grid.appendChild(fragment);
renderDock();
}
function toggleDeleteMode() {
isDeleteMode = !isDeleteMode;
document.body.classList.toggle('delete-mode', isDeleteMode);
const delBtn = document.getElementById('btnDelete');
if (delBtn) {
delBtn.innerHTML = isDeleteMode ? '<span style="font-size:18px; color:#34c759;">✅</span>' : '<img src="icons/icon_delete.png" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="this.outerHTML=\'🗑️\'" />';
}
if (isDeleteMode) closeDrawerSecure();
renderGrid();
}
function searchOnlineApps(query) {
currentQuery = query;
const ml = document.getElementById('modalList');
const btnMoreOnline = document.getElementById('btnLoadMoreOnline');
const btnMoreLocal = document.getElementById('btnLoadMoreLocal');
if(btnMoreLocal) btnMoreLocal.style.display = 'none';
if (!query.trim()) { renderModalList(); return; }
if(currentSearchLimit === 12 && ml) ml.innerHTML = '<div style="grid-column: span 4; text-align: center; color: var(--color-channel-name); padding: 20px;">🔍 Đang tải dữ liệu...</div>';
if(btnMoreOnline) btnMoreOnline.style.display = 'none';
fetch(`https://itunes.apple.com/search?term=${encodeURIComponent(query)}&country=${currentStore}&entity=software&limit=${currentSearchLimit}`)
.then(res => res.json())
.then(data => {
if(!ml) return;
ml.innerHTML = '';
if (!data.results || data.results.length === 0) {
ml.innerHTML = '<div style="grid-column: span 4; text-align: center; color: #888; padding: 20px;">Không tìm thấy kết quả!</div>';
return;
}
const fragment = document.createDocumentFragment();
data.results.forEach(app => {
const bundleId = app.bundleId;
let appName = app.trackName.split(':')[0].split('-')[0].trim();
/* Sửa theo yêu cầu: Ưu tiên trả về icon 100x100 trước thay vì 512x512 */
const iconUrl = sanitizeIconUrl(app.artworkUrl100 || app.artworkUrl512);
appDatabase[bundleId] = { Name: appName, icon: iconUrl };
const item = document.createElement('div');
item.className = 'app-item';
let firstLetter = appName.charAt(0).toUpperCase();
item.innerHTML = `
<div class="icon-wrapper" style="width:64px; height:64px; border-radius:16px;">
<span class="fallback-text" style="color:#333; display:none;">${firstLetter}</span>
<img src="${iconUrl}" class="icon-img" crossorigin="anonymous" referrerpolicy="no-referrer" loading="lazy" onerror="this.style.display='none'; this.previousElementSibling.style.display='block';">
</div>
<span class="app-name" style="margin-top:4px;">${appName}</span>
`;
item.onclick = () => selectAppToAdd(bundleId);
fragment.appendChild(item);
});
ml.appendChild(fragment);
if(data.results.length === currentSearchLimit && btnMoreOnline) btnMoreOnline.style.display = 'block';
})
.catch(() => {
if (ml) ml.innerHTML = '<div style="grid-column: span 4; text-align: center; color: #ff3b30;">Lỗi kết nối App Store!</div>';
});
}
function selectAppToAdd(id) {
let arr = getVals(isAddingDock ? ST_KEYS.dock : ST_KEYS.app, []).filter(savedId => Boolean(savedId) && appDatabase[savedId]);
let maxLimitMsg = (langData?.modal?.max_apps_limit || "Bạn chỉ có thể thêm tối đa {max} ứng dụng.").replace('{max}', isAddingDock ? MAX_DOCK_APPS : MAX_APPS);
if(arr.length >= (isAddingDock ? MAX_DOCK_APPS : MAX_APPS)) return showToast(maxLimitMsg);
arr.push(id);
setVals(isAddingDock ? ST_KEYS.dock : ST_KEYS.app, arr);
let customApps = getVals(ST_KEYS.custom, {});
if (!customApps[id] && appDatabase[id]) {
customApps[id] = { Name: appDatabase[id].Name, icon: appDatabase[id].icon };
setVals(ST_KEYS.custom, customApps);
}
document.getElementById('addAppModal')?.classList.remove('active');
isAddingDock = false;
renderGrid();
}
function renderModalList() {
const ml = document.getElementById('modalList'); if(!ml) return;
ml.innerHTML = '';
if(document.getElementById('btnLoadMoreOnline')) document.getElementById('btnLoadMoreOnline').style.display = 'none';
const btnMoreLocal = document.getElementById('btnLoadMoreLocal');
const used = [...getVals(ST_KEYS.app, []), ...getVals(ST_KEYS.dock, [])];
const availableApps = Object.keys(appDatabase).filter(id => !used.includes(id));
const fragment = document.createDocumentFragment();
availableApps.slice(0, currentLocalLimit).forEach(id => {
const item = document.createElement('div'); item.className = 'app-item';
let dName = appDatabase[id].Name;
let cleanIcon = sanitizeIconUrl(appDatabase[id].icon);
let firstLetter = dName.charAt(0).toUpperCase();
item.innerHTML = `
<div class="icon-wrapper" style="width:64px; height:64px; border-radius:12px; box-shadow: var(--shadow-box);">
<span class="fallback-text" style="color:#333; display:none;">${firstLetter}</span>
<img src="${cleanIcon}" class="icon-img" crossorigin="anonymous" referrerpolicy="no-referrer" loading="lazy" onerror="this.style.display='none'; this.previousElementSibling.style.display='block';">
</div>
<span style="display:block; font-size:10px; margin-top:6px; text-align:center; width:100%; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; padding: 0 4px; box-sizing:border-box;">${dName}</span>
`;
item.onclick = () => selectAppToAdd(id);
fragment.appendChild(item);
});
ml.appendChild(fragment);
if(btnMoreLocal) {
if(availableApps.length > currentLocalLimit) btnMoreLocal.style.display = 'block';
else btnMoreLocal.style.display = 'none';
}
}
function renderModal() {
if(document.getElementById('appSearchInput')) document.getElementById('appSearchInput').value = '';
currentQuery = '';
currentLocalLimit = 12;
renderModalList();
document.getElementById('addAppModal')?.classList.add('active');
}
function renameApp(id, old) {
let msg = langData?.messages?.prompt_rename_app || 'Nhập tên mới:';
let n = prompt(msg, old);
if(n !== null) { let dict = getVals(ST_KEYS.name, {}); n.trim() ? dict[id] = n.trim() : delete dict[id]; setVals(ST_KEYS.name, dict); renderGrid(); }
}
function openSettings(modalId) { closeDrawerSecure(); document.getElementById(modalId)?.classList.add('active'); }
function initColors() {
let cMain = localStorage.getItem(ST_KEYS.cMain);
let cCont = localStorage.getItem(ST_KEYS.cCont);
let cDock = localStorage.getItem(ST_KEYS.cDock);
if (cMain) { document.documentElement.style.setProperty('--bg-main', cMain); if(document.getElementById('colorMain')) document.getElementById('colorMain').value = cMain; }
if (cCont) { document.documentElement.style.setProperty('--bg-container', cCont + 'cc'); if(document.getElementById('colorContainer')) document.getElementById('colorContainer').value = cCont; }
if (cDock) { document.documentElement.style.setProperty('--bg-dock', cDock + 'cc'); if(document.getElementById('colorDock')) document.getElementById('colorDock').value = cDock; }
}
function initUI() {
if(document.getElementById('hapticSoundToggle')) document.getElementById('hapticSoundToggle').checked = localStorage.getItem(ST_KEYS.haptic) !== 'false';
initColors();
handleScreenResize();
if(document.getElementById('bgShadowBlurInput')) document.getElementById('bgShadowBlurInput').value = localStorage.getItem(ST_KEYS.bgBlur) || '60';
if(document.getElementById('bgShadowOffsetInput')) document.getElementById('bgShadowOffsetInput').value = localStorage.getItem(ST_KEYS.bgOffset) || '30';
if(document.getElementById('bgShadowOpacityInput')) document.getElementById('bgShadowOpacityInput').value = localStorage.getItem(ST_KEYS.bgOpacity) || '8';
let savedBgDir = localStorage.getItem(ST_KEYS.bgDir) || 'bottom';
document.querySelectorAll('.bg-dir-btn').forEach(btn => {
if (btn.dataset.dir === savedBgDir) btn.classList.add('active');
else btn.classList.remove('active');
});
if(document.getElementById('colorMain')) document.getElementById('colorMain').addEventListener('input', e => document.documentElement.style.setProperty('--bg-main', e.target.value));
if(document.getElementById('colorContainer')) document.getElementById('colorContainer').addEventListener('input', e => document.documentElement.style.setProperty('--bg-container', e.target.value + 'cc'));
if(document.getElementById('colorDock')) document.getElementById('colorDock').addEventListener('input', e => document.documentElement.style.setProperty('--bg-dock', e.target.value + 'cc'));
const sBtn = document.getElementById('settingsBtn');
if(sBtn) sBtn.onclick = () => {
if (isDeleteMode) { toggleDeleteMode(); return; }
if(!drawerWrapper || !drawerContent) return;
drawerWrapper.style.flexDirection = 'row';
drawerContent.style.flexDirection = 'row';
drawerWrapper.className = 'drawer-horizontal';
drawerWrapper.style.bottom = 'calc(30px + env(safe-area-inset-bottom, 20px))';
drawerWrapper.style.right = '88px';
drawerWrapper.style.left = 'auto';
drawerWrapper.style.transformOrigin = 'right center';
drawerWrapper.style.transform = 'scale(0.5)';
void drawerWrapper.offsetWidth;
drawerWrapper.classList.add('open');
};
if(document.getElementById('drawerClose')) document.getElementById('drawerClose').onclick = closeDrawerSecure;
const trashEl = document.getElementById('deleteTrash');
if (trashEl) { trashEl.onclick = () => { if (isDeleteMode) toggleDeleteMode(); }; }
if(document.getElementById('appSearchInput')) document.getElementById('appSearchInput').oninput = (e) => {
clearTimeout(searchTimeout);
currentSearchLimit = 12;
searchTimeout = setTimeout(() => searchOnlineApps(e.target.value), 400);
};
if(document.getElementById('storeToggleBtn')) document.getElementById('storeToggleBtn').onclick = () => {
currentStore = currentStore === 'vn' ? 'us' : 'vn';
document.getElementById('storeToggleBtn').innerText = currentStore.toUpperCase();
currentSearchLimit = 12;
if(currentQuery) searchOnlineApps(currentQuery);
};
if(document.getElementById('btnLoadMoreOnline')) document.getElementById('btnLoadMoreOnline').onclick = () => { currentSearchLimit += 12; searchOnlineApps(currentQuery); };
if(document.getElementById('btnLoadMoreLocal')) document.getElementById('btnLoadMoreLocal').onclick = () => { currentLocalLimit += 12; renderModalList(); };
if(document.getElementById('btnDelete')) document.getElementById('btnDelete').onclick = () => { closeDrawerSecure(); toggleDeleteMode(); };
if(document.getElementById('btnReset')) document.getElementById('btnReset').onclick = () => {
if(confirm(langData?.messages?.reset_confirm || "Xoá sạch?")){ localStorage.clear(); location.reload(); }
};
if(document.getElementById('btnInfo')) document.getElementById('btnInfo').onclick = () => { closeDrawerSecure(); document.getElementById('infoModal')?.classList.add('active'); };
if(document.getElementById('btnMail')) document.getElementById('btnMail').onclick = () => window.open(socialData?.links?.email || 'mailto:', '_blank');
if(document.getElementById('btnFollow')) document.getElementById('btnFollow').onclick = () => window.open(socialData?.links?.social_follow || 'https://icloud.com', '_blank');
if(document.getElementById('btnPlugin')) document.getElementById('btnPlugin').onclick = () => { closeDrawerSecure(); window.open(socialData?.links?.plugin_shortcut || 'https://www.icloud.com/shortcuts', '_blank'); };
if(document.getElementById('btnSettings')) document.getElementById('btnSettings').onclick = () => openSettings('settingsModal');
if(document.getElementById('openEffectsBtn')) document.getElementById('openEffectsBtn').onclick = () => { document.getElementById('settingsModal')?.classList.remove('active'); openSettings('effectModal'); };
if(document.getElementById('openBgEffectsBtn')) document.getElementById('openBgEffectsBtn').onclick = () => { document.getElementById('settingsModal')?.classList.remove('active'); openSettings('bgEffectModal'); };
if(document.getElementById('openDockBtn')) document.getElementById('openDockBtn').onclick = () => { document.getElementById('settingsModal')?.classList.remove('active'); openSettings('dockModal'); };
if(document.getElementById('openLabelsBtn')) document.getElementById('openLabelsBtn').onclick = () => { document.getElementById('settingsModal')?.classList.remove('active'); openSettings('labelsModal'); };
document.querySelectorAll('.dir-btn:not(.bg-dir-btn)').forEach(btn => btn.onclick = () => { document.querySelectorAll('.dir-btn:not(.bg-dir-btn)').forEach(b => b.classList.remove('active')); btn.classList.add('active'); });
document.querySelectorAll('.bg-dir-btn').forEach(btn => btn.onclick = () => { document.querySelectorAll('.bg-dir-btn').forEach(b => b.classList.remove('active')); btn.classList.add('active'); });
if(document.getElementById('saveBgEffectBtn')) document.getElementById('saveBgEffectBtn').onclick = () => {
let activeDir = document.querySelector('.bg-dir-btn.active');
if(activeDir) localStorage.setItem(ST_KEYS.bgDir, activeDir.dataset.dir);
let b = parseFloat(document.getElementById('bgShadowBlurInput')?.value) || 0;
let o = parseFloat(document.getElementById('bgShadowOffsetInput')?.value) || 0;
let op = parseFloat(document.getElementById('bgShadowOpacityInput')?.value);
if(isNaN(op)) op = 8;
localStorage.setItem(ST_KEYS.bgBlur, Math.max(0, b));
localStorage.setItem(ST_KEYS.bgOffset, o);
localStorage.setItem(ST_KEYS.bgOpacity, Math.max(0, Math.min(100, op)));
let cMain = document.getElementById('colorMain')?.value;
if(cMain) {
localStorage.setItem(ST_KEYS.cMain, cMain);
document.documentElement.style.setProperty('--bg-main', cMain);
}
if(document.getElementById('colorContainer')) localStorage.setItem(ST_KEYS.cCont, document.getElementById('colorContainer').value);
if(document.getElementById('colorDock')) localStorage.setItem(ST_KEYS.cDock, document.getElementById('colorDock').value);
document.getElementById('bgEffectModal')?.classList.remove('active');
applyBackgroundEffects(); showToast(langData?.messages?.toast_saved || "Đã lưu thành công");
};
if(document.getElementById('saveEffectBtn')) document.getElementById('saveEffectBtn').onclick = () => {
if(document.getElementById('markStyle')) localStorage.setItem(ST_KEYS.mark, document.getElementById('markStyle').value);
if(document.getElementById('radiusStyle')) localStorage.setItem(ST_KEYS.radius, document.getElementById('radiusStyle').value);
if(document.getElementById('strokeToggle')) localStorage.setItem(ST_KEYS.stroke, document.getElementById('strokeToggle').checked);
let activeDir = document.querySelector('.dir-btn:not(.bg-dir-btn).active');
if(activeDir) localStorage.setItem(ST_KEYS.dir, activeDir.dataset.dir);
let b = parseFloat(document.getElementById('shadowBlurInput')?.value) || 0;
let o = parseFloat(document.getElementById('shadowOffsetInput')?.value) || 0;
let op = parseFloat(document.getElementById('shadowOpacityInput')?.value);
if(isNaN(op)) op = 30;
localStorage.setItem(ST_KEYS.blur, Math.max(0, b));
localStorage.setItem(ST_KEYS.offset, o);
localStorage.setItem(ST_KEYS.opacity, Math.max(0, Math.min(100, op)));
document.getElementById('effectModal')?.classList.remove('active');
applyGlobalIconEffectsToSettingsBtn(); renderGrid(); showToast(langData?.messages?.toast_saved || "Đã lưu thành công");
};
if(document.getElementById('saveDockBtn')) document.getElementById('saveDockBtn').onclick = () => {
let style = 'none';
if(document.getElementById('dockGlassToggle')?.checked) style = 'glass';
else if(document.getElementById('dockWoodToggle')?.checked) style = 'wood';
else if(document.getElementById('dockBlurToggle')?.checked) style = 'blur';
localStorage.setItem(ST_KEYS.dockStyle, style);
document.getElementById('dockModal')?.classList.remove('active'); renderGrid(); showToast(langData?.messages?.toast_saved || "Đã lưu thành công");
};
if(document.getElementById('saveLabelsBtn')) document.getElementById('saveLabelsBtn').onclick = () => {
if(document.getElementById('hideLabelsToggle')) localStorage.setItem(ST_KEYS.hideLab, document.getElementById('hideLabelsToggle').checked);
if(document.getElementById('hapticSoundToggle')) localStorage.setItem(ST_KEYS.haptic, document.getElementById('hapticSoundToggle').checked);
if(document.getElementById('fastRenameToggle')) isFastRenameMode = document.getElementById('fastRenameToggle').checked;
document.getElementById('labelsModal')?.classList.remove('active'); renderGrid(); showToast(langData?.messages?.toast_saved || "Đã lưu thành công");
};
document.querySelectorAll('.close-modal').forEach(btn => {
if(btn.id.includes('close') || btn.id.includes('Close')) { btn.onclick = (e) => e.target.closest('.modal-overlay')?.classList.remove('active'); }
});
if(document.getElementById('exportBtn')) document.getElementById('exportBtn').onclick = () => {
const data = { apps: getVals(ST_KEYS.app,[]), dock: getVals(ST_KEYS.dock,[]), names: getVals(ST_KEYS.name,{}), eff: { mark: localStorage.getItem(ST_KEYS.mark), rad: localStorage.getItem(ST_KEYS.radius), dir: localStorage.getItem(ST_KEYS.dir), blur: localStorage.getItem(ST_KEYS.blur), off: localStorage.getItem(ST_KEYS.offset), op: localStorage.getItem(ST_KEYS.opacity), dk: localStorage.getItem(ST_KEYS.dockStyle), st: localStorage.getItem(ST_KEYS.stroke), hl: localStorage.getItem(ST_KEYS.hideLab), bgDir: localStorage.getItem(ST_KEYS.bgDir), bgBlur: localStorage.getItem(ST_KEYS.bgBlur), bgOff: localStorage.getItem(ST_KEYS.bgOff), bgOp: localStorage.getItem(ST_KEYS.bgOpacity), hp: localStorage.getItem(ST_KEYS.haptic), cMain: localStorage.getItem(ST_KEYS.cMain), cCont: localStorage.getItem(ST_KEYS.cCont), cDock: localStorage.getItem(ST_KEYS.cDock) }};
navigator.clipboard.writeText(btoa(encodeURIComponent(JSON.stringify(data)))).then(() => { document.getElementById('settingsModal')?.classList.remove('active'); showToast(langData?.messages?.toast_copied || "Đã sao chép"); });
};
if(document.getElementById('importBtn')) document.getElementById('importBtn').onclick = () => {
let code = prompt(langData?.messages?.prompt_import_code || "Dán mã cấu hình của bạn vào đây:"); if(!code) return;
try {
let d = JSON.parse(decodeURIComponent(atob(code)));
if(d.apps) setVals(ST_KEYS.app, d.apps); if(d.dock) setVals(ST_KEYS.dock, d.dock); if(d.names) setVals(ST_KEYS.name, d.names);
if(d.eff) { localStorage.setItem(ST_KEYS.mark, d.eff.mark||'0'); localStorage.setItem(ST_KEYS.radius, d.eff.rad||'0'); localStorage.setItem(ST_KEYS.dir, d.eff.dir||'bottom'); localStorage.setItem(ST_KEYS.blur, d.eff.blur||'10'); localStorage.setItem(ST_KEYS.offset, d.eff.off||'10'); localStorage.setItem(ST_KEYS.opacity, d.eff.op||'30'); localStorage.setItem(ST_KEYS.dockStyle, d.eff.dk||'none'); localStorage.setItem(ST_KEYS.stroke, d.eff.st||'false'); localStorage.setItem(ST_KEYS.hideLab, d.eff.hl||'false'); localStorage.setItem(ST_KEYS.bgDir, d.eff.bgDir||'bottom'); localStorage.setItem(ST_KEYS.bgBlur, d.eff.bgBlur||'60'); localStorage.setItem(ST_KEYS.bgOffset, d.eff.bgOff||'30'); localStorage.setItem(ST_KEYS.bgOpacity, d.eff.bgOp||'8'); localStorage.setItem(ST_KEYS.haptic, d.eff.hp||'true'); localStorage.setItem(ST_KEYS.cMain, d.eff.cMain||'#d4bbfc'); localStorage.setItem(ST_KEYS.cCont, d.eff.cCont||'#ffffff'); localStorage.setItem(ST_KEYS.cDock, d.eff.cDock||'#ffffff'); }
document.getElementById('settingsModal')?.classList.remove('active'); showToast(langData?.messages?.toast_success || "Thành công!"); setTimeout(() => location.reload(), 1000);
} catch(e) { alert(langData?.messages?.toast_error || "Có lỗi xảy ra!"); }
};
renderGrid();
const isStandalone = window.navigator.standalone === true || window.matchMedia('(display-mode: standalone)').matches;
if (!isStandalone) {
setTimeout(() => {
document.getElementById('onboardingModal')?.classList.add('active');
}, 15000);
}
}
</script>
</body>
</html>