diff --git a/src/js/Content/Features/LegacyPage.ts b/src/js/Content/Features/LegacyPage.ts index bbb88689c..7d5ed88e5 100644 --- a/src/js/Content/Features/LegacyPage.ts +++ b/src/js/Content/Features/LegacyPage.ts @@ -13,7 +13,7 @@ import ITAD from "@Content/Modules/ITAD"; export default class LegacyPage extends Page { override check(): boolean { - return !!document.getElementById("global_header"); + return !!document.querySelector("#global_header, .responsive_page_frame.no_header"); } protected override async getAppConfig(factory: AppConfigFactory): Promise { diff --git a/src/js/Content/Features/Page.ts b/src/js/Content/Features/Page.ts index 77013d32b..2c6da3ab8 100644 --- a/src/js/Content/Features/Page.ts +++ b/src/js/Content/Features/Page.ts @@ -53,12 +53,32 @@ export default abstract class Page { protected abstract getLanguage(factory: LanguageFactory): Promise; protected abstract getUser(factory: UserFactory): Promise; + private async waitForCheck(timeout = 10000): Promise { + if (this.check()) { return true; } + + return new Promise(resolve => { + const observer = new MutationObserver(() => { + if (!this.check()) { return; } + + window.clearTimeout(timeoutId); + observer.disconnect(); + resolve(true); + }); + const timeoutId = window.setTimeout(() => { + observer.disconnect(); + resolve(false); + }, timeout); + + observer.observe(document.documentElement, {childList: true, subtree: true}); + }); + } + async run(): Promise { if (document.querySelector("#as-menu")) { // already loaded return; } - if (!this.check()) { return; } + if (!await this.waitForCheck()) { return; } let language: Language|null; let user: UserInterface; diff --git a/src/js/Content/Features/Store/App/PApp.ts b/src/js/Content/Features/Store/App/PApp.ts index 3a1e8f0ef..399d2d6cc 100644 --- a/src/js/Content/Features/Store/App/PApp.ts +++ b/src/js/Content/Features/Store/App/PApp.ts @@ -6,4 +6,17 @@ import CApp from "@Content/Features/Store/App/CApp"; import StorePage from "@Content/Features/StorePage"; -(new StorePage(CApp)).run(); +const page = new StorePage(CApp); +const selector = ".page_content_ctn > .page_content, #error_box"; + +if (document.querySelector(selector)) { + page.run(); +} else { + const observer = new MutationObserver(() => { + if (!document.querySelector(selector)) { return; } + + observer.disconnect(); + page.run(); + }); + observer.observe(document.documentElement, {childList: true, subtree: true}); +} diff --git a/src/js/Content/Modules/AugmentedSteam.ts b/src/js/Content/Modules/AugmentedSteam.ts index 3a84fd5bf..d5ae868a7 100644 --- a/src/js/Content/Modules/AugmentedSteam.ts +++ b/src/js/Content/Modules/AugmentedSteam.ts @@ -32,7 +32,11 @@ export default class AugmentedSteam { const target = document.querySelector(this.react ? "header nav + div" : "#global_action_menu" - )!; + ); + if (!target) { + console.warn("Augmented Steam menu is unavailable on this page"); + return; + } (new AugmentedSteamMenu({ target, @@ -116,7 +120,8 @@ export default class AugmentedSteam { target = document.querySelector("header ~ section"); anchor = target?.firstElementChild ?? null; } else { - const header = document.querySelector("#global_header")! + const header = document.querySelector("#global_header"); + if (!header) { return; } target = header.parentElement!; anchor = header.nextElementSibling!; }