From bbd3859f54b30e4489c01d27cdb118cfea1b634f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 9 Nov 2023 20:55:43 +0000 Subject: [PATCH] add a debug mode --- index.html | 5 ++++- src/js/index.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 565179a..19de719 100644 --- a/index.html +++ b/index.html @@ -9,8 +9,11 @@ + + + - + diff --git a/src/js/index.ts b/src/js/index.ts index f2bd5d1..ed76955 100644 --- a/src/js/index.ts +++ b/src/js/index.ts @@ -129,5 +129,35 @@ async function ready(): Promise { }) } +// Custom function to emit toast notifications +// +// API Documentation: https://shoelace.style/components/alert/ +function notify(message: string, {variant = 'warning', icon = 'exclamation-triangle', duration = 3000} = {}) { + const alert = Object.assign(document.createElement('sl-alert'), { + variant, + closable: true, + duration, + innerHTML: ` + + ${message} + `, + }) + + document.body.append(alert) + // @ts-ignore + return alert.toast() +} + +if (new URL(window.location.toString(), window.location.origin).searchParams.get('debug') === 'true') { + window.addEventListener('unhandledrejection', event => { + notify(`[unhandledrejection]: ${event.reason}`) + }) + window.addEventListener('error', event => { + notify(`[error]: ${event.type}: ${event.message}\n`, {duration: Infinity}) + }) +} + await ready() fetchSubscriptions() + +throw new Error('foobar')