/* * notion-enhancer core: menu * (c) 2021 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ import { env, fs, storage, fmt, web, components } from '../../api/index.mjs'; import { tw } from './styles.mjs'; const notificationsURL = 'https://notion-enhancer.github.io/notifications.json'; export const notifications = { $container: web.html`
`, async add({ icon, message, id = undefined, color = undefined, link = undefined }) { const $notification = link ? web.html`` : web.html``, resolve = async () => { if (id !== undefined) { notifications.cache.push(id); await storage.set(['notifications'], notifications.cache); } $notification.remove(); }; $notification.addEventListener('click', resolve); $notification.addEventListener('keyup', (event) => { if (['Enter', ' '].includes(event.key)) resolve(); }); web.render( notifications.$container, web.render( $notification, web.html` ${fmt.md.renderInline(message)} `, web.html`${await components.feather(icon, { class: 'notification-icon' })}` ) ); return $notification; }, _onChange: false, async onChange() { if (this._onChange) return; this._onChange = true; const $notification = await this.add({ icon: 'refresh-cw', message: 'Reload to apply changes.', }); $notification.addEventListener('click', env.reload); }, }; (async () => { notifications.cache = await storage.get(['notifications'], []); notifications.provider = await fs.getJSON(notificationsURL); web.render(document.body, notifications.$container); for (const notification of notifications.provider) { const cached = notifications.cache.includes(notification.id), versionMatches = notification.version === env.version, envMatches = !notification.environments || notification.environments.includes(env.name); if (!cached && versionMatches && envMatches) notifications.add(notification); } })(); export const $changelogModal = web.render( web.html`` ); (async () => { const $changelogModalButton = web.html``; $changelogModalButton.addEventListener('click', async () => { $changelogModal.classList.remove('modal-visible'); await storage.set(['last_read_changelog'], env.version); }); web.render( $changelogModal, web.render( web.html``, web.html``, web.render(web.html``, $changelogModalButton) ) ); const lastReadChangelog = await storage.get(['last_read_changelog']); web.render(document.body, $changelogModal); if (lastReadChangelog !== env.version) { $changelogModal.classList.add('modal-visible'); } })();