diff --git a/packages/documentation/docs/sections/internals.md b/packages/documentation/docs/sections/internals.md index f1699ebc0..8b9cb4a6a 100644 --- a/packages/documentation/docs/sections/internals.md +++ b/packages/documentation/docs/sections/internals.md @@ -16,6 +16,12 @@ Allows you to select a language different from the language used in KG. Initially, KS will just use the language KG is set at, but you can override this language here. +## Other internals + +Some users may experience slow loads of KG itself, causing KS to fail to load in time, as the timeout for the loader is "only" 2 minutes. + +In case you are impacted by this, set `localStorage["ks.timeout"]` to the amount of milliseconds KS should wait for KG to load. The default value is `120000`, which correlates to the amount of milliseconds in 2 minutes. + *[JS]: JavaScript *[KG]: Kittens Game diff --git a/packages/userscript/source/UserScript.ts b/packages/userscript/source/UserScript.ts index d46a84592..cecddeeaf 100644 --- a/packages/userscript/source/UserScript.ts +++ b/packages/userscript/source/UserScript.ts @@ -45,6 +45,16 @@ export const ksVersion = (prefix = "") => { return `${prefix}${KS_VERSION}`; }; +// How long to wait for KG to load, in milliseconds. +const TIMEOUT_DEFAULT = 2 * 60 * 1000; + +// Allows the user to define a timeout override in their browser's web storage. +// This allows users to extend the timeout period, in case their local configuration +// requires it. +const TIMEOUT_OVERRIDE = !isNil(localStorage["ks.timeout"]) + ? Number(localStorage["ks.timeout"]) + : undefined; + export class UserScript { readonly gamePage: GamePage; @@ -254,7 +264,7 @@ export class UserScript { return state[0]; } - static async waitForGame(timeout = 30000): Promise { + static async waitForGame(timeout = TIMEOUT_OVERRIDE ?? TIMEOUT_DEFAULT): Promise { const signals: Array> = [sleep(2000)]; if (isNil(UserScript._gameStartSignal) && typeof UserScript.window.dojo !== "undefined") {