Update servers

This commit is contained in:
redphx 2024-07-15 09:13:23 +07:00
parent 55a56837c8
commit d41fd22a47
4 changed files with 47 additions and 8 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 5.3.0 // @version 5.3.1-beta
// @description Improve Xbox Cloud Gaming (xCloud) experience // @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx // @author redphx
// @license MIT // @license MIT
@ -134,7 +134,7 @@ function deepClone(obj) {
return {}; return {};
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
var SCRIPT_VERSION = "5.3.0", AppInterface = window.AppInterface; var SCRIPT_VERSION = "5.3.1-beta", AppInterface = window.AppInterface;
UserAgent.init(); UserAgent.init();
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = { var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
supportedRegion: !0, supportedRegion: !0,
@ -1001,6 +1001,19 @@ var UiSection;
UiSection2["ALL_GAMES"] = "all-games"; UiSection2["ALL_GAMES"] = "all-games";
})(UiSection || (UiSection = {})); })(UiSection || (UiSection = {}));
// src/enums/bypass-servers.ts
var BypassServers = {
br: "Brazil",
jp: "Japan",
pl: "Poland",
us: "United States"
}, BypassServerIps = {
br: "169.150.198.66",
jp: "138.199.21.239",
pl: "45.134.212.66",
us: "143.244.47.65"
};
// src/utils/preferences.ts // src/utils/preferences.ts
var PrefKey; var PrefKey;
(function(PrefKey2) { (function(PrefKey2) {
@ -1098,7 +1111,10 @@ class Preferences {
[PrefKey.SERVER_BYPASS_RESTRICTION]: { [PrefKey.SERVER_BYPASS_RESTRICTION]: {
label: t("bypass-region-restriction"), label: t("bypass-region-restriction"),
note: t("use-this-at-your-own-risk"), note: t("use-this-at-your-own-risk"),
default: !1 default: "off",
options: Object.assign({
off: t("off")
}, BypassServers)
}, },
[PrefKey.STREAM_PREFERRED_LOCALE]: { [PrefKey.STREAM_PREFERRED_LOCALE]: {
label: t("preferred-game-language"), label: t("preferred-game-language"),
@ -5941,8 +5957,11 @@ class StreamBadges {
// src/utils/xcloud-interceptor.ts // src/utils/xcloud-interceptor.ts
class XcloudInterceptor { class XcloudInterceptor {
static async#handleLogin(request, init) { static async#handleLogin(request, init) {
if (getPref(PrefKey.SERVER_BYPASS_RESTRICTION)) const bypassServer = getPref(PrefKey.SERVER_BYPASS_RESTRICTION);
request.headers.set("X-Forwarded-For", "9.9.9.9"); if (bypassServer !== "off") {
const ip = BypassServerIps[bypassServer];
ip && request.headers.set("X-Forwarded-For", ip);
}
const response = await NATIVE_FETCH(request, init); const response = await NATIVE_FETCH(request, init);
if (response.status !== 200) if (response.status !== 200)
return BxEvent.dispatch(window, BxEvent.XCLOUD_SERVERS_UNAVAILABLE), response; return BxEvent.dispatch(window, BxEvent.XCLOUD_SERVERS_UNAVAILABLE), response;

View File

@ -0,0 +1,13 @@
export const BypassServers = {
'br': 'Brazil',
'jp': 'Japan',
'pl': 'Poland',
'us': 'United States',
}
export const BypassServerIps = {
'br': '169.150.198.66',
'jp': '138.199.21.239',
'pl': '45.134.212.66',
'us': '143.244.47.65',
}

View File

@ -8,6 +8,7 @@ import { AppInterface, STATES } from "@utils/global";
import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player"; import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player";
import { UserAgentProfile } from "@/enums/user-agent"; import { UserAgentProfile } from "@/enums/user-agent";
import { UiSection } from "@/enums/ui-sections"; import { UiSection } from "@/enums/ui-sections";
import { BypassServers } from "@/enums/bypass-servers";
export enum PrefKey { export enum PrefKey {
LAST_UPDATE_CHECK = 'version_last_check', LAST_UPDATE_CHECK = 'version_last_check',
@ -128,7 +129,10 @@ export class Preferences {
[PrefKey.SERVER_BYPASS_RESTRICTION]: { [PrefKey.SERVER_BYPASS_RESTRICTION]: {
label: t('bypass-region-restriction'), label: t('bypass-region-restriction'),
note: t('use-this-at-your-own-risk'), note: t('use-this-at-your-own-risk'),
default: false, default: 'off',
options: Object.assign({
'off': t('off'),
}, BypassServers),
}, },
[PrefKey.STREAM_PREFERRED_LOCALE]: { [PrefKey.STREAM_PREFERRED_LOCALE]: {

View File

@ -8,12 +8,15 @@ import { STATES } from "./global";
import { patchIceCandidates } from "./network"; import { patchIceCandidates } from "./network";
import { getPref, PrefKey } from "./preferences"; import { getPref, PrefKey } from "./preferences";
import { getPreferredServerRegion } from "./region"; import { getPreferredServerRegion } from "./region";
import { BypassServerIps } from "@/enums/bypass-servers";
export export
class XcloudInterceptor { class XcloudInterceptor {
static async #handleLogin(request: RequestInfo | URL, init?: RequestInit) { static async #handleLogin(request: RequestInfo | URL, init?: RequestInit) {
if (getPref(PrefKey.SERVER_BYPASS_RESTRICTION)) { const bypassServer = getPref(PrefKey.SERVER_BYPASS_RESTRICTION);
(request as Request).headers.set('X-Forwarded-For', '9.9.9.9'); if (bypassServer !== 'off') {
const ip = BypassServerIps[bypassServer as keyof typeof BypassServerIps];
ip && (request as Request).headers.set('X-Forwarded-For', ip);
} }
const response = await NATIVE_FETCH(request, init); const response = await NATIVE_FETCH(request, init);