Fix global vars

This commit is contained in:
redphx
2024-04-24 16:50:59 +07:00
parent 9446e39eb0
commit 9d0f4c380b
30 changed files with 87 additions and 69 deletions

View File

@@ -1,5 +1,5 @@
import { CE, Icon } from "./html";
import { Preferences, getPref } from "../modules/preferences";
import { PrefKey, getPref } from "../modules/preferences";
export function addCss() {
@@ -1273,7 +1273,7 @@ div[class*=NotFocusedDialog] {
`;
// Hide "Play with friends" section
if (getPref(Preferences.BLOCK_SOCIAL_FEATURES)) {
if (getPref(PrefKey.BLOCK_SOCIAL_FEATURES)) {
css += `
div[class^=HomePage-module__bottomSpacing]:has(button[class*=SocialEmptyCard]),
button[class*=SocialEmptyCard] {
@@ -1283,7 +1283,7 @@ button[class*=SocialEmptyCard] {
}
// Reduce animations
if (getPref(Preferences.REDUCE_ANIMATIONS)) {
if (getPref(PrefKey.REDUCE_ANIMATIONS)) {
css += `
div[class*=GameCard-module__gameTitleInnerWrapper],
div[class*=GameCard-module__card],
@@ -1294,7 +1294,7 @@ div[class*=ScrollArrows-module] {
}
// Hide the top-left dots icon while playing
if (getPref(Preferences.HIDE_DOTS_ICON)) {
if (getPref(PrefKey.HIDE_DOTS_ICON)) {
css += `
div[class*=Grip-module__container] {
visibility: hidden;
@@ -1326,7 +1326,7 @@ div[class*=StreamMenu-module__menu] {
min-width: 100vw !important;
}
`;
if (getPref(Preferences.STREAM_SIMPLIFY_MENU)) {
if (getPref(PrefKey.STREAM_SIMPLIFY_MENU)) {
css += `
div[class*=Menu-module__scrollable] {
--bxStreamMenuItemSize: 80px;
@@ -1386,7 +1386,7 @@ body:not([data-media-type=tv]) div[class*=MenuItem-module__label] {
}
// Hide scrollbar
if (getPref(Preferences.UI_SCROLLBAR_HIDE)) {
if (getPref(PrefKey.UI_SCROLLBAR_HIDE)) {
css += `
html {
scrollbar-width: none;

22
src/utils/global.ts Normal file
View File

@@ -0,0 +1,22 @@
import { getLocale } from "../modules/translation";
export const AppInterface = window.AppInterface;
export const NATIVE_FETCH = window.fetch;
export const States: BxStates = {
isPlaying: false,
appContext: {},
serverRegions: {},
hasTouchSupport: ('ontouchstart' in window || navigator.maxTouchPoints > 0),
currentStream: {},
remotePlay: {},
};
export const SCRIPT_VERSION = '3.5.3';
export const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
export var LOCALE = getLocale();
export const refreshLocale = () => {
LOCALE = getLocale();
}

View File

@@ -1,5 +1,6 @@
import { BxEvent } from "../modules/bx-event";
import { getPref, PrefKey } from "../modules/preferences";
import { States } from "./global";
import { UserAgent } from "./user-agent";
export function patchVideoApi() {

View File

@@ -1,11 +1,11 @@
import { BxEvent } from "../modules/bx-event";
import { BX_FLAGS } from "../modules/bx-flags";
import { LoadingScreen } from "../modules/loading-screen";
import { MouseCursorHider } from "../modules/mkb/mouse-cursor-hider";
import { PrefKey, getPref } from "../modules/preferences";
import { RemotePlay } from "../modules/remote-play";
import { StreamBadges } from "../modules/stream/stream-badges";
import { TouchController } from "../modules/touch-controller";
import { NATIVE_FETCH, States } from "./global";
import { getPreferredServerRegion } from "./region";
import { TitlesInfo } from "./titles-info";
@@ -549,8 +549,6 @@ export function interceptHttpRequests() {
return nativeXhrSend.apply(this, arguments);
};
const PREF_UI_LOADING_SCREEN_GAME_ART = getPref(PrefKey.UI_LOADING_SCREEN_GAME_ART);
window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
let url = (typeof request === 'string') ? request : (request as Request).url;

View File

@@ -1,4 +1,5 @@
import { getPref, Preferences, PrefKey } from "../modules/preferences";
import { getPref, PrefKey } from "../modules/preferences";
import { States } from "./global";
export function getPreferredServerRegion(shortName = false) {

View File

@@ -1,5 +1,6 @@
import { PrefKey } from "../modules/preferences";
import { getPref } from "../modules/preferences";
import { States } from "./global";
import { UserAgent } from "./user-agent";
export class TitlesInfo {

View File

@@ -1,4 +1,4 @@
import { PrefKey, Preferences, getPref } from "../modules/preferences";
import { PrefKey, getPref } from "../modules/preferences";
export enum UserAgentProfile {
EDGE_WINDOWS = 'edge-windows',

View File

@@ -1,4 +1,5 @@
import { PrefKey, getPref, setPref } from "../modules/preferences";
import { SCRIPT_VERSION } from "./global";
import { UserAgent } from "./user-agent";
export function checkForUpdate() {