-
Notifications
You must be signed in to change notification settings - Fork 827
/
desktop.js
executable file
·4458 lines (4339 loc) · 206 KB
/
desktop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
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
'use strict';
/*
Windows 12 网页版
GitHub: tjy-gitnub/win12
*/
console.log('%cWindows 12 网页版(GitHub: tjy-gitnub/win12)', 'background-image: linear-gradient(to right, #ad6eca, #3b91d8); border-radius: 8px; font-size: 1.3em; padding: 10px 15px; color: #fff; ');
// 后端服务器
// loadlang();
const server = 'http://win12server.freehk.svipss.top/';
const pages = {
'get-title': '', // 获取标题
};
const page = $('html')[0];
function disableIframes() {
$('iframe:not(.nochanges)').css('pointer-events', 'none');
$('iframe:not(.nochanges)').css('touch-action', 'none');
}
function enableIframes() {
$('iframe:not(.nochanges)').css('pointer-events', 'auto');
$('iframe:not(.nochanges)').css('touch-action', 'auto');
}
async function api(index) {
const token = localStorage.getItem('token');
if (token) {
const headers = new Headers();
headers.append('Authorization', token);
const res = await fetch('https://api.github.com/' + index, {headers: headers});
return res;
}
else {
const res = await fetch('https://api.github.com/' + index);
return res;
}
}
page.addEventListener('mousedown', disableIframes);
page.addEventListener('touchstart', disableIframes);
page.addEventListener('mouseup', enableIframes);
page.addEventListener('touchend', enableIframes);
page.addEventListener('touchcancel', enableIframes);
page.addEventListener('click',(event)=>{
if($('#start-menu').hasClass('show')&&!$(event.target).closest('#start-menu').length){
hide_startmenu();
}
});
//开始菜单收回
// 上古代码
document.querySelectorAll('list.focs').forEach(li => {
li.addEventListener('click', () => {
let _ = li.$$('span.focs')[0], la = li.$$('a.check')[0],
las = li.$$('a');
if (_.dataset.type == 'abs') {
$(_).addClass('cl');
$(_).css('top', (la.getBoundingClientRect().top - li.parentElement.getBoundingClientRect().top) + 'px');
setTimeout(() => {
$(_).removeClass('cl');
}, 500);
}
else {
$(_).addClass('cl');
$(_).css('top', la.offsetTop - las[las.length - 1].offsetTop);
$(_).css('left', la.offsetLeft - li.offsetLeft);
setTimeout(() => {
$(_).removeClass('cl');
}, 500);
}
});
});
// 禁止拖拽图片
$('img').on('dragstart', () => {
return false;
});
// 右键菜单
$('html').on('contextmenu', () => {
return false;
});
function stop(e) {
e.stopPropagation();
return false;
}
$('input,textarea,*[contenteditable=true]').on('contextmenu', (e) => {
stop(e);
return true;
});
function addMenu() {
var parentDiv = $('#desktop')[0];
var childDivs = parentDiv.$$('#div');
for (var i = 0; i < childDivs.length; i++) {
if (i <= 4) {//win12内置的5个图标不添加
continue;
}
let div = childDivs[i];
div.setAttribute('iconIndex', i - 5);
div.addEventListener('contextmenu', (event) => {
if (div.getAttribute('appname') != undefined) {
return showcm(event, 'desktop.icon', [div.getAttribute('appname'), div.getAttribute('iconIndex')]);
}
return false;
}, useCapture = true);
}
}
var run_cmd = '';
let nomax = { 'calc': 0 , 'notepad-fonts': 0, 'camera-notice': 0, 'winver': 0, 'run': 0, 'wsa': 0 };
let nomin = { 'notepad-fonts': 0, 'camera-notice': 0, 'run': 0 };
var topmost = [];
var sys_setting = [1, 1, 1, 0, 0, 1, 1];
var use_music = true;
var use_mic_voice = true;
// 右键菜单
/* 参考 desktop.html 开头信息
每个标识对应一个列表,每一项为一个右键菜单中显示的项,可以有以下形式:
1. 'text', 文本信息
2. ['text','script'], 分别为显示内容,点击执行的代码
3. arg => {
...
return ...
}
形参 arg 为 showcm() 方法第三个位置的用以传参的参数内容,
返回内容或为 'null' 表示跳过此项,或参考条目 2 的格式
*/
let cms = {
'save-bar':[
arg => {
return ['<i class="bi bi-window-x"></i> 移除', `removeEdgeSaveUrl('${arg}')`];
}
],
'titbar': [
arg => {
if (arg in nomax) {
return 'null';
}
if ($('.window.' + arg).hasClass('max')) {
return ['<i class="bi bi-window-stack"></i> 还原', `maxwin('${arg}')`];
}
else {
return ['<i class="bi bi-window-fullscreen"></i> 最大化', `maxwin('${arg}')`];
}
},
arg => {
if (arg in nomin) {
return 'null';
}
else {
return ['<i class="bi bi-window-dash"></i> 最小化', `minwin('${arg}')`];
}
},
arg => {
if (arg in nomin) {
return ['<i class="bi bi-window-x"></i> 关闭', `hidewin('${arg}', 'configs')`];
}
else {
return ['<i class="bi bi-window-x"></i> 关闭', `hidewin('${arg}')`];
}
},
],
'taskbar': [
arg => {
return ['<i class="bi bi-window-x"></i> 关闭', `hidewin('${arg}')`];
}
],
'desktop': [
['<i class="bi bi-arrow-clockwise"></i> 刷新', '$(\'#desktop\').css(\'opacity\',\'0\');setTimeout(()=>{$(\'#desktop\').css(\'opacity\',\'1\');},100);setIcon();'],
['<i class="bi bi-circle-square"></i> 切换主题', 'toggletheme()'],
'<a onmousedown="window.open(\'https://github.com/tjy-gitnub/win12\',\'_blank\');" win12_title="https://github.com/tjy-gitnub/win12" onmouseenter="showdescp(event)" onmouseleave="hidedescp(event)"><i class="bi bi-github"></i> 在 Github 中查看此项目</a>',
arg => {
if (edit_mode) {
return ['<i class="bi bi-pencil"></i> 退出编辑模式', 'editMode();'];
}
else if (!edit_mode) {
return ['<i class="bi bi-pencil"></i> 进入编辑模式', 'editMode();'];
}
},
['<i class="bi bi-info-circle"></i> 关于 Win12 网页版', '$(\'#win-about>.about\').addClass(\'show\');$(\'#win-about>.update\').removeClass(\'show\');openapp(\'about\');if($(\'.window.about\').hasClass(\'min\'))minwin(\'about\');'],
['<i class="bi bi-brush"></i> 个性化', 'openapp(\'setting\');$(\'#win-setting > div.menu > list > a.enable.appearance\')[0].click()']
],
'desktop.icon': [
arg => {
return ['<i class="bi bi-folder2-open"></i> 打开', 'openapp(`' + arg[0] + '`)'];
},
arg => {
if (arg[1] >= 0) {
return ['<i class="bi bi-trash3"></i> 删除', 'desktopItem.splice(' + (arg[1]) + ', 1);saveDesktop();setIcon();addMenu();'];
} else {
return 'null';
}
}
],
'winx': [
arg => {
if ($('#start-menu').hasClass('show')) {
return ['<i class="bi bi-box-arrow-in-down"></i> 关闭开始菜单', 'hide_startmenu()'];
}
else {
return ['<i class="bi bi-box-arrow-in-up"></i> 打开开始菜单', `$('#start-btn').addClass('show');
if($('#search-win').hasClass('show')){$('#search-btn').removeClass('show');
$('#search-win').removeClass('show');setTimeout(() => {$('#search-win').removeClass('show-begin');
}, 200);}$('#start-menu').addClass('show-begin');setTimeout(() => {$('#start-menu').addClass('show');
}, 0);`];
}
},
'<hr>',
['<i class="bi bi-gear"></i> 设置', 'openapp(\'setting\')'],
['<i class="bi bi-terminal"></i> 运行', 'openapp(\'run\')'],
['<i class="bi bi-folder2-open"></i> 文件资源管理器', 'openapp(\'explorer\')'],
['<i class="bi bi-search"></i> 搜索', `$('#search-btn').addClass('show');hide_startmenu();
$('#search-win').addClass('show-begin');setTimeout(() => {$('#search-win').addClass('show');
$('#search-input').focus();}, 0);`],
'<hr>',
['<i class="bi bi-power"></i> 关机', 'window.location=\'shutdown.html\''],
['<i class="bi bi-arrow-counterclockwise"></i> 重启', 'window.location=\'reload.html\''],
],
'smapp': [
arg => {
return ['<i class="bi bi-window"></i> 打开', `openapp('${arg[0]}');hide_startmenu();`];
},
arg => {
return ['<i class="bi bi-link-45deg"></i> 在桌面创建链接', 'var s=`<div class=\'b\' ondblclick=openapp(\'' + arg[0] + '\') ontouchstart=openapp(\'' + arg[0] + '\') appname=\'' + arg[0] + '\'><img src=\'icon/' + geticon(arg[0]) + '\'><p>' + arg[1] + '</p></div>`;$(\'#desktop\').append(s);desktopItem[desktopItem.length]=s;addMenu();saveDesktop();'];
},
arg => {
return ['<i class="bi bi-x"></i> 取消固定', `$('#s-m-r>.pinned>.apps>.sm-app.${arg[0]}').remove()`];
}
],
'smlapp': [
arg => {
return ['<i class="bi bi-window"></i> 打开', `openapp('${arg[0]}');hide_startmenu();`];
},
arg => {
return ['<i class="bi bi-link-45deg"></i> 在桌面创建链接', 'var s=`<div class=\'b\' ondblclick=openapp(\'' + arg[0] + '\') ontouchstart=openapp(\'' + arg[0] + '\') appname=\'' + arg[0] + '\'><img src=\'icon/' + geticon(arg[0]) + '\'><p>' + arg[1] + '</p></div>`;$(\'#desktop\').append(s);desktopItem[desktopItem.length]=s;addMenu();saveDesktop();'];
},
arg => {
return ['<i class="bi bi-pin-angle"></i> 固定到开始菜单', 'pinapp(\'' + arg[0] + '\', \'' + arg[1] + '\', \'openapp("' + arg[0] + '");hide_startmenu();\')'];
}
],
'msgupdate': [
['<i class="bi bi-layout-text-window-reverse"></i> 查看详细', `openapp('about');if($('.window.about').hasClass('min'))
minwin('about');$('#win-about>.about').removeClass('show');$('#win-about>.update').addClass('show');
$('#win-about>.update>div>details:first-child').attr('open','open')`],
['<i class="bi bi-box-arrow-right"></i> 关闭', '$(\'.msg.update\').removeClass(\'show\')']
],
'explorer.folder': [
arg => {
return ['<i class="bi bi-folder2-open"></i> 打开', `apps.explorer.goto('${arg}')`];
},
arg => {
return ['<i class="bi bi-arrow-up-right-square"></i> 在新标签页中打开', `apps.explorer.newtab('${arg}');`];
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-trash3"></i> 删除', `apps.explorer.del('${arg}')`];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-files"></i> 复制', `apps.explorer.copy_or_cut('${arg}','copy')`];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-scissors"></i> 剪切', `apps.explorer.copy_or_cut('${arg}','cut')`];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-input-cursor-text"></i> 重命名', `apps.explorer.rename('${arg}')`];
return 'null';
}
],
'explorer.file': [
arg => {
return ['<i class="bi bi-folder2-open"></i> 打开(目前毛用没有)', ''];
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-trash3"></i> 删除', `apps.explorer.del('${arg}')`];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text')[0].innerHTML != '此电脑')
return ['<i class="bi bi-files"></i> 复制', `apps.explorer.copy_or_cut('${arg}','copy')`];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-scissors"></i> 剪切', `apps.explorer.copy_or_cut('${arg}','cut')`];
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-input-cursor-text"></i> 重命名', `apps.explorer.rename('${arg}')`];
return 'null';
}
],
'explorer.content': [
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-file-earmark-plus"></i> 新建文件', 'apps.explorer.add($(\'#win-explorer>.path>.tit\')[0].dataset.path,\'新建文本文档.txt\')'];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-folder-plus"></i> 新建文件夹', 'apps.explorer.add($(\'#win-explorer>.path>.tit\')[0].dataset.path,\'新建文件夹\',type=\'files\')'];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-file-earmark-arrow-down"></i> 粘贴', 'apps.explorer.paste($(\'#win-explorer>.path>.tit\')[0].dataset.path,\'新建文件夹\',type=\'files\')'];
return 'null';
},
arg => {
if ($('#win-explorer>.path>.tit>.path>div.text').length > 1)
return ['<i class="bi bi-arrow-clockwise"></i> 刷新', 'apps.explorer.goto($(\'#win-explorer>.path>.tit\')[0].dataset.path, false)'];
return ['<i class="bi bi-arrow-clockwise"></i> 刷新', 'apps.explorer.reset()'];
}
],
'explorer.tab': [
arg => {
return ['<i class="bi bi-x"></i> 关闭标签页', `m_tab.close('explorer',${arg})`];
}
],
'edge.tab': [
arg => {
return ['<i class="bi bi-pencil-square"></i> 命名标签页', `apps.edge.c_rename(${arg})`];
},
arg => {
return ['<i class="bi bi-x"></i> 关闭标签页', `m_tab.close('edge',${arg})`];
}
],
'taskmgr.processes': [
arg => {
return ['<i class="bi bi-x"></i> 结束任务', `apps.taskmgr.taskkill('${arg}')`];
}
]
};
function showcm(e, cl, arg) {
if ($('#cm').hasClass('show-begin')) {
setTimeout(() => {
$('#cm').css('left', e.clientX);
$('#cm').css('top', e.clientY);
let h = '';
cms[cl].forEach(item => {
if (typeof (item) == 'function') {
arg.event = e;
ret = item(arg);
if (ret == 'null') return true;
h += `<a class="a" onmousedown="${ret[1]}">${ret[0]}</a>\n`;
}
else if (typeof (item) == 'string') {
h += item + '\n';
}
else {
h += `<a class="a" onmousedown="${item[1]}">${item[0]}</a>\n`;
}
});
$('#cm>list')[0].innerHTML = h;
$('#cm').addClass('show-begin');
$('#cm>.foc').focus();
// 这个.foc是用来模拟焦点的,这句是将焦点放在右键菜单上,注释掉后果不堪设想 >u-)o
// 噢 可是如果设置焦点的话在移动设备上会显示虚拟键盘啊 QAQ (By: User782Tec)
// (By: tjy-gitnub)
setTimeout(() => {
$('#cm').addClass('show');
}, 0);
setTimeout(() => {
if (e.clientY + $('#cm')[0].offsetHeight > $('html')[0].offsetHeight) {
$('#cm').css('top', e.clientY - $('#cm')[0].offsetHeight);
}
if (e.clientX + $('#cm')[0].offsetWidth > $('html')[0].offsetWidth) {
$('#cm').css('left', $('html')[0].offsetWidth - $('#cm')[0].offsetWidth - 5);
}
}, 200);
}, 200);
return;
}
$('#cm').css('left', e.clientX);
$('#cm').css('top', e.clientY);
let h = '';
cms[cl].forEach(item => {
if (typeof (item) == 'function') {
let ret = item(arg);
if (ret == 'null') {
return true;
}
h += `<a class="a" onmousedown="${ret[1]}">${ret[0]}</a>\n`;
} else if (typeof (item) == 'string') {
h += item + '\n';
} else {
h += `<a class="a" onmousedown="${item[1]}">${item[0]}</a>\n`;
}
});
$('#cm>list')[0].innerHTML = h;
$('#cm').addClass('show-begin');
$('#cm>.foc').focus();
setTimeout(() => {
$('#cm').addClass('show');
}, 0);
setTimeout(() => {
if (e.clientY + $('#cm')[0].offsetHeight > $('html')[0].offsetHeight) {
$('#cm').css('top', e.clientY - $('#cm')[0].offsetHeight);
}
if (e.clientX + $('#cm')[0].offsetWidth > $('html')[0].offsetWidth) {
$('#cm').css('left', $('html')[0].offsetWidth - $('#cm')[0].offsetWidth - 5);
}
}, 200);
}
$('#cm>.foc').blur(() => {
let x = event.target.parentNode;
$(x).removeClass('show');
setTimeout(() => {
$(x).removeClass('show-begin');
}, 200);
});
let font_window = false;
// 下拉菜单
let dps = {
'notepad.file': [
['<i class="bi bi-file-earmark-plus"></i> 新建', `hidedp(true);$('#win-notepad>.text-box').addClass('down');
setTimeout(()=>{$('#win-notepad>.text-box').val('');$('#win-notepad>.text-box').removeClass('down')},200);`],
['<i class="bi bi-box-arrow-right"></i> 另存为', `hidedp(true);$('#win-notepad>.save').attr('href', window.URL.createObjectURL(new Blob([$('#win-notepad>.text-box').html()])));
$('#win-notepad>.save')[0].click();`],
'<hr>',
['<i class="bi bi-x"></i> 退出', 'isOnDp=false;hidedp(true);hidewin(\'notepad\')'],
],
'notepad.edit': [
['<i class="bi bi-files"></i> 复制 <info>Ctrl+C</info>', 'document.execCommand(\'copy\')'],
['<i class="bi bi-clipboard"></i> 粘贴 <info>Ctrl+V</info>', 'document.execCommand(\'paste\')'],
['<i class="bi bi-scissors"></i> 剪切 <info>Ctrl+X</info>', 'document.execCommand(\'cut\')'],
'<hr>',
['<i class="bi bi-arrow-return-left"></i> 撤销 <info>Ctrl+Z</info>', 'document.execCommand(\'undo\')'],
['<i class="bi bi-arrow-clockwise"></i> 重做 <info>Ctrl+Y</info>', 'document.execCommand(\'redo\')'],
],
'notepad.view': [
['<i class="bi bi-type"></i> 插入正常字块', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<p>T</p>\''],
['<i class="bi bi-type-h1"></i> 插入主标题', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<h1>H1</h1>\''],
['<i class="bi bi-type-h2"></i> 插入次标题', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<h2>H2</h2>\''],
['<i class="bi bi-type-h3"></i> 插入副标题', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<h3>H3</h3>\''],
['<i class="bi bi-type-underline"></i> 插入下划线', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<u>U</u>\''],
['<i class="bi bi-type-strikethrough"></i> 插入删除线', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<s>S</s>\''],
['<i class="bi bi-type-italic"></i> 插入斜体字', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<i>I</i>\''],
['<i class="bi bi-type-bold"></i> 插入加粗字', 'hidedp(true);$(\'#win-notepad>.text-box\')[0].innerHTML+=\'<b>B</b>\''],
'<hr>',
['<i class="bi bi-fonts"></i> 字体', 'font_window=true;hidedp(true);showwin(\'notepad-fonts\');apps.notepadFonts.reset();'],
]
};
function playWindowsBackground() {
var audio = new Audio('./media/Windows Background.wav');
audio.play();
}
let dpt = null, isOnDp = false;
$('#dp')[0].onmouseover = () => { isOnDp = true; };
$('#dp')[0].onmouseleave = () => { isOnDp = false; hidedp(); };
function showdp(e, cl, arg) {
if ($('#dp').hasClass('show-begin')) {
$('#dp').removeClass('show');
setTimeout(() => {
$('#dp').removeClass('show-begin');
}, 200);
if (e != dpt) {
setTimeout(() => {
showdp(e, cl, arg);
}, 400);
}
return;
}
// dpt = e;
let off = $(e).offset();
$('#dp').css('left', off.left);
$('#dp').css('top', off.top + e.offsetHeight);
let h = '';
dps[cl].forEach(item => {
if (typeof (item) == 'function') {
let ret = item(arg);
if (ret == 'null') {
return true;
}
h += `<a class="a" onclick="${ret[1]}">${ret[0]}</a>\n`;
} else if (typeof (item) == 'string') {
h += item + '\n';
} else {
h += `<a class="a" onclick="${item[1]}">${item[0]}</a>\n`;
}
});
$('#dp>list')[0].innerHTML = h;
$('#dp').addClass('show-begin');
setTimeout(() => {
$('#dp').addClass('show');
}, 0);
setTimeout(() => {
if (off.top + e.offsetHeight + $('#dp')[0].offsetHeight > $('html')[0].offsetHeight) {
$('#dp').css('top', off.top - $('#dp')[0].offsetHeight);
}
if (off.left + $('#dp')[0].offsetWidth > $('html')[0].offsetWidth) {
$('#dp').css('left', $('html')[0].offsetWidth - $('#dp')[0].offsetWidth - 5);
}
}, 200);
}
function hidedp(force = false) {
setTimeout(() => {
if (isOnDp && !force) {
return;
}
$('#dp').removeClass('show');
setTimeout(() => {
$('#dp').removeClass('show-begin');
}, 200);
}, 100);
}
// 悬停提示
document.querySelectorAll('*[win12_title]:not(.notip)').forEach(a => {
a.addEventListener('mouseenter', showdescp);
a.addEventListener('mouseleave', hidedescp);
});
function showdescp(e) {
$(e.target).attr('data-descp', 'waiting');
setTimeout(() => {
if ($(e.target).attr('data-descp') == 'hide') {
return;
}
$(e.target).attr('data-descp', 'show');
$('#descp').css('left', e.clientX + 15);
$('#descp').css('top', e.clientY + 20);
$('#descp').text($(e.target).attr('win12_title'));
$('#descp').addClass('show-begin');
setTimeout(() => {
if (e.clientY + $('#descp')[0].offsetHeight + 20 >= $('html')[0].offsetHeight) {
$('#descp').css('top', e.clientY - $('#descp')[0].offsetHeight - 10);
}
if (e.clientX + $('#descp')[0].offsetWidth + 15 >= $('html')[0].offsetWidth) {
$('#descp').css('left', e.clientX - $('#descp')[0].offsetWidth - 10);
}
$('#descp').addClass('show');
}, 100);
}, 500);
}
function hidedescp(e) {
$('#descp').removeClass('show');
$(e.target).attr('data-descp', 'hide');
setTimeout(() => {
$('#descp').removeClass('show-begin');
}, 100);
}
// 提示
/* 参考 desktop.html 开头信息,
格式、功能较简单,自行研究,不作赘述*/
let nts = {
'about': {
cnt: `<p class="tit">Windows 12 网页版</p>
<p>Windows 12 网页版是一个开放源项目,<br />
希望让用户在网络上预先体验 Windows 12,<br />
内容可能与 Windows 12 正式版本不一致。<br />
使用标准网络技术,例如 HTML, CSS 和 JS<br />
此项目绝不附属于微软,且不应与微软操作系统或产品混淆,<br />
这也不是 Windows365 cloud PC<br />
本项目中微软、Windows和其他示范产品是微软公司的商标<br />
本项目中谷歌、Android和其他示范产品是谷歌公司的商标</p>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' },
{ type: 'detail', text: '更多', js: 'closenotice();openapp(\'about\');if($(\'.window.about\').hasClass(\'min\'))minwin(\'about\');$(\'.dock.about\').removeClass(\'show\')' },
]
},
'feedback': {
cnt: `<p class="tit">反馈</p>
<p>我们非常注重用户的体验与反馈</p>
<list class="new">
<a class="a" onclick="window.open('https://github.com/tjy-gitnub/win12/issues','_blank');" win12_title="在浏览器新窗口打开链接" onmouseenter="showdescp(event)" onmouseleave="hidedescp(event)">在github上提交issue(需要github账户,会得到更高重视)</a>
<a class="a" onclick="window.open('https://forms.office.com/Pages/ResponsePage.aspx?id=DQSIkWdsW0yxEjajBLZtrQAAAAAAAAAAAAO__SDw7SZURjUzOUo0VEVXU1pMWlFTSUVGWDNYWU1EWS4u','_blank');" win12_title="在浏览器新窗口打开链接" onmouseenter="showdescp(event)" onmouseleave="hidedescp(event)">在Microsoft Forms上发送反馈(不需要账户,也会重视)</a>
</list>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' },
]
},
'widgets': {
cnt: `
<p class="tit">添加小组件</p>
<list class="new">
<a class="a" onclick="closenotice(); widgets.widgets.add('calc');">计算器</a>
<a class="a" onclick="closenotice(); widgets.widgets.add('weather');">天气</a>
<a class="a" onclick="closenotice(); widgets.widgets.add('monitor');">系统性能监视器</a>
</list>`,
btn: [
{ type: 'cancel', text: '取消', js: 'closenotice();' }
]
},
'ZeroDivision': {//计算器报错窗口
// 甚至还报错我真的哭死,直接输入框显示给error啥的不就完了。。
cnt: `<p class="tit">错误</p>
<p>除数不得等于0</p>`,
btn: [
{ type: 'main', text: '确定', js: 'closenotice();' },
]
},
'Can-not-open-file': {
cnt: '<p class="tit">' + run_cmd + `</p>
<p>Windows 找不到文件 '` + run_cmd + '\'。请确定文件名是否正确后,再试一次。</p> ',
btn: [
{ type: 'main', text: '确定', js: 'closenotice();' },
{ type: 'detail', text: '在 Micrsoft Edge 中搜索', js: 'closenotice();openapp(\'edge\');window.setTimeout(() => {apps.edge.newtab();apps.edge.goto(' + run_cmd + ');}, 300);' }
]
},
'widgets.monitor': {
cnt: `
<p class="tit">切换监视器类型</p>
<list class="new">
<a class="a" onclick="closenotice(); widgets.monitor.type = 'cpu';">CPU利用率</a>
<a class="a" onclick="closenotice(); widgets.monitor.type = 'memory';">内存使用率</a>
<a class="a" onclick="closenotice(); widgets.monitor.type = 'disk';">磁盘活动时间</a>
<a class="a" onclick="closenotice(); widgets.monitor.type = 'wifi-receive';">网络吞吐量-接收</a>
<a class="a" onclick="closenotice(); widgets.monitor.type = 'wifi-send';">网络吞吐量-发送</a>
<a class="a" onclick="closenotice(); widgets.monitor.type = 'gpu';">GPU利用率</a>
</list>`,
btn: [
{ type: 'cancel', text: '取消', js: 'closenotice();' }
]
},
'widgets.desktop': {
cnt: `
<p class="tit">添加桌面小组件</p>
<list class="new">
<a class="a" onclick="closenotice(); widgets.widgets.add('calc'); widgets.widgets.addToDesktop('calc');">计算器</a>
<a class="a" onclick="closenotice(); widgets.widgets.add('weather'); widgets.widgets.addToDesktop('weather');">天气</a>
<a class="a" onclick="closenotice(); widgets.widgets.add('monitor'); widgets.widgets.addToDesktop('monitor');">系统性能监视器</a>
</list>`,
btn: [
{ type: 'cancel', text: '取消', js: 'closenotice();' }
]
},
'widgets.news.source': {
cnt: `
<p class="tit">切换新闻源</p>
<list class="new">
新闻源未加载,请检查网络连接
</list>`,
btn: [{ type: 'cancel', text: '取消', js: 'closenotice();' }],
},
'duplication file name': {
cnt: `
<p class="tit">错误</p>
<p>文件名重复</p>`,
btn: [
{ type: 'cancel', text: '取消', js: 'closenotice();' }
]
},
'about-copilot': {
cnt: `
<p class="tit">关于 Windows 12 Copilot</p>
<p>你可以使用此 AI 助手帮助你更快地完成工作 (有人用Win12工作?)<br>
由于所用模型理解力较差,所以间歇性正常工作。<br>
有任何关于本 AI 的反馈请让 AI 帮你打开 AI Copilot反馈界面<br>
每日只有100,000条请求机会!每月只有1G的流量限制,请各位合理安排使用次数(<br>
也请适当使用,不要谈论敏感、违规话题,<br>请有身为一个人类最基本的道德底线。<br>
小项目难免会有bug,见谅,后端由 github@NB-Group 提供</p>`,
btn: [
{ type: 'main', text: '确定', js: 'closenotice();' },
]
},
'feedback-copilot': {
cnt: `<p class="tit">反馈 Windows 12 Copilot</p>
<p>我们非常注重用户的体验与反馈,非常感谢对AI Copilot的建议</p>
<list class="new">
<a class="a" onclick="window.open('https://github.com/tjy-gitnub/win12/issues','_blank');" win12_title="在浏览器新窗口打开链接" onmouseenter="showdescp(event)" onmouseleave="hidedescp(event)">在github上提交issue (需要github账户,会得到更高重视)</a>
<a class="a" onclick="window.open('https://forms.office.com/Pages/ResponsePage.aspx?id=DQSIkWdsW0yxEjajBLZtrQAAAAAAAAAAAAO__SDw7SZURjUzOUo0VEVXU1pMWlFTSUVGWDNYWU1EWS4u','_blank');" win12_title="在浏览器新窗口打开链接" onmouseenter="showdescp(event)" onmouseleave="hidedescp(event)">在Microsoft Forms上发送反馈(不需要账户,也会重视)</a>
</list>
`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' }
]
},
'shutdown': {
cnt: `
<p class="tit">即将注销你的登录</p>
<p>Windows 将在 114514 分钟后关闭。</p>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' }
]
},
'setting.update': {
cnt: `
<p class="tit">更新已就绪</p>
<p>请重启电脑以应用更新</p>
`,
btn: [
{ type: 'main', text: '立即重启', js: 'location.href = `./reload.html`;' },
{ type: 'detail', text: '稍后重启', js: 'closenotice();' }
]
},
'recognition' : {
cnt: `
<p class="tit">语音输入法使用须知</p>
<p>本语音输入法由@nb-group开发<br>
使用的语音识别api 仅可在使用 Chromium 内核的浏览器上使用,<br>
包括Microsoft Edge,Google Chrome等,<br>
api(理论上)完全离线.<br>
我们绝不会窃取您的输入信息,请放心使用。<br><br>
每次语音识别都会重新申请一下麦克风,这是浏览器的问题,<br>
可以在浏览器设置里选择始终允许。<br><br>
哦对了,关掉提示窗口之后再点一次语音球才能开始识别。
</p>
`,
btn: [
{ type: 'main', text: '确定', js: 'closenotice();' },
]
},
'setting.down': {
cnt: `
<p class="tit">下载完毕</p>
<p>请立即重新启动以应用更改</p>
`,
btn: [
{ type: 'main', text: '重新启动', js: 'closenotice(); setTimeout(() => {window.location=`reload.html`;},200);' }
]
}
};
function shownotice(name) {
$('#notice>.cnt').html(nts[name].cnt);
let tmp = '';
nts[name].btn.forEach(btn => {
tmp += `<a class="a btn ${btn.type}" onclick="${btn.js}">${btn.text}</a>`;
});
$('#notice>.btns').html(tmp);
$('#notice-back').addClass('show');
setTimeout(() => {
$('#notice').addClass('show');
}, 200);
}
function closenotice() {
$('#notice').removeClass('show');
setTimeout(() => {
$('#notice-back').removeClass('show');
}, 200);
}
function closeVideo() {
var video = apps.camera.video
if (video) {
try {
var stream = video.srcObject;
var tracks = stream.getTracks();
tracks.forEach(function (track) {
track.stop();
});
video.srcObject = null;
} catch (error) {}
}
}
var shutdown_task = []; //关机任务,储存在这个数组里
// 为什么要数组?
// 运行的指令
function runcmd(cmd, inTerminal=false) {
if (cmd.slice(0, 3) == 'cmd') {
run_cmd = cmd;
openapp('terminal');
return true;
}
else if (cmd in apps) {
openapp(cmd);
return true;
}
else if (cmd.replace('.exe', '') in apps) {
openapp(cmd.replace('.exe', ''));
return true;
}
else if (cmd.includes('shutdown')) {//关机指令
run_cmd = cmd;
var cmds = cmd.split(' ');
if ((cmds[0] == 'shutdown') || (cmds[0] == 'shutdown.exe')) { //帮助
if (cmds.length == 1) {
if(!inTerminal){
openapp('terminal');
$('#win-terminal').html('<pre class="text-cmd"></pre>');
}
$('#win-terminal>.text-cmd').append(`
shutdown [-s] [-r] [-f] [-a] [-t time]
-s:关机
-r:重启
-f:注销
-a:取消之前的操作
-t time:指定在 time秒 后操作
其余不多做介绍了` + (inTerminal?'' : `
请按任意键继续. . .<input type="text" onkeydown="hidewin('terminal')"></input>`));
// 所以你是没事干吗?。。提示:github并不是以行数来计算贡献的哦 from @tjy-gitnub
$('#win-terminal>pre>input').focus();
}
else if (cmds.includes('-s') || cmds.includes('/s')) {//关机
if ((cmds.indexOf('-t') != -1 && cmd.length/*判断是否-t后有其他参数*/ >= cmds.indexOf('-t') + 2/*先加一,获取当下标是从1开始的时候的下标索引;再加一,获取下一项。配合数组.length使用*/) || (cmds.indexOf('/t') != -1 && cmd.length/*判断是否-t后有其他参数*/ >= cmds.indexOf('/t') + 2)) {
str = '';
if (cmds.includes('-t')) { str = '-t'; }
if (cmds.includes('/t')) { str = '/t'; }
if (!isNaN(cmds[cmds.indexOf(str) + 1]/*这里只加一是因为下标是从0开始的*/)) {
num = parseInt(cmds[cmds.indexOf(str) + 1]);
nts['shutdown'] = {
cnt: `
<p class="tit">即将注销你的登录</p>
<p>Windows 将在 ` + calcTimeString(num) + ' 后关闭。</p>', // 如果必须原生样式的,建议改为 num<60 ? 1 : Math.floor(num / 60) + ` 分钟后关闭。</p>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' },
]
};
shutdown_task[shutdown_task.length] = setTimeout('window.location.href = \'./shutdown.html\'', num * 1000);
if (!(cmds.includes('/f') || cmds.includes('-f'))) {
shownotice('shutdown');
}
}
}
}
else if (cmds.includes('-r') || cmds.includes('/r')) {//重启
if ((cmds.indexOf('-t') != -1 && cmd.length >= cmds.indexOf('-t') + 2) || (cmds.indexOf('/t') != -1 && cmd.length >= cmds.indexOf('/t') + 2)) {/*详见上面的注释*/
str = '';
if (cmds.includes('-t')) { str = '-t'; }
if (cmds.includes('/t')) { str = '/t'; }
if (!isNaN(cmds[cmds.indexOf(str) + 1])) {
num = parseInt(cmds[cmds.indexOf(str) + 1]);
nts['shutdown'] = {
cnt: `
<p class="tit">即将注销你的登录</p>
<p>Windows 将在 ` + calcTimeString(num) + ' 后关闭。</p>', // 如果必须原生样式的,建议改为 num<60 ? 1 : Math.floor(num / 60) + ` 分钟后关闭。</p>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' },
]
};
shutdown_task[shutdown_task.length] = setTimeout('window.location.href = \'./reload.html\'', num * 1000);
if (!(cmds.includes('/f') || cmds.includes('-f'))) {
shownotice('shutdown');
}
}
}
}
else if (cmds.includes('-a') || cmds.includes('/a')) {//取消电源操作
if (shutdown_task.length > 0) {
for (var i = 0; i < shutdown_task.length; i++) {
if (shutdown_task[i] != null) {
try {
clearTimeout(shutdown_task[i]);
} catch (err) { console.log(err); }
shutdown_task[i] = null;
}
}
nts['shutdown'] = {
cnt: `
<p class="tit">注销已取消</p>
<p>计划的关闭已取消。</p>`,
btn: [
{ type: 'main', text: '关闭', js: 'closenotice();' },
]
};
shownotice('shutdown');
}
}
return true;
}
}
return false;
}
// 应用功能
let apps = {
setting: {
init: () => {
$('#win-setting>.menu>list>a.home')[0].click();
$('#win-setting>.page>.cnt.update>.setting-list>div:last-child>.alr>a.checkbox')[localStorage.getItem('autoUpdate') == 'true' ? 'addClass' : 'removeClass']('checked');
apps.setting.checkUpdate();
},
page: (name) => {
$('#win-setting>.page>.cnt.' + name).scrollTop(0);
$('#win-setting>.page>.cnt.show').removeClass('show');
$('#win-setting>.page>.cnt.' + name).addClass('show');
$('#win-setting>.menu>list>a.check').removeClass('check');
$('#win-setting>.menu>list>a.' + name).addClass('check');
},
theme_get: () => {
$('#set-theme').html(`<loading><svg width="30px" height="30px" viewBox="0 0 16 16">
<circle cx="8px" cy="8px" r="7px" style="stroke:#7f7f7f50;fill:none;stroke-width:3px;"></circle>
<circle cx="8px" cy="8px" r="7px" style="stroke:#2983cc;stroke-width:3px;"></circle></svg></loading>`);
// 实时获取主题
$.get('https://api.github.com/repos/tjy-gitnub/win12-theme/contents').then(cs => {
cs.forEach(c => {
if (c.type == 'dir') {
$.get(c.url).then(cnt => {
$('#set-theme').html('');
cnt.forEach(cn => {
if (cn.name == 'theme.json') {
$.getJSON('https://tjy-gitnub.github.io/win12-theme/' + cn.path).then(inf => {
infjs = inf;
if ($('#set-theme>loading').length)
$('#set-theme').html('');
$('#set-theme').append(`<a class="a act" onclick="apps.setting.theme_set('${c.name}')" style="background-image:url('https://tjy-gitnub.github.io/win12-theme/${c.name}/view.jpg')">${c.name}</a>`);
});
}
});
});
}
});
});
},
theme_set: (infp) => {
$.get('https://api.github.com/repos/tjy-gitnub/win12-theme/contents/' + infp).then(cnt => {
console.log('https://api.github.com/repos/tjy-gitnub/win12-theme/contents/' + infp);
cnt.forEach(cn => {
if (cn.name == 'theme.json') {
$.getJSON('https://tjy-gitnub.github.io/win12-theme/' + cn.path).then(inf => {
infjs = inf;
cnt.forEach(fbg => {
console.log(fbg, infjs);
if (fbg.name == infjs.bg) {
$(':root').css('--bgul', `url('https://tjy-gitnub.github.io/win12-theme/${fbg.path}')`);
$(':root').css('--theme-1', infjs.color1);
$(':root').css('--theme-2', infjs.color2);
$(':root').css('--href', infjs.href);
// $('#set-theme').append(`<a class="a act" onclick="apps.setting.theme_set(\`(${inf})\`)" style="background-image:url('https://tjy-gitnub.github.io/win12-theme/${fbg.path}')">${c.name}</a>`);
}
});
});
}
});
});
},
// 无法正常运行,待调试
checkUpdate: () => {
$('#win-setting>.page>.cnt.update>.lo>.update-main .notice')[0].innerText = '正在检查更新...';
$('#win-setting>.page>.cnt.update>.lo>.update-main .detail')[0].innerHTML = ' ';
$('#win-setting>.page>.cnt.update>.setting-list>.update-now').addClass('disabled');
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:first-child')[0].innerText = '正在检查更新...';
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:last-child')[0].innerHTML = ' ';
$('#win-setting>.page>.cnt.update>.lo>.update-main>div:last-child').addClass('disabled');
api('repos/tjy-gitnub/win12/commits').then(res => {
res.json().then(json => {
const sha = localStorage.getItem('sha');
if (sha != json[0].sha) {
let msg = json[0].commit.message.split('\n\n')[0];
if (msg.match(/v[0-9]*\.[0-9]*\.[0-9]*/)) {
msg = msg.match(/v[0-9]*\.[0-9]*\.[0-9]*/)[0];
window.setTimeout(() => {
$('#win-setting>.page>.cnt.update>.lo>.update-main .notice')[0].innerText = 'Windows 12 有更新可用';
$('#win-setting>.page>.cnt.update>.lo>.update-main .detail')[0].innerText = `目前最新版本: ${msg}`;
$('#win-setting>.page>.cnt.update>.lo>.update-main>div:last-child').removeClass('disabled');
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:first-child')[0].innerText = '更新已就绪';
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:last-child')[0].innerText = msg;
$('#win-setting>.page>.cnt.update>.setting-list>.update-now').removeClass('disabled');
}, 6000);
}
else {
window.setTimeout(() => {
let da = new Date();
$('#win-setting>.page>.cnt.update>.lo>.update-main .notice')[0].innerText = 'Windows 12 目前是最新版本';
$('#win-setting>.page>.cnt.update>.lo>.update-main .detail')[0].innerText = `上次检查时间: ${da.toLocaleDateString()},${da.toLocaleTimeString()}`;
$('#win-setting>.page>.cnt.update>.lo>.update-main>div:last-child').removeClass('disabled');
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:first-child')[0].innerText = '无更新可用';
$('#win-setting>.page>.cnt.update>.setting-list>.update-now>div>p:last-child')[0].innerText = 'Windows 12 目前是最新版本';
}, 6000);
}
}
});
});
}
},
msstore: {
init: () => {
$('#win-msstore>.menu>list>a.home')[0].click();
},
page: (name) => {
$('#win-msstore>.page>.cnt.' + name).scrollTop(0);
$('#win-msstore>.page>.cnt.show').removeClass('show');
$('#win-msstore>.page>.cnt.' + name).addClass('show');
$('#win-msstore>.menu>list>a.check').removeClass('check');
$('#win-msstore>.menu>list>a.' + name).addClass('check');
}
},
run: {
init: () => {
$('#win-run>.open>input').val(run_cmd); //在windows中,运行输入的内容会被保留
window.setTimeout(() => {
$('#win-run>.open>input').focus();
$('#win-run>.open>input').select();
}, 300);
},
run: (cmd) => {
if (!runcmd(cmd)) {
if (cmd != '') {
try {
cmd = cmd.replace(/\/$/, '');