From 938dfa6aaacfe9cf853bfd72cb4a9f66b74b8569 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:43:56 +0700 Subject: [PATCH] Add option to hide "Friends" section --- src/enums/ui-sections.ts | 6 ++++++ src/index.ts | 12 ++++++++++++ src/modules/patcher.ts | 3 ++- src/modules/ui/global-settings.ts | 1 + src/utils/css.ts | 14 +++++++++++--- src/utils/preferences.ts | 16 ++++++++++++++++ src/utils/translation.ts | 9 +++++++-- 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/enums/ui-sections.ts diff --git a/src/enums/ui-sections.ts b/src/enums/ui-sections.ts new file mode 100644 index 0000000..b704dc5 --- /dev/null +++ b/src/enums/ui-sections.ts @@ -0,0 +1,6 @@ +export enum UiSection { + NEWS = 'news', + FRIENDS = 'friends', + MOST_POPULAR = 'most-popular', + ALL_GAMES = 'all-games', +} diff --git a/src/index.ts b/src/index.ts index 4dc7d8a..ca9c84d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,6 +33,7 @@ import { NativeMkbHandler } from "./modules/mkb/native-mkb-handler"; import { GuideMenu, GuideMenuTab } from "./modules/ui/guide-menu"; import { StreamSettings } from "./modules/stream/stream-settings"; import { updateVideoPlayer } from "./modules/stream/stream-settings-utils"; +import { UiSection } from "./enums/ui-sections"; // Handle login page @@ -100,8 +101,19 @@ window.addEventListener('load', e => { window.location.reload(true); } }, 3000); + }); +// Hide "Play with Friends" skeleton section +if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) { + document.addEventListener('readystatechange', e => { + if (document.readyState === 'interactive') { + const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest('div[class*=HomePage-module]') as HTMLElement; + $parent && ($parent.style.display = 'none'); + } + }) +} + window.BX_EXPOSED = BxExposed; // Hide Settings UI when navigate to another page diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index 8c88bc0..c7b2cea 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -13,6 +13,7 @@ import codeRemotePlayEnable from "./patches/remote-play-enable.js" with { type: import codeRemotePlayKeepAlive from "./patches/remote-play-keep-alive.js" with { type: "text" }; import codeVibrationAdjust from "./patches/vibration-adjust.js" with { type: "text" }; import { FeatureGates } from "@/utils/feature-gates.js"; +import { UiSection } from "@/enums/ui-sections.js"; type PatchArray = (keyof typeof PATCHES)[]; @@ -744,7 +745,7 @@ let PATCH_ORDERS: PatchArray = [ getPref(PrefKey.LOCAL_CO_OP_ENABLED) && 'supportLocalCoOp', getPref(PrefKey.GAME_FORTNITE_FORCE_CONSOLE) && 'forceFortniteConsole', - getPref(PrefKey.BLOCK_SOCIAL_FEATURES) && 'ignorePlayWithFriendsSection', + getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS) && 'ignorePlayWithFriendsSection', ...(getPref(PrefKey.BLOCK_TRACKING) ? [ 'disableAiTrack', diff --git a/src/modules/ui/global-settings.ts b/src/modules/ui/global-settings.ts index 42d2b28..a3e0d4d 100644 --- a/src/modules/ui/global-settings.ts +++ b/src/modules/ui/global-settings.ts @@ -96,6 +96,7 @@ const SETTINGS_UI = { PrefKey.HIDE_DOTS_ICON, PrefKey.REDUCE_ANIMATIONS, PrefKey.BLOCK_SOCIAL_FEATURES, + PrefKey.UI_HIDE_SECTIONS, ], }, diff --git a/src/utils/css.ts b/src/utils/css.ts index 2849606..7520b56 100644 --- a/src/utils/css.ts +++ b/src/utils/css.ts @@ -1,17 +1,25 @@ import { CE } from "@utils/html"; import { PrefKey, getPref } from "@utils/preferences"; import { renderStylus } from "@macros/build" with {type: "macro"}; +import { UiSection } from "@/enums/ui-sections"; export function addCss() { const STYLUS_CSS = renderStylus(); let css = STYLUS_CSS; + // Hide "Play with Friends" section + if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) { + css += ` +div[class^=HomePage-module__bottomSpacing]:has(button[class*=SocialEmptyCard]), +button[class*=SocialEmptyCard] { + display: none; +} +`; + } + if (getPref(PrefKey.BLOCK_SOCIAL_FEATURES)) { css += ` -/* Hide "Play with friends" section */ -div[class^=HomePage-module__bottomSpacing]:has(button[class*=SocialEmptyCard]), -button[class*=SocialEmptyCard], /* Hide "Start a party" button in the Guide menu */ #gamepass-dialog-root div[class^=AchievementsPreview-module__container] + button[class*=HomeLandingPage-module__button] { diff --git a/src/utils/preferences.ts b/src/utils/preferences.ts index 771e5bd..b0bd62a 100644 --- a/src/utils/preferences.ts +++ b/src/utils/preferences.ts @@ -7,6 +7,7 @@ import type { PreferenceSetting, PreferenceSettings } from "@/types/preferences" import { AppInterface, STATES } from "@utils/global"; import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player"; import { UserAgentProfile } from "@/enums/user-agent"; +import { UiSection } from "@/enums/ui-sections"; export enum PrefKey { LAST_UPDATE_CHECK = 'version_last_check', @@ -70,6 +71,7 @@ export enum PrefKey { UI_LAYOUT = 'ui_layout', UI_SCROLLBAR_HIDE = 'ui_scrollbar_hide', + UI_HIDE_SECTIONS = 'ui_hide_sections', UI_HOME_CONTEXT_MENU_DISABLED = 'ui_home_context_menu_disabled', @@ -557,6 +559,20 @@ export class Preferences { default: STATES.browser.capabilities.touch, }, + [PrefKey.UI_HIDE_SECTIONS]: { + label: t('hide-sections'), + default: [], + multipleOptions: { + [UiSection.NEWS]: t('section-news'), + [UiSection.FRIENDS]: t('section-play-with-friends'), + [UiSection.MOST_POPULAR]: t('section-most-popular'), + [UiSection.ALL_GAMES]: t('section-all-games'), + }, + params: { + size: 4, + }, + }, + [PrefKey.BLOCK_SOCIAL_FEATURES]: { label: t('disable-social-features'), default: false, diff --git a/src/utils/translation.ts b/src/utils/translation.ts index 205ed2e..67c7540 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -110,6 +110,7 @@ const Texts = { "hide": "Hide", "hide-idle-cursor": "Hide mouse cursor on idle", "hide-scrollbar": "Hide web page's scrollbar", + "hide-sections": "Hide sections", "hide-system-menu-icon": "Hide System menu's icon", "hide-touch-controller": "Hide touch controller", "horizontal-scroll-sensitivity": "Horizontal scroll sensitivity", @@ -164,13 +165,13 @@ const Texts = { (e: any) => `${e.key} でこの機能を切替`, (e: any) => `${e.key} 키를 눌러 이 기능을 켜고 끄세요`, (e: any) => `Naciśnij ${e.key} aby przełączyć tę funkcję`, - , + (e: any) => `Pressione ${e.key} para alternar este recurso`, (e: any) => `Нажмите ${e.key} для переключения этой функции`, , (e: any) => `Etkinleştirmek için ${e.key} tuşuna basın`, (e: any) => `Натисніть ${e.key} щоб перемкнути цю функцію`, (e: any) => `Nhấn ${e.key} để bật/tắt tính năng này`, - , + (e: any) => `按下 ${e.key} 来切换此功能`, ], "press-to-bind": "Press a key or do a mouse click to bind...", "prompt-preset-name": "Preset's name:", @@ -191,6 +192,10 @@ const Texts = { "save": "Save", "screen": "Screen", "screenshot-apply-filters": "Applies video filters to screenshots", + "section-all-games": "All games", + "section-most-popular": "Most popular", + "section-news": "News", + "section-play-with-friends": "Play with friends", "separate-touch-controller": "Separate Touch controller & Controller #1", "separate-touch-controller-note": "Touch controller is Player 1, Controller #1 is Player 2", "server": "Server",