diff --git a/CHANGELOG.md b/CHANGELOG.md index aebcc29..99bd132 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## \[unreleased] + +### ⛰️ Features + +- Add `.cjs` and `.mjs` to `.editorconfig` + ## \[[0.9.5](https://git.usrspace.at/XimeX/usrspace-browser-addon/releases/tag/v0.9.5)] - 2023-09-13 ### 🐛 Bug Fixes diff --git a/src/popup.js b/src/popup.js index c148a5c..4dac619 100644 --- a/src/popup.js +++ b/src/popup.js @@ -3,6 +3,32 @@ import { QUICK_LINKS } from './config.js'; const dateTimeFormat = Intl.DateTimeFormat([], { dateStyle: 'medium', timeStyle: 'short' }); +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', async () => { + await init(); + }); +} else { + await init(); +} + +async function init() { + setL10n(); + setLinks(); + + /** + * @type {import("../types").Storage} + */ + const { calendar, spaceApi } = await browser.storage.session.get(['calendar', 'spaceApi']); + + if (calendar) { + updateNextEvent(calendar); + } + if (spaceApi) { + updateSpaceApiJson(spaceApi); + updateState(spaceApi); + } +} + function setL10n() { document.querySelector('html').setAttribute('lang', browser.i18n.getUILanguage()); @@ -22,7 +48,9 @@ function setLinks() { for (const quickLink of QUICK_LINKS) { const template = getCleanTemplateById('template-link-item'); - template.querySelector('.link').dataset.url = quickLink.url; + const linkElement = template.querySelector('.link') + linkElement.dataset.url = quickLink.url; + linkElement.addEventListener('click', linkElementClickListener); const svgIcon = getCleanTemplateById(quickLink.iconTemplateId); svgIcon.querySelector('svg').setAttribute('aria-label', quickLink.text); @@ -45,30 +73,6 @@ async function linkElementClickListener(event) { } } -async function init() { - setL10n(); - setLinks(); - - const linkElements = document.querySelectorAll('.link'); - for (const linkElement of linkElements) { - linkElement.addEventListener('click', linkElementClickListener); - } - - /** - * @type {import("../types").Storage} - */ - const { calendar, spaceApi } = await browser.storage.session.get(['calendar', 'spaceApi']); - - if (calendar) { - updateNextEvent(calendar); - } - if (spaceApi) { - updateSpaceApiJson(spaceApi); - updateState(spaceApi); - } -} -await init(); - /** * @param {import("../types").Calendar} nextEvents */