/* * notion-enhancer core: menu * (c) 2021 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ 'use strict'; const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e'; import { env, storage, web, fs, registry } from '../../api/_.mjs'; const sidebarSelector = '#notion-app > div > div.notion-cursor-listener > div.notion-sidebar-container > div > div > div > div:nth-child(4)'; web.whenReady([sidebarSelector]).then(async () => { const $enhancerSidebarElement = web.createElement( web.html`
${await fs.getText('icons/colour.svg')}
notion-enhancer
` ), errors = await registry.errors(), notifications = { list: await fs.getJSON('https://notion-enhancer.github.io/notifications.json'), dismissed: await storage.get(_id, 'notifications', []), }; notifications.waiting = notifications.list.filter( ({ id }) => !notifications.dismissed.includes(id) ); if (notifications.waiting.length + errors.length) { $enhancerSidebarElement.classList.add('enhancer--notifications'); $enhancerSidebarElement.children[0].append( web.createElement( web.html`
${ notifications.waiting.length + errors.length }
` ) ); } const setTheme = () => storage.set(_id, 'theme', document.querySelector('.notion-dark-theme') ? 'dark' : 'light'); $enhancerSidebarElement.addEventListener('click', () => { setTheme().then(env.openEnhancerMenu); }); window.addEventListener('focus', setTheme); window.addEventListener('blur', setTheme); setTheme(); document.querySelector(sidebarSelector).appendChild($enhancerSidebarElement); }); web.addHotkeyListener(await storage.get(_id, 'hotkey.focustoggle'), env.openEnhancerMenu);