From 9b3cf23b081080cc60d557d9c55f883ac93e4545 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Sun, 17 Oct 2021 22:57:41 +1100 Subject: [PATCH] extension: focus mode + only inject theming css if a theme is enabled, to reduce lag --- repo/focus-mode/client.css | 21 +++++++++++++++++++++ repo/focus-mode/client.mjs | 12 ++++++++++++ repo/focus-mode/mod.json | 30 ++++++++++++++++++++++++++++++ repo/indentation-lines/client.css | 1 + repo/registry.json | 3 ++- repo/theming/client.mjs | 10 +++++++++- repo/theming/mod.json | 2 +- 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 repo/focus-mode/client.css create mode 100644 repo/focus-mode/client.mjs create mode 100644 repo/focus-mode/mod.json diff --git a/repo/focus-mode/client.css b/repo/focus-mode/client.css new file mode 100644 index 0000000..5c13d5c --- /dev/null +++ b/repo/focus-mode/client.css @@ -0,0 +1,21 @@ +/* + * notion-enhancer: focus mode + * (c) 2020 Arecsu + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +.notion-sidebar-container[style*='width: 0px;'] ~ div .notion-topbar > :first-child { + opacity: 0 !important; + transition: opacity 200ms ease-in-out !important; +} +.notion-sidebar-container[style*='width: 0px;'] ~ div .notion-topbar > :first-child:hover { + opacity: 1 !important; +} + +[data-focus-mode='padded'] + .notion-sidebar-container[style*='width: 0px;'] + ~ div + .notion-frame { + height: calc(100vh - 90px) !important; +} diff --git a/repo/focus-mode/client.mjs b/repo/focus-mode/client.mjs new file mode 100644 index 0000000..660ae9c --- /dev/null +++ b/repo/focus-mode/client.mjs @@ -0,0 +1,12 @@ +/* + * notion-enhancer: focus mode + * (c) 2020 Arecsu + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +export default async function (api, db) { + if (await db.get(['padded'])) document.body.dataset.focusMode = 'padded'; +} diff --git a/repo/focus-mode/mod.json b/repo/focus-mode/mod.json new file mode 100644 index 0000000..91e6b79 --- /dev/null +++ b/repo/focus-mode/mod.json @@ -0,0 +1,30 @@ +{ + "name": "focus mode", + "id": "5a08598d-bfac-4167-9ae8-2bd0e2ef141e", + "version": "0.3.0", + "description": "hide the titlebar/menubar when the sidebar is closed (returns on hover).", + "tags": ["extension", "layout"], + "authors": [ + { + "name": "arecsu", + "email": "alejandro9r@gmail.com", + "homepage": "https://github.com/Arecsu", + "avatar": "https://avatars.githubusercontent.com/u/12679098" + } + ], + "css": { + "client": ["client.css"] + }, + "js": { + "client": ["client.mjs"] + }, + "options": [ + { + "type": "toggle", + "key": "padded", + "label": "even padding", + "tooltip": "matches the empty space at the top and sides of the frame with **extra padding at the bottom when the sidebar is hidden**", + "value": true + } + ] +} diff --git a/repo/indentation-lines/client.css b/repo/indentation-lines/client.css index 5222138..8acd6b6 100644 --- a/repo/indentation-lines/client.css +++ b/repo/indentation-lines/client.css @@ -1,6 +1,7 @@ /* * notion-enhancer: indentation lines * (c) 2020 Alexa Baldon (https://github.com/runargs) + * (c) 2021 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ diff --git a/repo/registry.json b/repo/registry.json index 335e757..ce291cf 100644 --- a/repo/registry.json +++ b/repo/registry.json @@ -22,5 +22,6 @@ "font-chooser", "collapse-properties", "scroll-to-top", - "indentation-lines" + "indentation-lines", + "focus-mode" ] diff --git a/repo/theming/client.mjs b/repo/theming/client.mjs index 98fc231..31bbf47 100644 --- a/repo/theming/client.mjs +++ b/repo/theming/client.mjs @@ -6,7 +6,15 @@ 'use strict'; -export default function ({ web }, db) { +export default async function ({ web, registry }, db) { + const enabledThemes = await registry.list( + async (m) => (await registry.enabled(m.id)) && m.tags.includes('theme') + ); + if (enabledThemes.length) { + web.loadStylesheet('repo/theming/theme.css'); + web.loadStylesheet('repo/theming/theme-colors.css'); + } + const updateTheme = () => document.documentElement.classList[ document.body.classList.contains('dark') ? 'add' : 'remove' diff --git a/repo/theming/mod.json b/repo/theming/mod.json index be376a6..91759d6 100644 --- a/repo/theming/mod.json +++ b/repo/theming/mod.json @@ -14,7 +14,7 @@ ], "css": { "frame": ["variables.css"], - "client": ["variables.css", "prism.css", "theme.css", "theme-colors.css"], + "client": ["variables.css", "prism.css"], "menu": ["variables.css", "prism.css"] }, "js": {