mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-05 12:56:42 +02:00
Add setting to bypass region restriction
This commit is contained in:
12
src/index.ts
12
src/index.ts
@@ -125,13 +125,13 @@ window.addEventListener('popstate', onHistoryChanged);
|
|||||||
window.history.pushState = patchHistoryMethod('pushState');
|
window.history.pushState = patchHistoryMethod('pushState');
|
||||||
window.history.replaceState = patchHistoryMethod('replaceState');
|
window.history.replaceState = patchHistoryMethod('replaceState');
|
||||||
|
|
||||||
|
window.addEventListener(BxEvent.XCLOUD_SERVERS_UNAVAILABLE, e => {
|
||||||
|
STATES.supportedRegion = false;
|
||||||
|
window.setTimeout(watchHeader, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
||||||
// Start rendering UI
|
watchHeader();
|
||||||
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
|
|
||||||
window.setTimeout(watchHeader, 2000);
|
|
||||||
} else {
|
|
||||||
watchHeader();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener(BxEvent.STREAM_LOADING, e => {
|
window.addEventListener(BxEvent.STREAM_LOADING, e => {
|
||||||
|
@@ -15,6 +15,7 @@ const SETTINGS_UI = {
|
|||||||
'Better xCloud': {
|
'Better xCloud': {
|
||||||
items: [
|
items: [
|
||||||
PrefKey.BETTER_XCLOUD_LOCALE,
|
PrefKey.BETTER_XCLOUD_LOCALE,
|
||||||
|
PrefKey.SERVER_BYPASS_RESTRICTION,
|
||||||
PrefKey.REMOTE_PLAY_ENABLED,
|
PrefKey.REMOTE_PLAY_ENABLED,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -260,9 +261,9 @@ export function setupSettingsUi() {
|
|||||||
if (setting.experimental) {
|
if (setting.experimental) {
|
||||||
settingLabel = '🧪 ' + settingLabel;
|
settingLabel = '🧪 ' + settingLabel;
|
||||||
if (!settingNote) {
|
if (!settingNote) {
|
||||||
settingNote = t('experimental')
|
settingNote = t('experimental');
|
||||||
} else {
|
} else {
|
||||||
settingNote = `${t('experimental')}: ${settingNote}`
|
settingNote = `${t('experimental')}: ${settingNote}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
src/types/index.d.ts
vendored
2
src/types/index.d.ts
vendored
@@ -24,6 +24,8 @@ interface NavigatorBattery extends Navigator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BxStates = {
|
type BxStates = {
|
||||||
|
supportedRegion: boolean;
|
||||||
|
|
||||||
isPlaying: boolean;
|
isPlaying: boolean;
|
||||||
appContext: any | null;
|
appContext: any | null;
|
||||||
serverRegions: any;
|
serverRegions: any;
|
||||||
|
@@ -26,6 +26,7 @@ export enum BxEvent {
|
|||||||
REMOTE_PLAY_FAILED = 'bx-remote-play-failed',
|
REMOTE_PLAY_FAILED = 'bx-remote-play-failed',
|
||||||
|
|
||||||
XCLOUD_SERVERS_READY = 'bx-servers-ready',
|
XCLOUD_SERVERS_READY = 'bx-servers-ready',
|
||||||
|
XCLOUD_SERVERS_UNAVAILABLE = 'bx-servers-unavailable',
|
||||||
|
|
||||||
DATA_CHANNEL_CREATED = 'bx-data-channel-created',
|
DATA_CHANNEL_CREATED = 'bx-data-channel-created',
|
||||||
|
|
||||||
|
@@ -13,6 +13,8 @@ const browserHasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoi
|
|||||||
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
||||||
|
|
||||||
export const STATES: BxStates = {
|
export const STATES: BxStates = {
|
||||||
|
supportedRegion: true,
|
||||||
|
|
||||||
isPlaying: false,
|
isPlaying: false,
|
||||||
appContext: {},
|
appContext: {},
|
||||||
serverRegions: {},
|
serverRegions: {},
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { CE } from "@utils/html";
|
import { CE } from "@utils/html";
|
||||||
import { SUPPORTED_LANGUAGES, t } from "@utils/translation";
|
import { SUPPORTED_LANGUAGES, t, ut } from "@utils/translation";
|
||||||
import { SettingElement, SettingElementType } from "@utils/settings";
|
import { SettingElement, SettingElementType } from "@utils/settings";
|
||||||
import { UserAgent } from "@utils/user-agent";
|
import { UserAgent } from "@utils/user-agent";
|
||||||
import { StreamStat } from "@modules/stream/stream-stats";
|
import { StreamStat } from "@modules/stream/stream-stats";
|
||||||
@@ -17,6 +17,8 @@ export enum PrefKey {
|
|||||||
BETTER_XCLOUD_LOCALE = 'bx_locale',
|
BETTER_XCLOUD_LOCALE = 'bx_locale',
|
||||||
|
|
||||||
SERVER_REGION = 'server_region',
|
SERVER_REGION = 'server_region',
|
||||||
|
SERVER_BYPASS_RESTRICTION = 'server_bypass_restriction',
|
||||||
|
|
||||||
PREFER_IPV6_SERVER = 'prefer_ipv6_server',
|
PREFER_IPV6_SERVER = 'prefer_ipv6_server',
|
||||||
STREAM_TARGET_RESOLUTION = 'stream_target_resolution',
|
STREAM_TARGET_RESOLUTION = 'stream_target_resolution',
|
||||||
STREAM_PREFERRED_LOCALE = 'stream_preferred_locale',
|
STREAM_PREFERRED_LOCALE = 'stream_preferred_locale',
|
||||||
@@ -122,6 +124,12 @@ export class Preferences {
|
|||||||
label: t('region'),
|
label: t('region'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
},
|
},
|
||||||
|
[PrefKey.SERVER_BYPASS_RESTRICTION]: {
|
||||||
|
label: ut('Bypass region restriction'),
|
||||||
|
note: ut('⚠️ Use this at your own risk'),
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
|
||||||
[PrefKey.STREAM_PREFERRED_LOCALE]: {
|
[PrefKey.STREAM_PREFERRED_LOCALE]: {
|
||||||
label: t('preferred-game-language'),
|
label: t('preferred-game-language'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
|
@@ -12,7 +12,17 @@ import { getPreferredServerRegion } from "./region";
|
|||||||
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)) {
|
||||||
|
(request as Request).headers.set('X-Forwarded-For', '9.9.9.9');
|
||||||
|
}
|
||||||
|
|
||||||
const response = await NATIVE_FETCH(request, init);
|
const response = await NATIVE_FETCH(request, init);
|
||||||
|
if (response.status !== 200) {
|
||||||
|
// Unsupported region
|
||||||
|
BxEvent.dispatch(window, BxEvent.XCLOUD_SERVERS_UNAVAILABLE);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
const obj = await response.clone().json();
|
const obj = await response.clone().json();
|
||||||
|
|
||||||
// Preload Remote Play
|
// Preload Remote Play
|
||||||
|
Reference in New Issue
Block a user