frontend/ts/util.ts (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import { DatagramSocket } from './websocket' import { BatchTimer } from './batch-timer' function _(key: string, value: any | null | undefined = undefined): any | null { const x = <any>window; if (value !== undefined) { x[key] = value; } return x[key]; } function $(id: string): HTMLElement | null { return document.getElementById(id); } function errMsg(msg: string): void { const div = $("err_div"); const w = $("err_wrapper"); if (div && w) { div.innerText = msg; w.style.display = "block"; } } function closeErr(): void { const w = $("err_wrapper"); if (w) { w.style.display = "none"; } } async function authorizedFetch(method: string, uri: string, body: any): Promise<Response> { const headers = new Headers() headers.set('Authorization', 'Bearer ' + DatagramSocket.skey) return await fetch(uri, { method: method, headers: headers, body: body, }) } export default { _, $, authorizedFetch, errMsg, closeErr } |