-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXbox CLoud Gaming优化整合.user.js
4454 lines (3840 loc) · 162 KB
/
Xbox CLoud Gaming优化整合.user.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
// ==UserScript==
// @name Xbox CLoud Gaming优化整合
// @name:zh-CN Xbox CLoud Gaming优化整合
// @namespace https://greasyfork.org/scripts/455741
// @version 3.10.3.3
// @author 奈非天
// @license MIT
// @match https://www.xbox.com/*/*play*
// @run-at document-start
// @grant none
// @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.4.1/jquery.min.js
// @description:zh-cn 脚本免费!谨防上当受骗!整合和修改现有脚本,优化项详见脚本说明。【若你有好的想法或者BUG可以进xbox云游戏QQ交流1群531602832,2群313340764,3群826510890,4群82737876反馈】
// @description 脚本免费!谨防上当受骗!整合和修改现有脚本,优化项详见脚本说明。【若你有好的想法或者BUG可以进xbox云游戏QQ交流1群531602832,2群313340764,3群826510890,4群82737876反馈】
// ==/UserScript==
(function () {
'use strict';
// Your code here...
//★★★★★★★★★★★★★★★★★★★★Reference Project License Agreement Begin 参考项目许可协议开始★★★★★★★★★★★★★★★★★★★★//
/* better-xcloud MIT License
Copyright (c) 2023 redphx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//★★★★★★★★★★★★★★★★★★★★Reference Project License Agreement End 参考项目许可协议结束★★★★★★★★★★★★★★★★★★★★//
let nftxboxversion = 'v3.10.3.3';
let naifeitian = {
isType(obj) {
return Object.prototype.toString.call(obj).replace(/^\[object (.+)\]$/, '$1').toLowerCase();
},
getValue(key) {
try {
return JSON.parse(localStorage.getItem(key));
} catch (e) {
return localStorage.getItem(key);
}
},
setValue(key, value) {
if (this.isType(value) === 'object' || this.isType(value) === 'array' || this.isType(value) === 'boolean') {
return localStorage.setItem(key, JSON.stringify(value));
}
return localStorage.setItem(key, value);
},
isValidIP(ip) {
let reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
return reg.test(ip);
},
isNumber(val) {
return !isNaN(parseFloat(val)) && isFinite(val);
},
toElement(key, onChange) {
const CE = createElement;
const setting = key;
const currentValue = key['default'] == undefined ? key : key['default'];
let $control;
if (setting['options'] != undefined) {
$control = CE('select', { id: 'xcloud_setting_' + key['name'] });
for (let value in setting.options) {
const label = setting.options[value];
const $option = CE('option', { value: value }, label);
$control.appendChild($option);
}
$control.value = currentValue;
$control.addEventListener('change', e => {
key['default'] = e.target.value;
this.setValue(key['name'], key);
onChange && onChange(e);
});
} else if (typeof setting.default === 'number') {
$control = CE('input', { 'type': 'number', 'min': setting.min, 'max': setting.max });
$control.value = currentValue;
$control.addEventListener('change', e => {
let value = Math.max(setting.min, Math.min(setting.max, parseInt(e.target.value)));
e.target.value = value;
key['default'] = e.target.value
this.setValue(key['name'], key);
onChange && onChange(e);
});
} else {
if (key.fps == undefined) {
$control = CE('input', { 'type': 'checkbox' });
$control.checked = currentValue;
$control.addEventListener('change', e => {
key['default'] = e.target.checked;
NFTconfig[key['name'].slice(0, -2)]['default'] = e.target.checked;
this.setValue(key['name'], key);
if (key['name'] == 'STATS_SLIDE_OPENGM' && e.target.checked) {
if (this.getValue('STATS_SHOW_WHEN_PLAYINGGM')['default']) {
$('#xcloud_setting_STATS_SHOW_WHEN_PLAYINGGM').click();
}
} else if (key['name'] == 'STATS_SHOW_WHEN_PLAYINGGM' && e.target.checked) {
if (this.getValue('STATS_SLIDE_OPENGM')['default']) {
$('#xcloud_setting_STATS_SLIDE_OPENGM').click();
}
}
onChange && onChange(e);
});
} else {
let stats_info_sortedEntries = Object.entries(NFTconfig['stats_info']).sort((a, b) => a[1][1] - b[1][1]);
//流统计信息
$control = CE('div', { 'class': 'stats-container' });
stats_info_sortedEntries.forEach(entry => {
//entry[1][0] 是否选中
//entry[1][1] 顺序
//entry[1][2] 名字
let divElement = document.createElement('div');
divElement.className = `drag-handle ${entry[1][0] === true ? 'stats-selected' : 'stats-delete'}`;
divElement.draggable = "true";
divElement.dataset.name = entry[0];
divElement.dataset.index = entry[1][1];
divElement.textContent = entry[1][2];
let dragIndicator = document.createElement('div');
dragIndicator.className = "drag-indicator";
divElement.appendChild(dragIndicator);
$control.appendChild(divElement);
});
let placeholder = document.createElement('div');
placeholder.className = "placeholder drag-handle";
$control.appendChild(placeholder);
}
}
$control.id = `xcloud_setting_${key.name}`;
return $control;
},
isSafari() {
let userAgent = userAgentOriginal.toLowerCase();
if (userAgent.indexOf('safari') !== -1 && userAgent.indexOf('chrome') === -1) {
return true;
} else {
return false;
}
},
getGM(defaultValue, n) {
let newval = this.getValue(n) == null ? defaultValue : this.getValue(n);
if (newval?.options != undefined) {
newval.options = defaultValue.options;
}
naifeitian.setValue(n, newval);
return newval;
},
showSetting() {
$('#settingsBackgroud').css('display', '');
$('body').css('overflow', 'hidden');
},
hideSetting() {
$('#settingsBackgroud').css('display', 'none');
$('body').css('overflow', 'visible');
},
patchFunctionBind() {
const nativeBind = Function.prototype.bind;
Function.prototype.bind = function () {
let valid = false;
if (this.name.length <= 2 && arguments.length === 2 && arguments[0] === null) {
if (arguments[1] === 0 || (typeof arguments[1] === 'function')) {
valid = true;
}
}
if (!valid) {
return nativeBind.apply(this, arguments);
}
if (typeof arguments[1] === 'function') {
console.log('还原 Function.prototype.bind()');
Function.prototype.bind = nativeBind;
}
const orgFunc = this;
const newFunc = (a, item) => {
if (NFTconfig['PATCH_ORDERS'].length === 0) {
orgFunc(a, item);
return;
}
naifeitian.patch(item);
orgFunc(a, item);
}
return nativeBind.apply(newFunc, arguments);
};
},
patch(item) {
// console.log('patch', '-----');
let patchName;
let appliedPatches;
for (let id in item[1]) {
if (NFTconfig['PATCH_ORDERS'].length <= 0) {
return;
}
appliedPatches = [];
const func = item[1][id];
let funcStr = func.toString();
for (let groupIndex = 0; groupIndex < NFTconfig['PATCH_ORDERS'].length; groupIndex++) {
const group = NFTconfig['PATCH_ORDERS'][groupIndex];
let modified = false;
for (let patchIndex = 0; patchIndex < group.length; patchIndex++) {
const patchName = group[patchIndex];
if (appliedPatches.indexOf(patchName) > -1) {
continue;
}
const patchedFuncStr = naifeitian.handle_remote_patch(patchName, funcStr);
if (!patchedFuncStr) {
// Only stop if the first patch is failed
if (patchIndex === 0) {
break;
} else {
continue;
}
}
modified = true;
funcStr = patchedFuncStr;
console.log(`应用 "${patchName}" 修补`);
appliedPatches.push(patchName);
// Remove patch from group
group.splice(patchIndex, 1);
patchIndex--;
}
// Apply patched functions
if (modified) {
item[1][id] = eval(funcStr);
}
// Remove empty group
if (!group.length) {
NFTconfig['PATCH_ORDERS'].splice(groupIndex, 1);
groupIndex--;
}
}
}
},
handle_remote_patch(name, funcStr) {
//根据不同的字符串执行不同的方法
if (name == 'remotePlayConnectMode') {
const text = 'connectMode:"cloud-connect"';
if (!funcStr.includes(text)) {
return false;
}
return funcStr.replace(text, `connectMode:window.BX_REMOTE_PLAY_CONFIG?"xhome-connect":"cloud-connect",remotePlayServerId:(window.BX_REMOTE_PLAY_CONFIG&&window.BX_REMOTE_PLAY_CONFIG.serverId)||''`);
} else if (name == 'remotePlayDirectConnectUrl') {
const index = funcStr.indexOf('/direct-connect');
if (index === -1) {
return false;
}
return funcStr.replace(funcStr.substring(index - 9, index + 15), 'https://www.xbox.com/play');
} else if (name == 'remotePlayKeepAlive') {
if (!funcStr.includes('onServerDisconnectMessage(e){')) {
return false;
}
funcStr = funcStr.replace('onServerDisconnectMessage(e){', `onServerDisconnectMessage (e) {
const msg = JSON.parse(e);
if (msg.reason === 'WarningForBeingIdle') {
try {
this.sendKeepAlive();
return;
} catch (ex) {}
}
`);
return funcStr;
} else if (name == 'EnableStreamGate') {
const index = funcStr.indexOf(',EnableStreamGate:');
if (index === -1) {
return false;
}
// Find the next "},"
const endIndex = funcStr.indexOf('},', index);
const newCode = `
EnableStreamGate: false,
PwaPrompt: false,
`;
funcStr = funcStr.substring(0, endIndex) + ',' + newCode + funcStr.substring(endIndex);
return funcStr;
} else if (name == 'remotePlayGuideWorkaround') {
const text = 'nexusButtonHandler:this.featureGates.EnableClientGuideInStream';
if (!funcStr.includes(text)) {
return false;
}
return funcStr.replace(text, `nexusButtonHandler: !window.BX_REMOTE_PLAY_CONFIG && this.featureGates.EnableClientGuideInStream`);
} else if (name == 'patchStreamHud') {
const text = 'let{onCollapse';
if (!funcStr.includes(text)) {
return false;
}
// 恢复悬浮窗 "..." 按钮
funcStr = funcStr.replace(text, 'e.guideUI = null;' + text);
return funcStr;
} else if (name == "loadingEndingChunks") {
// Add patches that are only needed when start playing
const text = 'Symbol("ChatSocketPlugin")';
if (!funcStr.includes(text)) {
return false;
}
NFTconfig['PATCH_ORDERS'] = NFTconfig['PATCH_ORDERS'].concat(NFTconfig['PLAYING_PATCH_ORDERS']);
return funcStr;
}
},
isDivTopOrBottomOutOfBounds(divElement) {
const $div = $(divElement);
$div.css("height","")
// 获取div的边界信息
const divRect = $div[0].getBoundingClientRect();
const divTop = divRect.top;
const divBottom = divRect.bottom;
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
return (
divBottom > viewportHeight ||
divTop < 0
);
}
}
//★★ 1=开 0=关 ★★//
let default_language_list = { '智能简繁': 'Auto', '简体': 'zh-CN', '繁体': 'zh-TW' }
let NFTconfig =
{
enableRemotePlay: 0,
PATCH_ORDERS: [],
PLAYING_PATCH_ORDERS: [],
no_need_VPN_play: 1,
regionBlock: {
blockIp: '美服',
options: {
'韩服': '168.126.63.1',
'美服': '4.2.2.2',
'日服': '210.131.113.123'
}
},
chooseLanguage: 1,
IfErrUsedefaultGameLanguage: 'zh-CN',
high_bitrate: 1,
disableCheckNetwork: 1,
IPv6: 0,
autoFullScreen: 0,
blockXcloudServer: 0,
blockXcloudServerList: ['AustraliaEast', 'AustraliaSouthEast', 'BrazilSouth', 'EastUS', 'EastUS2', 'JapanEast', 'KoreaCentral', 'NorthCentralUs', 'SouthCentralUS', 'UKSouth', 'WestEurope', 'WestUS', 'WestUS2'],
defaultXcloudServer: 'KoreaCentral',
video_stretch: {
default: 'none',
options: {
none: '无',
fill: '填充',
setting: '微调'
},
name: 'video_stretchGM'
},
rtcCodecPreferences: {
default: '自动',
options: [
'默认',
'自动'
]
},
video_stretch_x_y: {
x: 0,
y: 0,
name: 'video_stretch_x_yGM'
},
noPopSetting: 0,
disableTouchControls: 0,
autoOpenOC: 1,
autoShowTouch: true,
STATS_SHOW_WHEN_PLAYING: {
default: false,
name: 'STATS_SHOW_WHEN_PLAYINGGM'
},
STATS_POSITION: {
default: 'top-left',
options: {
'top-left': '上左',
'top-center': '上中',
'top-right': '上右'
},
name: 'STATS_POSITIONGM'
},
STATS_TRANSPARENT: {
default: false,
name: 'STATS_TRANSPARENTGM'
},
STATS_OPACITY: {
default: 80,
min: 10,
max: 100,
name: 'STATS_OPACITYGM'
},
STATS_TEXT_SIZE: {
default: '0.9rem',
options: {
'0.9rem': '小',
'1.0rem': '中',
'1.1rem': '大'
},
name: 'STATS_TEXT_SIZEGM'
},
STATS_CONDITIONAL_FORMATTING: {
default: false,
name: 'STATS_CONDITIONAL_FORMATTINGGM'
},
STATS_SLIDE_OPEN: {
default: false,
name: 'STATS_SLIDE_OPENGM'
},
VIDEO_CLARITY: {
default: 0,
min: 0,
max: 3,
name: 'VIDEO_CLARITYGM'
},
VIDEO_CONTRAST: {
default: 100,
min: 0,
max: 150,
name: 'VIDEO_CONTRASTGM'
},
VIDEO_SATURATION: {
default: 100,
min: 0,
max: 150,
name: 'VIDEO_SATURATIONGM'
},
VIDEO_BRIGHTNESS: {
default: 100,
min: 0,
max: 150,
name: 'VIDEO_BRIGHTNESSGM'
},
antiKick: 0,
useCustomfakeIp: 0,
customfakeIp: '',
xcloud_game_language: default_language_list['简体'],
REMOTE_PLAY_RESOLUTION: {
'default': '1080p',
'options': {
'1080p': '1080p',
'720p': '720p',
},
'name': 'REMOTE_PLAY_RESOLUTIONGM'
},
REMOTE_SERVER_LIST: ['eau', 'seau', 'brs', 'eus', 'eus2', 'ejp', 'ckr', 'mxc', 'ncus', 'scus', 'uks', 'weu', 'wus', 'wus2'],
stats_info: {
fps: [true, 1, "帧率"],
rtt: [true, 2, "延迟"],
dt: [true, 3, "解码"],
br: [true, 4, "码率"],
pl: [true, 5, "丢包"],
fl: [true, 6, "丢帧"],
}
}
const integratekeys = Object.keys(NFTconfig);
integratekeys.forEach(key => {
NFTconfig[key] = naifeitian.getGM(NFTconfig[key], key + 'GM');
});
NFTconfig['PATCH_ORDERS'] = [
NFTconfig['enableRemotePlay'] == 1 && ['remotePlayKeepAlive'],
NFTconfig['enableRemotePlay'] == 1 && ['remotePlayDirectConnectUrl'],
];
NFTconfig['PATCH_ORDERS'] = [
NFTconfig['enableRemotePlay'] == 1 && ['remotePlayConnectMode'],
NFTconfig['enableRemotePlay'] == 1 && ['remotePlayGuideWorkaround'],
['patchStreamHud'],
['EnableStreamGate']
]
let regionsMenuItemList = [];
let languageMenuItemList = [];
let crturl = "";
let canShowOC = null;
let letmeOb = true;
let checkIpsuc = false;
let STREAM_WEBRTC;
const ICON_VIDEO_SETTINGS = '<path d="M16 9.144A6.89 6.89 0 0 0 9.144 16 6.89 6.89 0 0 0 16 22.856 6.89 6.89 0 0 0 22.856 16 6.9 6.9 0 0 0 16 9.144zm0 11.427c-2.507 0-4.571-2.064-4.571-4.571s2.064-4.571 4.571-4.571 4.571 2.064 4.571 4.571-2.064 4.571-4.571 4.571zm15.704-7.541c-.065-.326-.267-.607-.556-.771l-4.26-2.428-.017-4.802c-.001-.335-.15-.652-.405-.868-1.546-1.307-3.325-2.309-5.245-2.953-.306-.103-.641-.073-.923.085L16 3.694l-4.302-2.407c-.282-.158-.618-.189-.924-.086a16.02 16.02 0 0 0-5.239 2.964 1.14 1.14 0 0 0-.403.867L5.109 9.84.848 12.268a1.14 1.14 0 0 0-.555.771 15.22 15.22 0 0 0 0 5.936c.064.326.267.607.555.771l4.261 2.428.017 4.802c.001.335.149.652.403.868 1.546 1.307 3.326 2.309 5.245 2.953.306.103.641.073.923-.085L16 28.306l4.302 2.407a1.13 1.13 0 0 0 .558.143 1.18 1.18 0 0 0 .367-.059c1.917-.648 3.695-1.652 5.239-2.962.255-.216.402-.532.405-.866l.021-4.807 4.261-2.428a1.14 1.14 0 0 0 .555-.771 15.21 15.21 0 0 0-.003-5.931zm-2.143 4.987l-4.082 2.321a1.15 1.15 0 0 0-.429.429l-.258.438a1.13 1.13 0 0 0-.174.601l-.022 4.606a13.71 13.71 0 0 1-3.623 2.043l-4.117-2.295a1.15 1.15 0 0 0-.559-.143h-.546c-.205-.005-.407.045-.586.143l-4.119 2.3a13.74 13.74 0 0 1-3.634-2.033l-.016-4.599a1.14 1.14 0 0 0-.174-.603l-.257-.437c-.102-.182-.249-.333-.429-.437l-4.085-2.328a12.92 12.92 0 0 1 0-4.036l4.074-2.325a1.15 1.15 0 0 0 .429-.429l.258-.438a1.14 1.14 0 0 0 .175-.601l.021-4.606a13.7 13.7 0 0 1 3.625-2.043l4.11 2.295a1.14 1.14 0 0 0 .585.143h.52c.205.005.407-.045.586-.143l4.119-2.3a13.74 13.74 0 0 1 3.634 2.033l.016 4.599a1.14 1.14 0 0 0 .174.603l.257.437c.102.182.249.333.429.438l4.085 2.327a12.88 12.88 0 0 1 .007 4.041h.007z" fill-rule="nonzero"/>';
//视频调整
const ICON_HD_VIDEO_SETTINGS = '<g transform="matrix(.142357 0 0 .142357 -2.22021 -2.22164)" fill="none" stroke="#fff" stroke-width="16"><circle cx="128" cy="128" r="40"/><path d="M130.05 206.11h-4L94 224c-12.477-4.197-24.049-10.711-34.11-19.2l-.12-36c-.71-1.12-1.38-2.25-2-3.41L25.9 147.24a99.16 99.16 0 0 1 0-38.46l31.84-18.1c.65-1.15 1.32-2.29 2-3.41l.16-36C69.951 42.757 81.521 36.218 94 32l32 17.89h4L162 32c12.477 4.197 24.049 10.711 34.11 19.2l.12 36c.71 1.12 1.38 2.25 2 3.41l31.85 18.14a99.16 99.16 0 0 1 0 38.46l-31.84 18.1c-.65 1.15-1.32 2.29-2 3.41l-.16 36A104.59 104.59 0 0 1 162 224l-31.95-17.89z"/></g>';
//流监控
const ICON_HD_STREAM_STATS = '<g transform="scale(2)" class="ICON_HD_STREAM_STATS_OFF" style="display:block"><path d="M13.359 11.238C15.06 9.72 16 8 16 8s-3-5.5-8-5.5a7 7 0 0 0-2.79.588l.77.771A6 6 0 0 1 8 3.5c2.12 0 3.879 1.168 5.168 2.457A13 13 0 0 1 14.828 8q-.086.13-.195.288c-.335.48-.83 1.12-1.465 1.755q-.247.248-.517.486z"></path><path d="M11.297 9.176a3.5 3.5 0 0 0-4.474-4.474l.823.823a2.5 2.5 0 0 1 2.829 2.829zm-2.943 1.299.822.822a3.5 3.5 0 0 1-4.474-4.474l.823.823a2.5 2.5 0 0 0 2.829 2.829"></path><path d="M3.35 5.47q-.27.24-.518.487A13 13 0 0 0 1.172 8l.195.288c.335.48.83 1.12 1.465 1.755C4.121 11.332 5.881 12.5 8 12.5c.716 0 1.39-.133 2.02-.36l.77.772A7 7 0 0 1 8 13.5C3 13.5 0 8 0 8s.939-1.721 2.641-3.238l.708.709zm10.296 8.884-12-12 .708-.708 12 12z"></path></g><g transform="scale(2)" class="ICON_HD_STREAM_STATS_ON" style="display:none"><path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8M1.173 8a13 13 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5s3.879 1.168 5.168 2.457A13 13 0 0 1 14.828 8q-.086.13-.195.288c-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5s-3.879-1.168-5.168-2.457A13 13 0 0 1 1.172 8z"/><path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5M4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0"/></g>';
// Quickly create a tree of elements without having to use innerHTML
function createElement(elmName, props = {}) {
let $elm;
const hasNs = 'xmlns' in props;
if (hasNs) {
$elm = document.createElementNS(props.xmlns, elmName);
} else {
$elm = document.createElement(elmName);
}
for (let key in props) {
if (key === 'xmlns') {
continue;
}
if (!props.hasOwnProperty(key) || $elm.hasOwnProperty(key)) {
continue;
}
if (hasNs) {
$elm.setAttributeNS(null, key, props[key]);
} else {
$elm.setAttribute(key, props[key]);
}
}
for (let i = 2, size = arguments.length; i < size; i++) {
const arg = arguments[i];
const argType = typeof arg;
if (argType === 'string' || argType === 'number') {
$elm.textContent = arg;
} else if (arg) {
$elm.appendChild(arg);
}
}
return $elm;
}
function setMachineFullScreen() {
try {
let element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen();
}
screen?.orientation?.lock("landscape");
} catch (e) {
}
}
function exitMachineFullscreen() {
try {
screen?.orientation?.unlock();
if (document.exitFullScreen) {
document.exitFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (element.msExitFullscreen) {
element.msExitFullscreen();
}
} catch (e) {
}
}
function exitGame() {
canShowOC = null;
setTimeout(RemotePlay.detect, 10);
document.documentElement.style.overflowY = "";
StreamStats.hideSettingsUi();
letmeOb = true;
StreamStats.stop();
bindmslogoevent();
$('.better-xcloud-quick-settings-bar').css("display", "none");
if (NFTconfig['autoFullScreen'] == 1) {
exitMachineFullscreen();
}
if (NFTconfig['noPopSetting'] == 0) {
$('#popSetting').css('display', 'block');
}
}
function inGame() {
if (!IS_REMOTE_PLAYING) {
let path = window.location.pathname;
history.pushState({}, null, window.location.pathname.substr(0, window.location.pathname.indexOf("/launch/")));
history.pushState({}, null, path);
}
document.documentElement.style.overflowY = "hidden";
document.body.style.top = '0px';
if (NFTconfig['autoFullScreen'] == 1) {
setMachineFullScreen();
}
if (NFTconfig['noPopSetting'] == 0) {
$('#popSetting').css('display', 'none');
}
}
class StreamBadges {
static get BADGE_PLAYTIME() { return '游玩时间'; };
static get BADGE_BATTERY() { return '电量'; };
static get BADGE_IN() { return '下载'; };
static get BADGE_OUT() { return '上传'; };
static get BADGE_SERVER() { return '服务器'; };
static get BADGE_VIDEO() { return '编解码器'; };
static get BADGE_AUDIO() { return '音频'; };
static get BADGE_BREAK() { return 'break'; };
static ipv6 = false;
static resolution = null;
static video = null;
static audio = null;
static fps = 0;
static region = '';
static startBatteryLevel = 100;
static startTimestamp = 0;
static #cachedDoms = {};
static #interval;
static get #REFRESH_INTERVAL() { return 3000; };
static #renderBadge(name, value, color) {
const CE = createElement;
if (name === StreamBadges.BADGE_BREAK) {
return CE('div', { 'style': 'display: block' });
}
let $badge;
if (StreamBadges.#cachedDoms[name]) {
$badge = StreamBadges.#cachedDoms[name];
$badge.lastElementChild.textContent = value;
return $badge;
}
$badge = CE('div', { 'class': 'better-xcloud-badge' },
CE('span', { 'class': 'better-xcloud-badge-name' }, name),
CE('span', { 'class': 'better-xcloud-badge-value', 'style': `background-color: ${color}` }, value));
if (name === StreamBadges.BADGE_BATTERY) {
$badge.classList.add('better-xcloud-badge-battery');
}
StreamBadges.#cachedDoms[name] = $badge;
return $badge;
}
static async #updateBadges(forceUpdate) {
if (!forceUpdate && !document.querySelector('.better-xcloud-badges')) {
StreamBadges.#stop();
return;
}
// 游玩时间
let now = +new Date;
const diffSeconds = Math.ceil((now - StreamBadges.startTimestamp) / 1000);
const playtime = StreamBadges.#secondsToHm(diffSeconds);
// 电量
let batteryLevel = '100%';
let batteryLevelInt = 100;
let isCharging = false;
if (navigator.getBattery) {
try {
const bm = await navigator.getBattery();
isCharging = bm.charging;
batteryLevelInt = Math.round(bm.level * 100);
batteryLevel = `${batteryLevelInt}%`;
if (batteryLevelInt != StreamBadges.startBatteryLevel) {
const diffLevel = Math.round(batteryLevelInt - StreamBadges.startBatteryLevel);
const sign = diffLevel > 0 ? '+' : '';
batteryLevel += ` (${sign}${diffLevel}%)`;
}
} catch (e) { }
}
const stats = await STREAM_WEBRTC.getStats();
let totalIn = 0;
let totalOut = 0;
stats.forEach(stat => {
if (stat.type === 'candidate-pair' && stat.state == 'succeeded') {
totalIn += stat.bytesReceived;
totalOut += stat.bytesSent;
}
});
const badges = {
[StreamBadges.BADGE_IN]: totalIn ? StreamBadges.#humanFileSize(totalIn) : null,
[StreamBadges.BADGE_OUT]: totalOut ? StreamBadges.#humanFileSize(totalOut) : null,
[StreamBadges.BADGE_PLAYTIME]: playtime,
[StreamBadges.BADGE_BATTERY]: batteryLevel,
};
for (let name in badges) {
const value = badges[name];
if (value === null) {
continue;
}
const $elm = StreamBadges.#cachedDoms[name];
$elm && ($elm.lastElementChild.textContent = value);
if (name === StreamBadges.BADGE_BATTERY) {
// Show charging status
$elm.setAttribute('data-charging', isCharging);
if (StreamBadges.startBatteryLevel === 100 && batteryLevelInt === 100) {
$elm.style.display = 'none';
} else {
$elm.style = '';
}
}
}
}
static #stop() {
StreamBadges.#interval && clearInterval(StreamBadges.#interval);
StreamBadges.#interval = null;
}
static #secondsToHm(seconds) {
const h = Math.floor(seconds / 3600);
const m = Math.floor(seconds % 3600 / 60) + 1;
const hDisplay = h > 0 ? `${h}小时` : '';
const mDisplay = m > 0 ? `${m}分钟` : '';
return hDisplay + mDisplay;
}
// https://stackoverflow.com/a/20732091
static #humanFileSize(size) {
let i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}
static async render() {
// Video
let video = '';
if (StreamBadges.resolution) {
video = `${StreamBadges.resolution.height}p`;
}
if (StreamBadges.video) {
video && (video += '/');
video += StreamBadges.video.codec;
if (StreamBadges.video.profile) {
let profile = StreamBadges.video.profile;
profile = profile.startsWith('4d') ? '高' : (profile.startsWith('42e') ? '中' : '低');
video += ` (${profile})`;
}
}
// 音频
let audio;
if (StreamBadges.audio) {
audio = StreamBadges.audio.codec;
const bitrate = StreamBadges.audio.bitrate / 1000;
audio += ` (${bitrate} kHz)`;
}
// 电量
let batteryLevel = '';
if (navigator.getBattery) {
batteryLevel = '100%';
}
// Server + Region
let server = StreamBadges.region;
server += '@' + (StreamBadges.ipv6 ? 'IPv6' : 'IPv4');
const BADGES = [
[StreamBadges.BADGE_PLAYTIME, '1m', '#ff004d'],
[StreamBadges.BADGE_BATTERY, batteryLevel, '#00b543'],
[StreamBadges.BADGE_IN, StreamBadges.#humanFileSize(0), '#29adff'],
[StreamBadges.BADGE_OUT, StreamBadges.#humanFileSize(0), '#ff77a8'],
[StreamBadges.BADGE_BREAK],
[StreamBadges.BADGE_SERVER, server, '#ff6c24'],
video ? [StreamBadges.BADGE_VIDEO, video, '#742f29'] : null,
audio ? [StreamBadges.BADGE_AUDIO, audio, '#5f574f'] : null,
];
const $wrapper = createElement('div', { 'class': 'better-xcloud-badges' });
BADGES.forEach(item => item && $wrapper.appendChild(StreamBadges.#renderBadge(...item)));
await StreamBadges.#updateBadges(true);
StreamBadges.#stop();
StreamBadges.#interval = setInterval(StreamBadges.#updateBadges, StreamBadges.#REFRESH_INTERVAL);
return $wrapper;
}
}
class StreamStats {
static #interval;
static #updateInterval = 1000;
static #$container;
static #$fps;
static #$rtt;
static #$dt;
static #$pl;
static #$fl;
static #$br;
static #$settings;
static #lastStat;
static status() {
return StreamStats.#interval != null;
}
static start() {
clearInterval(StreamStats.#interval);
StreamStats.#$container.classList.remove('better-xcloud-gone');
StreamStats.#interval = setInterval(StreamStats.update, StreamStats.#updateInterval);
$('#xcloud_setting_STATS_BUTTON').text("关闭监控");
$('.ICON_HD_STREAM_STATS_ON').css("display", 'block');
$('.ICON_HD_STREAM_STATS_OFF').css("display", 'none');
}
static stop() {
clearInterval(StreamStats.#interval);
StreamStats.#$container.classList.add('better-xcloud-gone');
StreamStats.#interval = null;
StreamStats.#lastStat = null;
$('#xcloud_setting_STATS_BUTTON').text("启动监控");
$('.ICON_HD_STREAM_STATS_ON').css("display", 'none');
$('.ICON_HD_STREAM_STATS_OFF').css("display", 'block');
}
static toggle() {
StreamStats.#isHidden() ? StreamStats.start() : StreamStats.stop();
screenClicktohide();
if (naifeitian.isDivTopOrBottomOutOfBounds(".better-xcloud-stats-settings")) {
$(".better-xcloud-stats-settings").css("height", "90%");
} else {
$(".better-xcloud-stats-settings").css("height", "");
}
}
static #isHidden = () => StreamStats.#$container.classList.contains('better-xcloud-gone');
static update() {
if (StreamStats.#isHidden() || !STREAM_WEBRTC) {
StreamStats.stop();
return;
}
try {
STREAM_WEBRTC.getStats().then(stats => {
stats.forEach(stat => {
let grade = '';
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
// FPS
$(".stats_fps span").text(stat.framesPerSecond || 0);
// Packets Lost
const packetsLost = stat.packetsLost;
if (packetsLost != undefined) {
const packetsReceived = stat.packetsReceived;
const packetsLostPercentage = (packetsLost * 100 / ((packetsLost + packetsReceived) || 1)).toFixed(2);
$(".stats_pl span").text(`${packetsLost} (${packetsLostPercentage}%)`);
} else {
$(".stats_pl span").text(`-1 (-1%)`);
}
// Frames Dropped
const framesDropped = stat.framesDropped;
if (framesDropped != undefined) {
const framesReceived = stat.framesReceived;
const framesDroppedPercentage = (framesDropped * 100 / ((framesDropped + framesReceived) || 1)).toFixed(2);
$(".stats_fl span").text(`${framesDropped} (${framesDroppedPercentage}%)`);
} else {
$(".stats_fl span").text(`-1 (-1%)`);
}
if (StreamStats.#lastStat) {
const lastStat = StreamStats.#lastStat;
// Bitrate
const timeDiff = stat.timestamp - lastStat.timestamp;
const bitrate = 8 * (stat.bytesReceived - lastStat.bytesReceived) / timeDiff / 1000;
$(".stats_br span").text(`${bitrate.toFixed(2)} Mbps`);
// Decode time
const totalDecodeTimeDiff = stat.totalDecodeTime - lastStat.totalDecodeTime;
const framesDecodedDiff = stat.framesDecoded - lastStat.framesDecoded;
const currentDecodeTime = totalDecodeTimeDiff / framesDecodedDiff * 1000;
$(".stats_dt span").text(`${currentDecodeTime.toFixed(2)}ms`);
if (NFTconfig['STATS_CONDITIONAL_FORMATTING']['default']) {
grade = (currentDecodeTime > 12) ? 'bad' : (currentDecodeTime > 9) ? 'ok' : (currentDecodeTime > 6) ? 'good' : '';
}
$(".stats_dt span").attr('data-grade', grade);
}
StreamStats.#lastStat = stat;
} else if (stat.type === 'candidate-pair' && stat.state === 'succeeded') {
// Round Trip Time
const roundTripTime = typeof stat.currentRoundTripTime !== 'undefined' ? stat.currentRoundTripTime * 1000 : '???';
$(".stats_rtt span").text(`${roundTripTime}ms`);
if (NFTconfig['STATS_CONDITIONAL_FORMATTING']['default']) {
grade = (roundTripTime > 100) ? 'bad' : (roundTripTime > 75) ? 'ok' : (roundTripTime > 40) ? 'good' : '';
}
$(".stats_rtt span").attr('data-grade', grade);
}
});
});
} catch (e) { }
}
static #refreshStyles() {
const PREF_POSITION = NFTconfig['STATS_POSITION']['default'];
const PREF_TRANSPARENT = NFTconfig['STATS_TRANSPARENT']['default'];
const PREF_OPACITY = NFTconfig['STATS_OPACITY']['default'];
const PREF_TEXT_SIZE = NFTconfig['STATS_TEXT_SIZE']['default'];
StreamStats.#$container.setAttribute('data-position', PREF_POSITION);
StreamStats.#$container.setAttribute('data-transparent', PREF_TRANSPARENT);