From de7bf3edc752fd2c8219d8761e7abcec92513db6 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:05:29 +0700 Subject: [PATCH] Refactor --- dist/better-xcloud.lite.user.js | 5 +---- dist/better-xcloud.user.js | 5 +---- src/index.ts | 2 +- src/modules/touch-controller.ts | 2 +- src/modules/ui/dialog/navigation-dialog.ts | 4 ++-- src/modules/ui/ui.ts | 2 +- src/types/global.d.ts | 19 +++++++++++++++++++ src/utils/bx-event.ts | 2 +- src/utils/bx-logger.ts | 2 +- src/utils/history.ts | 8 +------- src/utils/monkey-patches.ts | 6 +++--- src/utils/network.ts | 2 +- src/utils/user-agent.ts | 2 +- 13 files changed, 34 insertions(+), 27 deletions(-) diff --git a/dist/better-xcloud.lite.user.js b/dist/better-xcloud.lite.user.js index e44e985..761388b 100755 --- a/dist/better-xcloud.lite.user.js +++ b/dist/better-xcloud.lite.user.js @@ -5742,10 +5742,7 @@ function patchHistoryMethod(type) { } function onHistoryChanged(e) { if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === "better-xcloud") return; - window.setTimeout(RemotePlayManager.detect, 10); - let $settings = document.querySelector(".bx-settings-container"); - if ($settings) $settings.classList.add("bx-gone"); - NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), EventBus.Stream.emit("stateStopped", {}); + window.setTimeout(RemotePlayManager.detect, 10), NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), EventBus.Stream.emit("stateStopped", {}); } function setCodecPreferences(sdp, preferredCodec) { let h264Pattern = /a=fmtp:(\d+).*profile-level-id=([0-9a-f]{6})/g, profilePrefix = preferredCodec === "high" ? "4d" : preferredCodec === "low" ? "420" : "42e", preferredCodecIds = [], matches = sdp.matchAll(h264Pattern) || []; diff --git a/dist/better-xcloud.user.js b/dist/better-xcloud.user.js index 3525e2f..7023fd6 100755 --- a/dist/better-xcloud.user.js +++ b/dist/better-xcloud.user.js @@ -8087,10 +8087,7 @@ function patchHistoryMethod(type) { } function onHistoryChanged(e) { if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === "better-xcloud") return; - window.setTimeout(RemotePlayManager.detect, 10); - let $settings = document.querySelector(".bx-settings-container"); - if ($settings) $settings.classList.add("bx-gone"); - NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), EventBus.Stream.emit("stateStopped", {}); + window.setTimeout(RemotePlayManager.detect, 10), NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), EventBus.Stream.emit("stateStopped", {}); } function setCodecPreferences(sdp, preferredCodec) { let h264Pattern = /a=fmtp:(\d+).*profile-level-id=([0-9a-f]{6})/g, profilePrefix = preferredCodec === "high" ? "4d" : preferredCodec === "low" ? "420" : "42e", preferredCodecIds = [], matches = sdp.matchAll(h264Pattern) || []; diff --git a/src/index.ts b/src/index.ts index 9065e9b..46059e9 100755 --- a/src/index.ts +++ b/src/index.ts @@ -160,7 +160,7 @@ document.addEventListener('readystatechange', e => { return; } - STATES.isSignedIn = !!((window as any).xbcUser?.isSignedIn); + STATES.isSignedIn = !!window.xbcUser?.isSignedIn; if (STATES.isSignedIn) { // Preload Remote Play diff --git a/src/modules/touch-controller.ts b/src/modules/touch-controller.ts index b6b4ddf..de811a1 100755 --- a/src/modules/touch-controller.ts +++ b/src/modules/touch-controller.ts @@ -268,7 +268,7 @@ export class TouchController { static setup() { // Function for testing touch control - (window as any).testTouchLayout = (layout: any) => { + window.testTouchLayout = (layout: any) => { const { touchLayoutManager } = window.BX_EXPOSED; touchLayoutManager && touchLayoutManager.changeLayoutForScope({ diff --git a/src/modules/ui/dialog/navigation-dialog.ts b/src/modules/ui/dialog/navigation-dialog.ts index 584f27c..c95d6a8 100755 --- a/src/modules/ui/dialog/navigation-dialog.ts +++ b/src/modules/ui/dialog/navigation-dialog.ts @@ -442,7 +442,7 @@ export class NavigationDialogManager { BxEvent.dispatch(window, BxEvent.XCLOUD_DIALOG_SHOWN); // Stop xCloud's navigation polling - (window as any).BX_EXPOSED.disableGamepadPolling = true; + window.BX_EXPOSED.disableGamepadPolling = true; // Lock scroll bar document.body.classList.add('bx-no-scroll'); @@ -504,7 +504,7 @@ export class NavigationDialogManager { this.unmountCurrentDialog(); // Enable xCloud's navigation polling - (window as any).BX_EXPOSED.disableGamepadPolling = false; + window.BX_EXPOSED.disableGamepadPolling = false; // Show the last dialog in dialogs stack if (this.dialogsStack.length) { diff --git a/src/modules/ui/ui.ts b/src/modules/ui/ui.ts index 2c3d6a6..b5d9ceb 100755 --- a/src/modules/ui/ui.ts +++ b/src/modules/ui/ui.ts @@ -24,4 +24,4 @@ export function localRedirect(path: string) { $anchor.click(); } -(window as any).localRedirect = localRedirect; +window.localRedirect = localRedirect; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 2d16cf8..fe40d85 100755 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -2,6 +2,8 @@ import type { BxExposed } from "@/utils/bx-exposed"; import type { AllPresets, ControllerShortcutPresetRecord } from "./presets"; import type { PrefKey } from "@/enums/pref-keys"; import type { StreamSettings, type StreamSettingsData } from "@/utils/stream-settings"; +import type { BxEvent } from "@/utils/bx-event"; +import type { BxLogger } from "@/utils/bx-logger"; export {}; @@ -24,5 +26,22 @@ declare global { BX_REMOTE_PLAY_CONFIG: BxStates.remotePlay.config; BX_STREAM_SETTINGS: StreamSettingsData; + + BX_FETCH: typeof window['fetch']; + + BxEvent: typeof BxEvent; + BxLogger: typeof BxLogger; + localRedirect: (path: stringn) => void; + testTouchLayout: (layout: any) => void; + + chrome?: any; + + // xCloud properties + xbcUser?: { + isSignedIn: boolean; + }; + MSA: any; + MeControl: any; + adobe: any; } } diff --git a/src/utils/bx-event.ts b/src/utils/bx-event.ts index e240402..f37b37a 100755 --- a/src/utils/bx-event.ts +++ b/src/utils/bx-event.ts @@ -67,4 +67,4 @@ export namespace BxEvent { } } -(window as any).BxEvent = BxEvent; +window.BxEvent = BxEvent; diff --git a/src/utils/bx-logger.ts b/src/utils/bx-logger.ts index 59f9cdd..5dab4c6 100755 --- a/src/utils/bx-logger.ts +++ b/src/utils/bx-logger.ts @@ -16,4 +16,4 @@ export class BxLogger { } } -(window as any).BxLogger = BxLogger; +window.BxLogger = BxLogger; diff --git a/src/utils/history.ts b/src/utils/history.ts index 0b77093..fddf07e 100755 --- a/src/utils/history.ts +++ b/src/utils/history.ts @@ -2,8 +2,8 @@ import { BxEvent } from "@utils/bx-event"; import { LoadingScreen } from "@modules/loading-screen"; import { RemotePlayManager } from "@/modules/remote-play-manager"; import { HeaderSection } from "@/modules/ui/header"; -import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog"; import { EventBus } from "./event-bus"; +import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog"; export function patchHistoryMethod(type: 'pushState' | 'replaceState') { const orig = window.history[type]; @@ -27,12 +27,6 @@ export function onHistoryChanged(e: PopStateEvent) { window.setTimeout(RemotePlayManager.detect, 10); - // Hide Global settings - const $settings = document.querySelector('.bx-settings-container'); - if ($settings) { - $settings.classList.add('bx-gone'); - } - // Hide Navigation dialog NavigationDialogManager.getInstance().hide(); diff --git a/src/utils/monkey-patches.ts b/src/utils/monkey-patches.ts index 12c62e0..8f9a167 100755 --- a/src/utils/monkey-patches.ts +++ b/src/utils/monkey-patches.ts @@ -201,8 +201,8 @@ export function patchMeControl() { }, }; - (window as any).MSA = new Proxy(MSA, MsaHandler); - (window as any).MeControl = new Proxy(MeControl, MeControlHandler); + window.MSA = new Proxy(MSA, MsaHandler); + window.MeControl = new Proxy(MeControl, MeControlHandler); } @@ -210,7 +210,7 @@ export function patchMeControl() { * Disable Adobe Audience Manager (AAM) */ export function disableAdobeAudienceManager() { - (window as any).adobe = Object.freeze({}); + window.adobe = Object.freeze({}); } /** diff --git a/src/utils/network.ts b/src/utils/network.ts index 8f2d54c..6743986 100755 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -189,7 +189,7 @@ export function interceptHttpRequests() { '2c06dea3f26c40c69b8456d319791fd0@o427368.ingest.sentry.io', ]; - (window as any).BX_FETCH = window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise => { + window.BX_FETCH = window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise => { let url = (typeof request === 'string') ? request : (request as Request).url; // Check blocked URLs diff --git a/src/utils/user-agent.ts b/src/utils/user-agent.ts index 6cafa3e..09542b1 100755 --- a/src/utils/user-agent.ts +++ b/src/utils/user-agent.ts @@ -10,7 +10,7 @@ type UserAgentConfig = { const SMART_TV_UNIQUE_ID = 'FC4A1DA2-711C-4E9C-BC7F-047AF8A672EA'; let CHROMIUM_VERSION = '125.0.0.0'; -if (!!(window as any).chrome || window.navigator.userAgent.includes('Chrome')) { +if (!!window.chrome || window.navigator.userAgent.includes('Chrome')) { // Get Chromium version in the original User-Agent value const match = window.navigator.userAgent.match(/\s(?:Chrome|Edg)\/([\d\.]+)/); if (match) {