From 45bda4bb24713a770dcf116f4d79e3fe7f08f042 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 13 Jul 2024 12:19:07 +0700 Subject: [PATCH] Fix script not being loaded after refreshing token --- src/index.ts | 20 +++++++++++++------- src/utils/monkey-patches.ts | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3503acb..5d89749 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,13 +37,19 @@ import { updateVideoPlayer } from "./modules/stream/stream-settings-utils"; // Handle login page if (window.location.pathname.includes('/auth/msa')) { - window.addEventListener('load', e => { - window.location.search.includes('loggedIn') && window.setTimeout(() => { - const location = window.location; - // @ts-ignore - location.pathname.includes('/play') && location.reload(true); - }, 2000); - }); + const nativePushState = window.history['pushState']; + window.history['pushState'] = function(...args: any[]) { + const url = args[2]; + if (url && (url.startsWith('/play') || url.substring(6).startsWith('/play'))) { + console.log('Redirecting to xbox.com/play'); + window.stop(); + window.location.href = 'https://www.xbox.com' + url; + return; + } + + // @ts-ignore + return nativePushState.apply(this, arguments); + } // Stop processing the script throw new Error('[Better xCloud] Refreshing the page after logging in'); } diff --git a/src/utils/monkey-patches.ts b/src/utils/monkey-patches.ts index 7a04649..bcf73d1 100644 --- a/src/utils/monkey-patches.ts +++ b/src/utils/monkey-patches.ts @@ -161,6 +161,8 @@ export function patchMeControl() { API: { setDisplayMode: () => {}, setMobileState: () => {}, + addEventListener: () => {}, + removeEventListener: () => {}, }, }, };