mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-13 11:13:50 +01:00
31 lines
975 B
TypeScript
31 lines
975 B
TypeScript
import { setTimeoutRef } from "../utils/SetTimeoutRef";
|
|
import { getElementById } from "../../utils/uiHelpers/getElementById";
|
|
import { Action } from "../types";
|
|
|
|
const threeSeconds = 3000;
|
|
let x: number | undefined;
|
|
|
|
/**
|
|
* Displays a status message to the player for approximately 3 seconds.
|
|
* @param text The status text to display
|
|
*/
|
|
export function createStatusText(text: string): void {
|
|
if (x !== undefined) {
|
|
clearTimeout(x);
|
|
// Likely not needed due to clearTimeout, but just in case...
|
|
x = undefined;
|
|
}
|
|
|
|
const statusElement: HTMLElement = getElementById("status-text");
|
|
statusElement.style.display = "block";
|
|
statusElement.classList.add("status-text");
|
|
statusElement.innerText = text;
|
|
const handler: Action = () => {
|
|
statusElement.innerText = "";
|
|
statusElement.style.display = "none";
|
|
statusElement.classList.remove("status-text");
|
|
};
|
|
|
|
x = setTimeoutRef(handler, threeSeconds);
|
|
}
|