From af7e659c0ee7d2972f2e9f608bdbb6c149e1ddde Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 3 May 2021 21:39:16 +1000 Subject: [PATCH] merge bracketed-links with tweaks --- extension/helpers.js | 66 ++++++++++++------- extension/launcher.js | 9 ++- extension/repo/CHANGELOG.md | 2 + .../menu.css | 7 ++ .../menu.js | 14 ++-- .../client.css | 19 ++++++ .../client.js | 3 +- .../mod.json | 7 ++ 8 files changed, 97 insertions(+), 30 deletions(-) diff --git a/extension/helpers.js b/extension/helpers.js index 114e5e1..ea11507 100644 --- a/extension/helpers.js +++ b/extension/helpers.js @@ -16,6 +16,7 @@ export const ERROR = Symbol(), registry = {}; env.name = 'extension'; +env.supported = ['linux', 'win32', 'darwin', 'extension']; env.version = chrome.runtime.getManifest().version; env.openEnhancerMenu = () => chrome.runtime.sendMessage({ action: 'openEnhancerMenu' }); env.focusNotion = () => chrome.runtime.sendMessage({ action: 'focusNotion' }); @@ -287,6 +288,19 @@ registry.validate = async (mod, err, check) => { ), ]) ), + check( + 'environments', + mod.environments, + !mod.environments || Array.isArray(mod.environments) + ).then((environments) => + environments + ? environments === ERROR + ? ERROR + : environments.map((environment) => + check('environment', environment, env.supported.includes(environment)) + ) + : undefined + ), check( 'css', mod.css, @@ -440,8 +454,12 @@ registry.validate = async (mod, err, check) => { environments ? environments === ERROR ? ERROR - : environments.map((env) => - check('option.environment', env, typeof env === 'string') + : environments.map((environment) => + check( + 'option.environment', + environment, + env.supported.includes(environment) + ) ) : undefined ), @@ -483,29 +501,33 @@ registry.defaults = async (id) => { return defaults; }; -registry.get = async (enabled) => { - if (registry._list && registry._list.length) return registry._list; - registry._list = []; +registry.get = async (filter = (mod) => mod) => { if (!registry._errors) registry._errors = []; - for (const dir of await fs.getJSON('repo/registry.json')) { - const err = (message) => [registry._errors.push({ source: dir, message }), ERROR][1]; - try { - const mod = await fs.getJSON(`repo/${dir}/mod.json`); - mod._dir = dir; - mod.tags = mod.tags ?? []; - mod.css = mod.css ?? {}; - mod.js = mod.js ?? {}; - mod.options = mod.options ?? []; - - const check = (prop, value, condition) => - Promise.resolve(condition ? value : err(`invalid ${prop} ${JSON.stringify(value)}`)), - validation = await registry.validate(mod, err, check); - if (validation.every((condition) => condition !== ERROR)) registry._list.push(mod); - } catch (e) { - err('invalid mod.json'); + if (!registry._list || !registry._list.length) { + registry._list = []; + for (const dir of await fs.getJSON('repo/registry.json')) { + const err = (message) => [registry._errors.push({ source: dir, message }), ERROR][1]; + try { + const mod = await fs.getJSON(`repo/${dir}/mod.json`); + mod._dir = dir; + mod.tags = mod.tags ?? []; + mod.css = mod.css ?? {}; + mod.js = mod.js ?? {}; + mod.options = mod.options ?? []; + const check = (prop, value, condition) => + Promise.resolve( + condition ? value : err(`invalid ${prop} ${JSON.stringify(value)}`) + ), + validation = await registry.validate(mod, err, check); + if (validation.every((condition) => condition !== ERROR)) registry._list.push(mod); + } catch (e) { + err('invalid mod.json'); + } } } - return registry._list; + const list = []; + for (const mod of registry._list) if (await filter(mod)) list.push(mod); + return list; }; registry.errors = async () => { if (!registry._errors) await registry.get(); diff --git a/extension/launcher.js b/extension/launcher.js index 702decf..0767f34 100644 --- a/extension/launcher.js +++ b/extension/launcher.js @@ -6,10 +6,13 @@ 'use strict'; -import(chrome.runtime.getURL('helpers.js')).then(({ web, registry }) => { +import(chrome.runtime.getURL('helpers.js')).then(({ env, web, registry }) => { web.whenReady().then(async () => { - for (let mod of await registry.get()) { - if (!(await registry.enabled(mod.id))) continue; + for (let mod of await registry.get( + async (mod) => + (await registry.enabled(mod.id)) && + (!mod.environments || mod.environments.includes(env.name)) + )) { for (let sheet of mod.css?.client || []) { web.loadStyleset(`repo/${mod._dir}/${sheet}`); } diff --git a/extension/repo/CHANGELOG.md b/extension/repo/CHANGELOG.md index 93cc9c3..6041842 100644 --- a/extension/repo/CHANGELOG.md +++ b/extension/repo/CHANGELOG.md @@ -4,6 +4,7 @@ - improved: split the core mod into the theming & menu mods. - improved: new larger menu layout, with individual mod pages. +- improved: merged bracketed-links into tweaks. - removed: integrated scrollbar tweak (notion now includes by default). #### todo @@ -18,6 +19,7 @@ - dragarea height tweak - tray +- always on top **changelog below this point is a mix of the app enhancer and all mods.** **above this, changelogs have been split: see the** diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css index ba6dafe..c574112 100644 --- a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css @@ -292,6 +292,7 @@ label [data-icon='fa/question-circle'] { .library--toggle_label > :not(input) .library--toggle { position: relative; margin: auto 0 auto auto; + min-width: 2.25rem; width: 2.25rem; height: 1.25rem; display: block; @@ -406,6 +407,12 @@ label [data-icon='fa/question-circle'] { overflow-x: auto; } +/* is this weird? absolutely. but intentional. cos i wanted markdown __underline__ */ +strong { + text-decoration: underline; + font-weight: normal; +} + .tooltip { position: absolute; background: var(--theme--tooltip); diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js index cd77888..d21f8ae 100644 --- a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js @@ -9,8 +9,11 @@ const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e'; import { env, storage, web, fmt, fs, registry } from '../../helpers.js'; -for (let mod of await registry.get()) { - if (!(await registry.enabled(mod.id))) continue; +for (let mod of await registry.get( + async (mod) => + (await registry.enabled(mod.id)) && + (!mod.environments || mod.environments.includes(env.name)) +)) { for (let sheet of mod.css?.menu || []) { web.loadStyleset(`repo/${mod._dir}/${sheet}`); } @@ -83,7 +86,7 @@ components.card = { tags.includes('theme') && (await storage.get(_id, 'themes.autoresolve', true)) ) { - const themes = (await registry.get()).filter( + const themes = await registry.get( (mod) => mod.tags.includes('theme') && mod.id !== id && @@ -437,8 +440,11 @@ const views = { async library() { document.body.dataset.view = 'library'; document.querySelector('header [data-view-target="library"]').dataset.active = true; - for (let mod of await registry.get()) + for (const mod of await registry.get( + (mod) => !mod.environments || mod.environments.includes(env.name) + )) { this.$container.append(await components.card._generate(mod)); + } }, }; views._router = views._router.bind(views); diff --git a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.css b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.css index a82d330..e3a907d 100644 --- a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.css +++ b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.css @@ -1,6 +1,7 @@ /* * notion-enhancer: tweaks * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (c) 2020 arecsu * (https://notion-enhancer.github.io/) under the MIT license */ @@ -44,3 +45,21 @@ --theme--page-width: 100%; --theme--page-padding: calc(48px + env(safe-area-inset-left)); } + +.tweak--bracketed_links .notion-link-token span { + border-bottom: none !important; +} +.tweak--bracketed_links .notion-link-token:before { + content: '[['; + opacity: 0.7; + transition: opacity 100ms ease-in; +} +.tweak--bracketed_links .notion-link-token:after { + content: ']]'; + opacity: 0.7; + transition: opacity 100ms ease-in; +} +.tweak--bracketed_links .notion-link-token:hover::before, +.tweak--bracketed_links .notion-link-token:hover::after { + opacity: 1; +} diff --git a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.js b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.js index e96c7f6..89f7703 100644 --- a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.js +++ b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/client.js @@ -11,7 +11,7 @@ import { env, storage, web } from '../../helpers.js'; web.whenReady().then(async () => { if (['linux', 'win32'].includes(env.name)) { - // 'dragarea_height', + // dragarea_height } for (const tweak of [ @@ -21,6 +21,7 @@ web.whenReady().then(async () => { 'hide_help', 'condensed_bullets', 'scroll_db_toolbars', + 'bracketed_links', ]) { if (await storage.get(_id, `tweak.${tweak}`)) { document.body.classList.add(`tweak--${tweak}`); diff --git a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/mod.json b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/mod.json index 3c63a3b..5796e9f 100644 --- a/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/mod.json +++ b/extension/repo/tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2/mod.json @@ -73,6 +73,13 @@ "tooltip": "hold the shift key down while scrolling. up = left, down = right.", "type": "toggle", "value": true + }, + { + "key": "tweak.bracketed_links", + "label": "bracketed links", + "tooltip": "render links surrounded with [[brackets]] instead of __underlined__.", + "type": "toggle", + "value": false } ] }