// ==UserScript==
// @name Xbox CLoud Gaming优化整合v1.0.8
// @name:zh-CN Xbox CLoud Gaming优化整合v1.0.8
// @namespace http://tampermonkey.net/xbox/nft
// @version 1.0.8
// @description:zh-cn 整合和修改现有脚本,感谢@TGSAN,@刘翠两位大佬,该脚本支持ios,pc,安卓,,优化项:游戏语言简体繁体自动选择+免代理直连+safari免添加桌面+高码率+禁用低画质+隐藏滚动条+裸连网络中强制开启触屏控制+美化悬浮按钮的样式+自选服务器(不完善,未开放)。 【xbox云游戏交流群531602832】
// @author 奈非天
// @match https://www.xbox.com/*/play*
// @run-at document-start
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @original-script https://greasyfork.org/zh-CN/scripts/455741-xbox-cloud-gaming%E4%BC%98%E5%8C%96%E6%95%B4%E5%90%88
// @description 整合和修改现有脚本,感谢@TGSAN,@刘翠两位大佬,该脚本支持ios,pc,安卓,,优化项:游戏语言简体繁体自动选择+免代理直连+safari免添加桌面+高码率+禁用低画质+隐藏滚动条+裸连网络中强制开启触屏控制+美化悬浮按钮的样式+自选服务器(不完善,未开放)。 【xbox云游戏交流群531602832】
// ==/UserScript==
(function() {
'use strict';
// Your code here...
const originFetch = fetch;
let windowCtx = self.window;
if (self.unsafeWindow) {
console.log("使用unsafeWindow模式");
windowCtx = self.unsafeWindow;
} else {
console.log("使用原生模式");
}
windowCtx.fetch = (...arg) => {
let arg0 = arg[0];
let url = "";
let isRequest = false;
switch (typeof arg0) {
case "object":
url = arg0.url;
isRequest = true;
break;
case "string":
url = arg0;
break;
default:
break;
}
if (url.indexOf('xgpuweb.gssv-play-prod.xboxlive.com/v2/login/user') > -1){
console.log('xff欺骗开始'+url)
return new Promise((resolve, reject) => {
if (isRequest && arg0.method == "POST") {
arg0.json().then(json => {
let body = JSON.stringify(json);
arg[0].headers.set('x-forwarded-for','168.126.63.1')
arg[0] = new Request(url, {
method: arg0.method,
headers: arg0.headers,
body: body,
});
originFetch(...arg).then(res => {
console.log('xff欺骗结束')
console.log('修改服务器开始')
res.json().then(json => {
json["offeringSettings"]["allowRegionSelection"] = true;
if(1==2){
let newServerList = [];
let currentAutoServer;
let closedChinaServer=[];
json["offeringSettings"]["regions"].forEach((region) => {
newServerList.push(region["name"]);
if(region['name'].indexOf('Japan')>-1 || region['name'].indexOf('Korea')>-1){
closedChinaServer.push(region["name"]);
}
if (region["isDefault"] === true) {
currentAutoServer = region["name"];
}
});
let selectedServer=confirm("确定"+closedChinaServer[0]+",取消"+closedChinaServer[1]);
if(selectedServer){
selectedServer=closedChinaServer[0];
}else{
selectedServer=closedChinaServer[1];
}
if (selectedServer !== "Auto" && newServerList.includes(selectedServer)) {
json["offeringSettings"]["regions"].forEach((region) => {
if (region["name"] === selectedServer) {
region["isDefault"] = true;
} else {
region["isDefault"] = false;
}
});
}
}
let body = JSON.stringify(json);
let newRes = new Response(body, {
status: res.status,
statusText: res.statusText,
headers: res.headers
})
console.log('允许修改区域结束')
resolve(newRes);
}).catch(err => {
reject(err);
});
}).catch(err => {
reject(err);
});
});
} else {
console.error("[ERROR] Not a request.");
return originFetch(...arg);
}
});
}else if (url.indexOf('/v5/sessions/cloud/play') > -1) {
console.log('语言开始')
document.documentElement.style.overflowY = "hidden"
// Start Configuration
return new Promise(async(resolve, reject) => {
const regex = /\/([a-zA-Z0-9]+)\/?/gm;
let matches;
let latestMatch;
while ((matches = regex.exec(document.location.pathname)) !== null) {
if (matches.index === regex.lastIndex) {
regex.lastIndex++;
}
matches.forEach((match, groupIndex) => {
// console.log(`Found match, group ${groupIndex}: ${match}`);
latestMatch = match;
});
}
let selectedLanguage='zh-CN';
if (latestMatch) {
let pid = latestMatch;
try {
let res = await fetch(
"https://catalog.gamepass.com/products?market=US&language=en-US&hydration=PCInline", {
"headers": {
"content-type": "application/json;charset=UTF-8",
},
"body": "{\"Products\":[\"" + pid + "\"]}",
"method": "POST",
"mode": "cors",
"credentials": "omit"
});
let jsonObj =await res.json();
let languageSupport = jsonObj["Products"][pid]["LanguageSupport"]
let defaultL=['zh-CN','zh-TW'];
for(let i=0;i<defaultL.length;i++){
for(let j=0;j< Object.keys(languageSupport).length;j++){
if(defaultL[i]==Object.keys(languageSupport)[j]){
selectedLanguage=defaultL[i];
break;
}
}
}
}catch(e){}
}
if (isRequest && arg0.method == "POST") {
arg0.json().then(json => {
json["settings"]["locale"] = selectedLanguage;
let body = JSON.stringify(json);
arg[0] = new Request(url, {
method: arg0.method,
headers: arg0.headers,
body: body,
mode: arg0.mode,
credentials: arg0.credentials,
cache: arg0.cache,
redirect: arg0.redirect,
referrer: arg0.referrer,
integrity: arg0.integrity
});
originFetch(...arg).then(res => {
console.log('语言结束')
resolve(res);
let cssChanged= setInterval(function(){
let basicBtn=$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY');
if(basicBtn!=null){
if(basicBtn.css('color')!='black'){
$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').text('X')
//$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').css('color',' black')
$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').css('width',' 10px')
$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').css('min-width',' 10px')
$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').css('background-color','rgba(255,0,0,0)')
$('.EditErgoMenu-module__basicControlsButtonColor___1sLIY').css('opacity','0.3')
$('.GripHandle-module__container___3clUM').css('opacity','0.3')
$('.StreamHUD-module__buttonsContainer___9B1o3').css('opacity','0.5')
}
}
},2000)
}).catch(err => {
reject(err);
});
});
} else {
console.error("[ERROR] Not a request.");
return originFetch(...arg);
}
});
} else if (url.indexOf('/v2/titles') > -1) { // /v2/titles or /v2/titles/mru
// Enable CustomTouchOverlay
console.log('修改触摸开始')
return new Promise((resolve, reject) => {
originFetch(...arg).then(res => {
res.json().then(json => {
// console.error(json);
try {
json["results"].forEach(result => {
if (result["details"]["supportedInputTypes"].includes("CustomTouchOverlay") === false) {
result["details"]["supportedInputTypes"].push("CustomTouchOverlay");
// console.log("[Xbox Cloud Gaming Global Touch Controll] Hook " + result["titleId"]);
}
if (result["details"]["supportedInputTypes"].includes("MKB") === false) {
result["details"]["supportedInputTypes"].push("MKB");
// console.log("[Xbox Cloud Gaming Global Touch Controll] Hook " + result["titleId"]);
}
if (result["details"]["supportedInputTypes"].includes("GenericTouch") === false) {
result["details"]["supportedInputTypes"].push("GenericTouch");
// console.log("[Xbox Cloud Gaming Global Touch Controll] Hook " + result["titleId"]);
}
if (result["details"]["supportedInputTypes"].includes("NativeTouch") === false) {
result["details"]["supportedInputTypes"].push("NativeTouch");
// console.log("[Xbox Cloud Gaming Global Touch Controll] Hook " + result["titleId"]);
}
});
} catch (err) {}
let body = JSON.stringify(json);
let newRes = new Response(body, {
status: res.status,
statusText: res.statusText,
headers: res.headers
})
resolve(newRes);
console.log('修改触摸结束')
}).catch(err => {
reject(err);
});
}).catch(err => {
reject(err);
});
});
}else {
return originFetch(...arg);
}
}
function HookProperty(object, property, value)
{
Object.defineProperty(object, property, {
value: value
});
}
let fakeuad = {
"brands": [
{
"brand": "Microsoft Edge",
"version": "999"
},
{
"brand": "Chromium",
"version": "999"
},
{
"brand": "Not=A?Brand",
"version": "24"
}
],
"mobile": false,
"platform": "Windows"
};
try{
HookProperty(windowCtx.navigator, "userAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36 Edg/999.0.0.0");
HookProperty(windowCtx.navigator, "appVersion", "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36 Edg/999.0.0.0");
HookProperty(windowCtx.navigator, "platform", "Win32");
HookProperty(windowCtx.navigator, "appName", "Netscape");
HookProperty(windowCtx.navigator, "appCodeName", "Mozilla");
HookProperty(windowCtx.navigator, "product", "Gecko");
HookProperty(windowCtx.navigator, "vendor", "Google Inc.");
HookProperty(windowCtx.navigator, "vendorSub", "");
HookProperty(windowCtx.navigator, "maxTouchPoints", undefined);
HookProperty(windowCtx.navigator, "userAgentData", fakeuad);
HookProperty(windowCtx.navigator, "connection", undefined);
HookProperty(windowCtx.navigator, "standalone", true);
}catch(e){}
})();