-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent-script.js
More file actions
3337 lines (2969 loc) · 110 KB
/
Copy pathcontent-script.js
File metadata and controls
3337 lines (2969 loc) · 110 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
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
(() => {
if (window.top !== window) return;
const ORIGIN = location.origin;
const WEB_VERSION_ALLOWED_ORIGINS = new Set([
'https://fn.mods.aurysian.top'
]);
const WEB_VERSION_REQUEST_TYPE = 'FNOS_UI_MODS_REQUEST_VERSION';
const WEB_VERSION_RESPONSE_TYPE = 'FNOS_UI_MODS_VERSION_RESPONSE';
const BASIC_STYLE_ID = 'fnos-ui-mods-basic-style';
const LOCKSCREEN_STYLE_ID = 'fnos-ui-mods-lockscreen-style';
const TITLEBAR_STYLE_ID = 'fnos-ui-mods-titlebar-style';
const LAUNCHPAD_STYLE_ID = 'fnos-ui-mods-launchpad-style';
const SCRIPT_ID = 'fnos-ui-mods-script';
const THEME_STYLE_ID = 'fnos-ui-mods-theme-style';
const FONT_STYLE_ID = 'fnos-ui-mods-font-style';
const CUSTOM_CSS_STYLE_ID = 'fnos-ui-mods-custom-css-style';
const CUSTOM_JS_SCRIPT_ID = 'fnos-ui-mods-custom-js-script';
const DESKTOP_ICON_LAYOUT_STYLE_ID = 'fnos-ui-mods-desktop-icon-layout-style';
const DESKTOP_ICON_MOD_STYLE_ID = 'fnos-ui-mods-desktop-icon-mod-style';
const LAUNCHPAD_ICON_SCALE_STYLE_ID = 'fnos-ui-mods-launchpad-icon-scale-style';
const WINDOW_ANIMATION_BLUR_DISABLED_CLASS =
'fnos-window-animation-blur-disabled';
const LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR = 'data-fnos-original-src';
const LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR = 'data-fnos-original-data-src';
const APP_CENTER_DETAIL_OVERLAY_CLASS_TOKENS = [
'absolute',
'inset-0',
'flex',
'flex-col',
'z-10'
];
const APP_CENTER_ROUTE_WINDOW_ACTIVE_CLASS = 'fnos-app-center-route-detail-open';
const APP_CENTER_ROUTE_HOME_CLASS = 'fnos-app-center-route-home';
const APP_CENTER_ROUTE_DETAIL_CLASS = 'fnos-app-center-route-detail';
const APP_CENTER_ROUTE_ACTIVE_CLASS = 'fnos-app-center-route-active';
const APP_CENTER_ROUTE_LEAVING_CLASS = 'fnos-app-center-route-leaving';
const APP_CENTER_ROUTE_PREPARED_ATTR = 'data-fnos-route-prepared';
const APP_CENTER_ROUTE_BACK_BYPASS_ATTR = 'data-fnos-route-bypass';
const APP_CENTER_ROUTE_PENDING_ATTR = 'data-fnos-route-pending';
const APP_CENTER_GLOBAL_BACK_CLASS = 'fnos-app-center-global-back';
const THEME_DEFAULT_BRAND = '#0066ff';
const BRAND_LIGHTNESS_MIN = 0.3;
const BRAND_LIGHTNESS_MAX = 0.7;
const DESKTOP_ICON_LAYOUT_MODE_DEFAULT = 'adaptive';
const DESKTOP_ICON_PER_COLUMN_DEFAULT = 8;
const DESKTOP_ICON_PER_COLUMN_MIN = 4;
const DESKTOP_ICON_PER_COLUMN_MAX = 16;
const FONT_LOCAL_DATA_KEY = 'customFontDataUrl';
const FONT_LOCAL_NAME_KEY = 'customFontFileName';
const FONT_LOCAL_FORMAT_KEY = 'customFontFormat';
const LOGIN_WALLPAPER_LOCAL_DATA_KEY = 'loginWallpaperDataUrl';
const LOGIN_WALLPAPER_LOCAL_NAME_KEY = 'loginWallpaperFileName';
const LOGIN_WALLPAPER_GRADIENT =
'linear-gradient(120deg, rgba(8, 14, 28, 0.35), rgba(8, 14, 28, 0.18))';
const LOCKSCREEN_TEXT_AVATAR_CLASS = 'fnos-lockscreen-text-avatar';
const LOCKSCREEN_TEXT_AVATAR_BOUND_ATTR = 'data-fnos-avatar-bound';
const LOCKSCREEN_DEFAULT_USERNAME_MAX = 80;
const LOCKSCREEN_DEFAULT_USERNAME_ROW_CLASS =
'fnos-lockscreen-default-username-row';
const LOCKSCREEN_DEFAULT_USERNAME_TEXT_CLASS =
'fnos-lockscreen-default-username-text';
const LOCKSCREEN_SWITCH_ACCOUNT_BUTTON_CLASS =
'fnos-lockscreen-switch-account';
const LOCKSCREEN_SWITCH_ACCOUNT_ICON_CLASS =
'fnos-lockscreen-switch-account-icon';
const LOCKSCREEN_SWITCH_ACCOUNT_LABEL_CLASS =
'fnos-lockscreen-switch-account-label';
const LOCKSCREEN_DEFAULT_USERNAME_FIELD_HIDDEN_ATTR =
'data-fnos-default-username-hidden';
const LOCKSCREEN_DEFAULT_USERNAME_FIELD_DISPLAY_ATTR =
'data-fnos-default-username-inline-display';
const LOCKSCREEN_DEFAULT_USERNAME_SWITCH_BOUND_ATTR =
'data-fnos-switch-account-bound';
const LOCKSCREEN_MANUAL_ACCOUNT_MODE_ATTR = 'data-fnos-manual-account-mode';
const LOCKSCREEN_PINYIN_BOUNDARIES = [
'\u963f',
'\u516b',
'\u5693',
'\u642d',
'\u86fe',
'\u53d1',
'\u65ee',
'\u54c8',
'\u51fb',
'\u5580',
'\u5783',
'\u5988',
'\u62ff',
'\u5662',
'\u556a',
'\u671f',
'\u7136',
'\u6492',
'\u584c',
'\u6316',
'\u6614',
'\u538b',
'\u531d'
];
const LOCKSCREEN_PINYIN_INITIALS = 'ABCDEFGHJKLMNOPQRSTWXYZ';
const LOCKSCREEN_PINYIN_COLLATOR = new Intl.Collator(
'zh-Hans-u-co-pinyin',
{ sensitivity: 'base', usage: 'sort' }
);
const CUSTOM_CSS_LOCAL_KEY = 'customCssCode';
const CUSTOM_JS_LOCAL_KEY = 'customJsCode';
const FONT_DEFAULT_FACE_NAME = 'FnOSCustomFont';
const FONT_DEFAULT_SETTINGS = {
enabled: false,
family: '',
monospaceFamily: '',
weight: '',
featureSettings: '',
faceName: FONT_DEFAULT_FACE_NAME,
url: ''
};
const CUSTOM_CODE_DEFAULT_SETTINGS = {
enabled: false,
css: '',
js: ''
};
const LAUNCHPAD_DESKTOP_ICON_CARD_CLASS_TOKENS = [
'flex',
'h-[124px]',
'w-[130px]',
'cursor-pointer',
'flex-col',
'items-center',
'justify-center',
'gap-4'
];
const LAUNCHPAD_PANEL_ICON_CARD_CLASS_TOKENS = [
'flex',
'flex-col',
'justify-center',
'items-center',
'w-[172px]',
'h-[156px]',
'cursor-pointer'
];
const LAUNCHPAD_ICON_BOX_CLASS_TOKENS = [
'box-border',
'size-[80px]',
'p-[15%]'
];
const LAUNCHPAD_ICON_BASE_CLASS = 'fnos-launchpad-icon-box--processed';
const LAUNCHPAD_ICON_BOX_CLASS = 'fnos-launchpad-icon-box--scaled';
const LAUNCHPAD_ICON_MASK_ONLY_CLASS = 'fnos-launchpad-icon-box--mask-only';
const LAUNCHPAD_ICON_BLUR_CLONE_CLASS = 'fnos-launchpad-icon-blur-clone';
const LAUNCHPAD_ICON_BLUR_CLONE_IMG_CLASS = 'fnos-launchpad-icon-blur-clone-img';
const LAUNCHPAD_ICON_SRC_PREFIXES = [
'/static/app/icons/',
'/app-center-static/serviceicon/'
];
const DESKTOP_ICON_GRID_SELECTOR =
'.box-border.flex.size-full.flex-col.flex-wrap.place-content-start.items-start.py-base-loose:has(.flex.h-\\[124px\\].w-\\[130px\\].cursor-pointer.flex-col.items-center.justify-center.gap-4)';
const DESKTOP_ICON_CARD_SELECTOR =
'.flex.h-\\[124px\\].w-\\[130px\\].cursor-pointer.flex-col.items-center.justify-center.gap-4';
let currentBrandColor = THEME_DEFAULT_BRAND;
let currentBasePresetEnabled = true;
let currentWindowAnimationBlurEnabled = true;
let currentTitlebarStyle = 'windows';
let currentLaunchpadStyle = 'classic';
let currentDesktopIconLayoutEnabled = true;
let currentDesktopIconLayoutMode = DESKTOP_ICON_LAYOUT_MODE_DEFAULT;
let currentDesktopIconPerColumn = DESKTOP_ICON_PER_COLUMN_DEFAULT;
let currentFontSettings = { ...FONT_DEFAULT_SETTINGS };
let currentCustomCodeSettings = { ...CUSTOM_CODE_DEFAULT_SETTINGS };
let currentLaunchpadIconScaleEnabled = false;
let currentLaunchpadIconScaleSelectedKeys = [];
let currentLaunchpadIconMaskOnlyKeys = [];
let currentLaunchpadIconRedrawKeys = [];
let currentLaunchpadIconRedrawMap = {};
let currentUploadedFontDataUrl = '';
let currentUploadedFontFileName = '';
let currentUploadedFontFormat = '';
let currentLoginWallpaperDataUrl = '';
let currentLoginWallpaperFileName = '';
let currentLockscreenDefaultUsername = '';
let currentLoginWallpaperResolvedDataUrl = '';
let currentLoginWallpaperObjectUrl = '';
let currentLaunchpadAppItems = [];
let launchpadIconObserver = null;
let launchpadIconRefreshRafId = 0;
let appCenterMetaObserver = null;
let appCenterMetaRefreshRafId = 0;
let appCenterRouteRefreshRafId = 0;
let lockscreenStyleObserver = null;
let lockscreenStyleRafId = 0;
let lockscreenStylePollTimer = 0;
let hasLockscreenLifecycleHooks = false;
let hasAppCenterRouteClickHook = false;
let lastAppliedCustomJs = '';
let isInjectionActive = false;
let extensionContextInvalidated = false;
const appCenterRoutePendingTimers = new WeakMap();
const appCenterRouteHomeInlineSnapshot = new WeakMap();
const appCenterRouteHomeRestoreTimers = new WeakMap();
const TITLEBAR_STYLES = {
windows: 'windows_titlebar_mod.css',
mac: 'mac_titlebar_mod.css'
};
const LAUNCHPAD_STYLES = {
classic: 'classic_launchpad_mod.css',
spotlight: 'spotlight_launchpad_mod.css'
};
const APP_CENTER_META_TYPE_MAP = {
开发者: 'developer',
发布者: 'publisher',
下载数: 'downloads',
大小: 'size',
安装位置: 'install-location',
当前版本: 'version'
};
function normalizeTitlebarStyle(style) {
return style === 'mac' ? 'mac' : 'windows';
}
function normalizeLaunchpadStyle(style) {
return style === 'spotlight' ? 'spotlight' : 'classic';
}
function isContextInvalidatedError(error) {
const message = error?.message;
return typeof message === 'string' && message.includes('Extension context invalidated');
}
function markContextInvalidated(error) {
if (!isContextInvalidatedError(error)) return;
extensionContextInvalidated = true;
stopLaunchpadIconObserver();
}
function safeRuntimeGetURL(path) {
if (extensionContextInvalidated) return '';
if (typeof path !== 'string' || !path) return '';
try {
if (!chrome?.runtime?.id) return '';
return chrome.runtime.getURL(path);
} catch (error) {
markContextInvalidated(error);
return '';
}
}
function getManifestVersion() {
if (extensionContextInvalidated) return '';
try {
return String(chrome.runtime.getManifest()?.version || '');
} catch (error) {
markContextInvalidated(error);
return '';
}
}
function handleWebsiteVersionRequest(event) {
if (!WEB_VERSION_ALLOWED_ORIGINS.has(ORIGIN)) return;
if (event.source !== window) return;
if (event.origin !== ORIGIN) return;
const payload =
event.data && typeof event.data === 'object' && !Array.isArray(event.data)
? event.data
: null;
if (!payload || payload.type !== WEB_VERSION_REQUEST_TYPE) return;
const requestId = typeof payload.requestId === 'string' ? payload.requestId : '';
const version = getManifestVersion();
if (!version) return;
window.postMessage(
{
type: WEB_VERSION_RESPONSE_TYPE,
requestId,
version
},
ORIGIN
);
}
function ensureLaunchpadIconScaleStyle() {
let style = document.getElementById(LAUNCHPAD_ICON_SCALE_STYLE_ID);
if (!style) {
style = document.createElement('style');
style.id = LAUNCHPAD_ICON_SCALE_STYLE_ID;
(document.head || document.documentElement).appendChild(style);
}
const nextCss = [
`.${LAUNCHPAD_ICON_BASE_CLASS} {`,
' position: relative;',
' overflow: visible;',
'}',
`.${LAUNCHPAD_ICON_BASE_CLASS} .semi-image {`,
' transform-origin: center center;',
' position: relative;',
' z-index: 1;',
'}',
`.${LAUNCHPAD_ICON_BLUR_CLONE_CLASS} {`,
' position: absolute;',
' inset: 0;',
' z-index: 0;',
' pointer-events: none;',
' transform: scale(1.25);',
' transform-origin: center center;',
' filter: blur(8px) saturate(115%);',
' opacity: 0.42;',
'}',
`.${LAUNCHPAD_ICON_BLUR_CLONE_CLASS} .${LAUNCHPAD_ICON_BLUR_CLONE_IMG_CLASS} {`,
' width: 100%;',
' height: 100%;',
' object-fit: contain;',
' display: block;',
'}',
`.${LAUNCHPAD_ICON_BOX_CLASS} .semi-image {`,
' transform: scale(0.75) !important;',
'}',
`.${LAUNCHPAD_ICON_MASK_ONLY_CLASS}:not(.${LAUNCHPAD_ICON_BOX_CLASS}) .semi-image {`,
' transform: none !important;',
'}'
].join('\n');
if (style.textContent !== nextCss) {
style.textContent = nextCss;
}
}
function hasAllClasses(el, classTokens) {
if (!(el instanceof HTMLElement)) return false;
return classTokens.every((token) => el.classList.contains(token));
}
function normalizeLaunchpadKeyList(value, maxLength = 320) {
if (!Array.isArray(value)) return [];
const unique = new Set();
value.forEach((item) => {
if (typeof item !== 'string') return;
const key = item.trim().slice(0, maxLength);
if (!key) return;
unique.add(key);
});
return Array.from(unique);
}
function normalizeLaunchpadRedrawMap(value, maxLength = 320) {
if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
const map = {};
Object.entries(value).forEach(([rawKey, rawPath]) => {
if (typeof rawKey !== 'string' || typeof rawPath !== 'string') return;
const key = rawKey.trim().slice(0, maxLength);
const path = rawPath.trim();
if (!key) return;
if (!/^prefect_icon\/[a-z0-9-]+\.png$/i.test(path)) return;
map[key] = path;
});
return map;
}
function normalizeLaunchpadIconKey(rawValue) {
if (typeof rawValue !== 'string') return '';
const raw = rawValue.trim();
if (!raw) return '';
try {
const url = new URL(raw, window.location.origin);
return url.pathname.toLowerCase();
} catch {
return raw.split('?')[0].toLowerCase();
}
}
function isLaunchpadIconKey(key) {
if (typeof key !== 'string' || !key) return false;
return LAUNCHPAD_ICON_SRC_PREFIXES.some((prefix) => key.includes(prefix));
}
function isLaunchpadDesktopIconCard(el) {
return hasAllClasses(el, LAUNCHPAD_DESKTOP_ICON_CARD_CLASS_TOKENS);
}
function isLaunchpadPanelIconCard(el) {
return hasAllClasses(el, LAUNCHPAD_PANEL_ICON_CARD_CLASS_TOKENS);
}
function collectLaunchpadIconCards() {
const cards = [];
document
.querySelectorAll('div.cursor-pointer')
.forEach((candidateEl) => {
if (!(candidateEl instanceof HTMLElement)) return;
if (
!isLaunchpadDesktopIconCard(candidateEl) &&
!isLaunchpadPanelIconCard(candidateEl)
) {
return;
}
const key = extractLaunchpadAppKey(candidateEl);
if (!key) return;
cards.push(candidateEl);
});
return cards;
}
function findLaunchpadIconBox(cardEl) {
if (!(cardEl instanceof HTMLElement)) return null;
const candidates = Array.from(cardEl.querySelectorAll('div.box-border'));
for (const candidate of candidates) {
if (!(candidate instanceof HTMLElement)) continue;
if (!hasAllClasses(candidate, LAUNCHPAD_ICON_BOX_CLASS_TOKENS)) continue;
if (!candidate.querySelector('.semi-image')) continue;
return candidate;
}
return null;
}
function extractLaunchpadAppTitle(cardEl) {
if (!(cardEl instanceof HTMLElement)) return '';
const titleNodes = Array.from(cardEl.querySelectorAll('.line-clamp-1[title], div[title], span[title]'));
for (const node of titleNodes) {
if (!(node instanceof HTMLElement)) continue;
const title = (node.getAttribute('title') || '').trim();
if (title) return title;
}
const titleText = cardEl
.querySelector('.py-base-loose')
?.textContent
?.trim();
return typeof titleText === 'string' ? titleText : '';
}
function extractLaunchpadAppKey(cardEl) {
if (!(cardEl instanceof HTMLElement)) return '';
const imageEl = getLaunchpadIconImageElement(cardEl);
if (!(imageEl instanceof HTMLImageElement)) return '';
const rawDataSrc =
imageEl.getAttribute(LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR) ||
imageEl.getAttribute('data-src') ||
'';
const rawSrc =
imageEl.getAttribute(LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR) ||
imageEl.getAttribute('src') ||
'';
const keyFromDataSrc = normalizeLaunchpadIconKey(rawDataSrc);
const keyFromSrc = normalizeLaunchpadIconKey(rawSrc);
const key = keyFromDataSrc || keyFromSrc;
if (!isLaunchpadIconKey(key)) return '';
return key;
}
function getLaunchpadIconImageElement(cardEl) {
if (!(cardEl instanceof HTMLElement)) return null;
const imageEl = cardEl.querySelector('.semi-image img');
if (!(imageEl instanceof HTMLImageElement)) return null;
return imageEl;
}
function getLaunchpadIconImageSource(cardEl) {
if (!(cardEl instanceof HTMLElement)) return '';
const imageEl = getLaunchpadIconImageElement(cardEl);
if (!(imageEl instanceof HTMLImageElement)) return '';
const currentSrc = imageEl.currentSrc || '';
if (typeof currentSrc === 'string' && currentSrc.trim()) return currentSrc.trim();
const rawSrc = (imageEl.getAttribute('src') || '').trim();
if (rawSrc) return rawSrc;
return (imageEl.getAttribute('data-src') || '').trim();
}
function restoreLaunchpadRedrawIconFromImage(imageEl) {
if (!(imageEl instanceof HTMLImageElement)) return;
if (!imageEl.hasAttribute(LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR)) return;
const originalSrc = imageEl.getAttribute(LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR) || '';
const originalDataSrc =
imageEl.getAttribute(LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR) || '';
if (originalSrc) {
imageEl.setAttribute('src', originalSrc);
} else {
imageEl.removeAttribute('src');
}
if (originalDataSrc) {
imageEl.setAttribute('data-src', originalDataSrc);
} else {
imageEl.removeAttribute('data-src');
}
imageEl.removeAttribute(LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR);
imageEl.removeAttribute(LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR);
}
function restoreLaunchpadRedrawIcon(cardEl) {
const imageEl = getLaunchpadIconImageElement(cardEl);
if (!(imageEl instanceof HTMLImageElement)) return;
restoreLaunchpadRedrawIconFromImage(imageEl);
}
function resolveLaunchpadRedrawPath(cardEl) {
const key = extractLaunchpadAppKey(cardEl);
if (!key) return '';
const path = currentLaunchpadIconRedrawMap[key];
if (typeof path !== 'string' || !path.trim()) return '';
if (!/^prefect_icon\/[a-z0-9-]+\.png$/i.test(path)) return '';
return path.trim();
}
function applyLaunchpadRedrawIcon(cardEl) {
const imageEl = getLaunchpadIconImageElement(cardEl);
if (!(imageEl instanceof HTMLImageElement)) return;
const redrawPath = resolveLaunchpadRedrawPath(cardEl);
if (!redrawPath) {
restoreLaunchpadRedrawIconFromImage(imageEl);
return;
}
if (!imageEl.hasAttribute(LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR)) {
imageEl.setAttribute(
LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR,
imageEl.getAttribute('src') || ''
);
}
if (!imageEl.hasAttribute(LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR)) {
imageEl.setAttribute(
LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR,
imageEl.getAttribute('data-src') || ''
);
}
const redrawUrl = safeRuntimeGetURL(redrawPath);
if (!redrawUrl) {
restoreLaunchpadRedrawIconFromImage(imageEl);
return;
}
if (imageEl.getAttribute('src') !== redrawUrl) {
imageEl.setAttribute('src', redrawUrl);
}
}
function normalizeLaunchpadPreviewSource(rawSource) {
if (typeof rawSource !== 'string') return '';
const source = rawSource.trim();
if (!source) return '';
try {
return new URL(source, window.location.origin).toString();
} catch {
return source;
}
}
function ensureLaunchpadBlurClone(boxEl, cardEl) {
if (!(boxEl instanceof HTMLElement)) return;
const source = getLaunchpadIconImageSource(cardEl);
if (!source) return;
let cloneEl = boxEl.querySelector(`:scope > .${LAUNCHPAD_ICON_BLUR_CLONE_CLASS}`);
if (!(cloneEl instanceof HTMLElement)) {
cloneEl = document.createElement('div');
cloneEl.className = LAUNCHPAD_ICON_BLUR_CLONE_CLASS;
const cloneImgEl = document.createElement('img');
cloneImgEl.className = LAUNCHPAD_ICON_BLUR_CLONE_IMG_CLASS;
cloneImgEl.alt = '';
cloneEl.appendChild(cloneImgEl);
boxEl.insertBefore(cloneEl, boxEl.firstChild);
}
const cloneImgEl = cloneEl.querySelector(`img.${LAUNCHPAD_ICON_BLUR_CLONE_IMG_CLASS}`);
if (!(cloneImgEl instanceof HTMLImageElement)) return;
if (cloneImgEl.getAttribute('src') !== source) {
cloneImgEl.setAttribute('src', source);
}
}
function removeLaunchpadBlurClone(boxEl) {
if (!(boxEl instanceof HTMLElement)) return;
boxEl
.querySelectorAll(`:scope > .${LAUNCHPAD_ICON_BLUR_CLONE_CLASS}`)
.forEach((cloneEl) => {
if (!(cloneEl instanceof HTMLElement)) return;
cloneEl.remove();
});
}
function collectLaunchpadAppItems() {
const itemMap = new Map();
const cards = collectLaunchpadIconCards();
cards.forEach((cardEl) => {
const key = extractLaunchpadAppKey(cardEl);
if (!key) return;
const title = extractLaunchpadAppTitle(cardEl);
if (itemMap.has(key)) return;
itemMap.set(key, {
key,
title: title || key.split('/').pop() || key,
iconSrc: normalizeLaunchpadPreviewSource(getLaunchpadIconImageSource(cardEl))
});
});
return Array.from(itemMap.values());
}
function shouldScaleLaunchpadCard(cardEl, selectedSet) {
const key = extractLaunchpadAppKey(cardEl);
if (!key) return false;
if (!(selectedSet instanceof Set) || selectedSet.size === 0) return false;
return selectedSet.has(key);
}
function shouldMaskOnlyLaunchpadCard(cardEl, maskOnlySet) {
if (!(maskOnlySet instanceof Set) || maskOnlySet.size === 0) return false;
const key = extractLaunchpadAppKey(cardEl);
if (!key) return false;
return maskOnlySet.has(key);
}
function shouldRedrawLaunchpadCard(cardEl, redrawSet) {
if (!(redrawSet instanceof Set) || redrawSet.size === 0) return false;
const key = extractLaunchpadAppKey(cardEl);
if (!key) return false;
return redrawSet.has(key);
}
function setLaunchpadIconScaleOnDom(enabled) {
const selectedSet = new Set(currentLaunchpadIconScaleSelectedKeys);
const maskOnlySet = new Set(currentLaunchpadIconMaskOnlyKeys);
const redrawSet = new Set(currentLaunchpadIconRedrawKeys);
const cards = collectLaunchpadIconCards();
const matchedBoxes = new Set();
cards.forEach((cardEl) => {
const boxEl = findLaunchpadIconBox(cardEl);
if (!(boxEl instanceof HTMLElement)) return;
matchedBoxes.add(boxEl);
const shouldScale = enabled && shouldScaleLaunchpadCard(cardEl, selectedSet);
const shouldMaskOnly =
enabled && shouldMaskOnlyLaunchpadCard(cardEl, maskOnlySet);
const shouldRedraw =
enabled && shouldRedrawLaunchpadCard(cardEl, redrawSet);
const shouldProcess = shouldScale || shouldMaskOnly;
boxEl.classList.toggle(LAUNCHPAD_ICON_BASE_CLASS, shouldProcess);
boxEl.classList.toggle(LAUNCHPAD_ICON_BOX_CLASS, shouldScale);
boxEl.classList.toggle(LAUNCHPAD_ICON_MASK_ONLY_CLASS, shouldMaskOnly);
if (shouldScale) {
ensureLaunchpadBlurClone(boxEl, cardEl);
} else {
removeLaunchpadBlurClone(boxEl);
}
if (shouldRedraw) {
applyLaunchpadRedrawIcon(cardEl);
} else {
restoreLaunchpadRedrawIcon(cardEl);
}
});
document
.querySelectorAll(
`.${LAUNCHPAD_ICON_BASE_CLASS}, .${LAUNCHPAD_ICON_BOX_CLASS}, .${LAUNCHPAD_ICON_MASK_ONLY_CLASS}`
)
.forEach((boxEl) => {
if (!(boxEl instanceof HTMLElement)) return;
if (enabled && matchedBoxes.has(boxEl)) return;
boxEl.classList.remove(LAUNCHPAD_ICON_BASE_CLASS);
boxEl.classList.remove(LAUNCHPAD_ICON_BOX_CLASS);
boxEl.classList.remove(LAUNCHPAD_ICON_MASK_ONLY_CLASS);
removeLaunchpadBlurClone(boxEl);
});
document
.querySelectorAll(
`img[${LAUNCHPAD_ICON_ORIGINAL_SRC_ATTR}], img[${LAUNCHPAD_ICON_ORIGINAL_DATA_SRC_ATTR}]`
)
.forEach((imageEl) => {
if (!(imageEl instanceof HTMLImageElement)) return;
const cardEl = imageEl.closest('div.cursor-pointer');
if (!(cardEl instanceof HTMLElement)) {
restoreLaunchpadRedrawIconFromImage(imageEl);
return;
}
const shouldKeep =
enabled && shouldRedrawLaunchpadCard(cardEl, redrawSet);
if (!shouldKeep) {
restoreLaunchpadRedrawIconFromImage(imageEl);
}
});
}
function refreshLaunchpadIconState() {
launchpadIconRefreshRafId = 0;
currentLaunchpadAppItems = collectLaunchpadAppItems();
window.__fnosLaunchpadAppIconItems = currentLaunchpadAppItems.map((item) => ({
key: item.key,
title: item.title,
iconSrc: item.iconSrc
}));
window.__fnosLaunchpadAppIconTitles = currentLaunchpadAppItems.map((item) => item.title);
if (currentLaunchpadIconScaleEnabled) {
ensureLaunchpadIconScaleStyle();
}
setLaunchpadIconScaleOnDom(currentLaunchpadIconScaleEnabled);
}
function scheduleLaunchpadIconRefresh() {
if (launchpadIconRefreshRafId) return;
launchpadIconRefreshRafId = window.requestAnimationFrame(refreshLaunchpadIconState);
}
function stopLaunchpadIconObserver() {
if (launchpadIconObserver) {
launchpadIconObserver.disconnect();
launchpadIconObserver = null;
}
if (launchpadIconRefreshRafId) {
window.cancelAnimationFrame(launchpadIconRefreshRafId);
launchpadIconRefreshRafId = 0;
}
}
function startLaunchpadIconObserver() {
if (!(document.body instanceof HTMLElement)) {
document.addEventListener(
'DOMContentLoaded',
() => {
if (!currentLaunchpadIconScaleEnabled) return;
startLaunchpadIconObserver();
scheduleLaunchpadIconRefresh();
},
{ once: true }
);
return;
}
if (launchpadIconObserver) return;
launchpadIconObserver = new MutationObserver(() => {
scheduleLaunchpadIconRefresh();
});
launchpadIconObserver.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class', 'title', 'src', 'data-src']
});
}
function updateLaunchpadIconScaleEnabled(
nextEnabled,
nextSelectedKeys = [],
nextMaskOnlyKeys = [],
nextRedrawKeys = [],
nextRedrawMap = {}
) {
currentLaunchpadIconScaleEnabled = Boolean(nextEnabled);
const normalizedRedrawMap = normalizeLaunchpadRedrawMap(nextRedrawMap);
const normalizedRedrawKeys = normalizeLaunchpadKeyList(nextRedrawKeys).filter(
(key) => typeof normalizedRedrawMap[key] === 'string'
);
const redrawSet = new Set(normalizedRedrawKeys);
currentLaunchpadIconRedrawKeys = normalizedRedrawKeys;
currentLaunchpadIconRedrawMap = {};
currentLaunchpadIconRedrawKeys.forEach((key) => {
currentLaunchpadIconRedrawMap[key] = normalizedRedrawMap[key];
});
currentLaunchpadIconMaskOnlyKeys = normalizeLaunchpadKeyList(
nextMaskOnlyKeys
).filter((key) => !redrawSet.has(key));
currentLaunchpadIconScaleSelectedKeys = normalizeLaunchpadKeyList(
nextSelectedKeys
).filter((key) => !redrawSet.has(key));
if (currentLaunchpadIconScaleEnabled) {
startLaunchpadIconObserver();
scheduleLaunchpadIconRefresh();
return;
}
stopLaunchpadIconObserver();
setLaunchpadIconScaleOnDom(false);
currentLaunchpadAppItems = collectLaunchpadAppItems();
window.__fnosLaunchpadAppIconItems = currentLaunchpadAppItems.map((item) => ({
key: item.key,
title: item.title,
iconSrc: item.iconSrc
}));
window.__fnosLaunchpadAppIconTitles = currentLaunchpadAppItems.map((item) => item.title);
}
function normalizeAppCenterMetaLabel(value) {
const normalized = normalizeText(value, 40).replace(/\s+/g, '');
return APP_CENTER_META_TYPE_MAP[normalized] || '';
}
function formatAppCenterDownloadValue(value) {
const normalized = normalizeText(value, 80);
if (!/^\d+$/.test(normalized)) return normalized;
return normalized.replace(/\B(?=(\d{4})+(?!\d))/g, ',');
}
function parseAppCenterSizeValue(value) {
const normalized = normalizeText(value, 80);
const matched = normalized.match(/^(.+?)(?:\s+)([A-Za-z]+)$/);
if (!matched) {
return {
main: normalized,
sub: ''
};
}
return {
main: normalizeText(matched[1], 40),
sub: normalizeText(matched[2], 20)
};
}
function getAppCenterMetaItems(rowEl) {
return Array.from(rowEl.children).filter((child) => child instanceof HTMLElement);
}
function isAppCenterMetaRow(rowEl) {
if (!(rowEl instanceof HTMLElement)) return false;
const items = getAppCenterMetaItems(rowEl);
if (items.length !== 5 && items.length !== 6) return false;
const types = items.map((itemEl) => {
const labelEl = Array.from(itemEl.children).find(
(child) => child instanceof HTMLParagraphElement
);
return normalizeAppCenterMetaLabel(labelEl?.textContent || '');
});
if (types.some((type) => !type)) return false;
const uniqueTypes = new Set(types);
if (uniqueTypes.size !== types.length) return false;
if (items.length === 6) {
return uniqueTypes.has('install-location');
}
return !uniqueTypes.has('install-location');
}
function removeAppCenterMetaSubValue(itemEl, valueEl) {
Array.from(itemEl.children).forEach((child) => {
if (!(child instanceof HTMLElement) || child === valueEl) return;
if (!child.classList.contains('fnos-app-meta-value-sub')) return;
child.remove();
});
}
function setAppCenterMetaStackedValue(itemEl, valueEl, mainText, subText) {
const nextMain = normalizeText(mainText, 80);
const nextSub = normalizeText(subText, 40);
const nextSignature = `${nextMain}||${nextSub}`;
if (valueEl.dataset.fnosAppMetaRendered === nextSignature) return;
valueEl.textContent = nextMain;
valueEl.dataset.fnosAppMetaRendered = nextSignature;
let subEl = Array.from(itemEl.children).find(
(child) =>
child instanceof HTMLElement &&
child.classList.contains('fnos-app-meta-value-sub')
);
if (nextSub) {
if (!(subEl instanceof HTMLElement)) {
subEl = document.createElement('span');
subEl.className = 'fnos-app-meta-value-sub';
itemEl.appendChild(subEl);
}
subEl.textContent = nextSub;
} else if (subEl instanceof HTMLElement) {
subEl.remove();
}
}
function setAppCenterMetaPlainValue(itemEl, valueEl, rawValue) {
const normalized = normalizeText(rawValue, 100);
if (valueEl.dataset.fnosAppMetaRendered === normalized) return;
removeAppCenterMetaSubValue(itemEl, valueEl);
valueEl.textContent = normalized;
valueEl.dataset.fnosAppMetaRendered = normalized;
}
function enhanceAppCenterMetaItem(itemEl, type) {
if (!(itemEl instanceof HTMLElement) || !type) return;
const paragraphs = Array.from(itemEl.children).filter(
(child) => child instanceof HTMLParagraphElement
);
if (paragraphs.length < 2) return;
const labelEl = paragraphs[0];
const valueEl = paragraphs[1];
const rawValue =
itemEl.dataset.fnosAppMetaRaw || normalizeText(valueEl.textContent, 100);
itemEl.dataset.fnosAppMetaRaw = rawValue;
itemEl.classList.add('fnos-app-meta-item', `fnos-app-meta-item--${type}`);
labelEl.classList.add('fnos-app-meta-label');
valueEl.classList.add('fnos-app-meta-value');
let iconEl = Array.from(itemEl.children).find(
(child) =>
child instanceof HTMLElement &&
child.classList.contains('fnos-app-meta-icon')
);
const iconTypes = new Set(['developer', 'publisher', 'install-location', 'version']);
if (iconTypes.has(type)) {
if (!(iconEl instanceof HTMLElement)) {
iconEl = document.createElement('span');
iconEl.setAttribute('aria-hidden', 'true');
itemEl.insertBefore(iconEl, valueEl);
}
iconEl.className = `fnos-app-meta-icon fnos-app-meta-icon--${type}`;
valueEl.classList.remove('fnos-app-meta-value-main');
setAppCenterMetaPlainValue(itemEl, valueEl, rawValue);
return;
}
if (iconEl instanceof HTMLElement) {
iconEl.remove();
}
valueEl.classList.add('fnos-app-meta-value-main');
if (type === 'downloads') {
setAppCenterMetaStackedValue(
itemEl,
valueEl,
formatAppCenterDownloadValue(rawValue),
'次'
);
return;
}
if (type === 'size') {
const parsed = parseAppCenterSizeValue(rawValue);
setAppCenterMetaStackedValue(itemEl, valueEl, parsed.main, parsed.sub);
return;
}
valueEl.classList.remove('fnos-app-meta-value-main');
setAppCenterMetaPlainValue(itemEl, valueEl, rawValue);
}
function refreshAppCenterMetaLayout() {
appCenterMetaRefreshRafId = 0;
document.querySelectorAll('.trim-ui__app-layout--window').forEach((windowEl) => {
if (!(windowEl instanceof HTMLElement)) return;
const appCenterIcon = windowEl.querySelector(
'.trim-ui__app-layout--header-title img[alt="应用中心"]'
);
if (!(appCenterIcon instanceof HTMLImageElement)) return;
windowEl.querySelectorAll('div').forEach((rowEl) => {
if (!(rowEl instanceof HTMLElement) || !isAppCenterMetaRow(rowEl)) return;
rowEl.classList.add('fnos-app-meta-panel');
rowEl.dataset.fnosAppMetaCount = String(getAppCenterMetaItems(rowEl).length);
getAppCenterMetaItems(rowEl).forEach((itemEl) => {
const labelEl = Array.from(itemEl.children).find(
(child) => child instanceof HTMLParagraphElement
);
const type = normalizeAppCenterMetaLabel(labelEl?.textContent || '');
enhanceAppCenterMetaItem(itemEl, type);
});
});
});
}
function isAppCenterWindow(windowEl) {
if (!(windowEl instanceof HTMLElement)) return false;
return Boolean(
windowEl.querySelector('.trim-ui__app-layout--header-title img[alt="应用中心"]')
);
}
function isAppCenterDetailOverlay(overlayEl) {
if (!(overlayEl instanceof HTMLElement)) return false;
if (!hasAllClasses(overlayEl, APP_CENTER_DETAIL_OVERLAY_CLASS_TOKENS)) return false;
if (!overlayEl.classList.contains('bg-[var(--semi-color-app-container)]')) return false;
return Boolean(overlayEl.querySelector('button.semi-button-with-icon-only'));
}
function getAppCenterDetailOverlay(windowEl) {
if (!(windowEl instanceof HTMLElement)) return null;
return Array.from(windowEl.querySelectorAll('div')).find((candidate) =>
isAppCenterDetailOverlay(candidate)