merge bracketed-links with tweaks

This commit is contained in:
dragonwocky 2021-05-03 21:39:16 +10:00
parent 86723e28eb
commit af7e659c0e
8 changed files with 97 additions and 30 deletions

View File

@ -16,6 +16,7 @@ export const ERROR = Symbol(),
registry = {}; registry = {};
env.name = 'extension'; env.name = 'extension';
env.supported = ['linux', 'win32', 'darwin', 'extension'];
env.version = chrome.runtime.getManifest().version; env.version = chrome.runtime.getManifest().version;
env.openEnhancerMenu = () => chrome.runtime.sendMessage({ action: 'openEnhancerMenu' }); env.openEnhancerMenu = () => chrome.runtime.sendMessage({ action: 'openEnhancerMenu' });
env.focusNotion = () => chrome.runtime.sendMessage({ action: 'focusNotion' }); 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( check(
'css', 'css',
mod.css, mod.css,
@ -440,8 +454,12 @@ registry.validate = async (mod, err, check) => {
environments environments
? environments === ERROR ? environments === ERROR
? ERROR ? ERROR
: environments.map((env) => : environments.map((environment) =>
check('option.environment', env, typeof env === 'string') check(
'option.environment',
environment,
env.supported.includes(environment)
)
) )
: undefined : undefined
), ),
@ -483,29 +501,33 @@ registry.defaults = async (id) => {
return defaults; return defaults;
}; };
registry.get = async (enabled) => { registry.get = async (filter = (mod) => mod) => {
if (registry._list && registry._list.length) return registry._list;
registry._list = [];
if (!registry._errors) registry._errors = []; if (!registry._errors) registry._errors = [];
for (const dir of await fs.getJSON('repo/registry.json')) { if (!registry._list || !registry._list.length) {
const err = (message) => [registry._errors.push({ source: dir, message }), ERROR][1]; registry._list = [];
try { for (const dir of await fs.getJSON('repo/registry.json')) {
const mod = await fs.getJSON(`repo/${dir}/mod.json`); const err = (message) => [registry._errors.push({ source: dir, message }), ERROR][1];
mod._dir = dir; try {
mod.tags = mod.tags ?? []; const mod = await fs.getJSON(`repo/${dir}/mod.json`);
mod.css = mod.css ?? {}; mod._dir = dir;
mod.js = mod.js ?? {}; mod.tags = mod.tags ?? [];
mod.options = mod.options ?? []; mod.css = mod.css ?? {};
mod.js = mod.js ?? {};
const check = (prop, value, condition) => mod.options = mod.options ?? [];
Promise.resolve(condition ? value : err(`invalid ${prop} ${JSON.stringify(value)}`)), const check = (prop, value, condition) =>
validation = await registry.validate(mod, err, check); Promise.resolve(
if (validation.every((condition) => condition !== ERROR)) registry._list.push(mod); condition ? value : err(`invalid ${prop} ${JSON.stringify(value)}`)
} catch (e) { ),
err('invalid mod.json'); 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 () => { registry.errors = async () => {
if (!registry._errors) await registry.get(); if (!registry._errors) await registry.get();

View File

@ -6,10 +6,13 @@
'use strict'; '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 () => { web.whenReady().then(async () => {
for (let mod of await registry.get()) { for (let mod of await registry.get(
if (!(await registry.enabled(mod.id))) continue; async (mod) =>
(await registry.enabled(mod.id)) &&
(!mod.environments || mod.environments.includes(env.name))
)) {
for (let sheet of mod.css?.client || []) { for (let sheet of mod.css?.client || []) {
web.loadStyleset(`repo/${mod._dir}/${sheet}`); web.loadStyleset(`repo/${mod._dir}/${sheet}`);
} }

View File

@ -4,6 +4,7 @@
- improved: split the core mod into the theming & menu mods. - improved: split the core mod into the theming & menu mods.
- improved: new larger menu layout, with individual mod pages. - improved: new larger menu layout, with individual mod pages.
- improved: merged bracketed-links into tweaks.
- removed: integrated scrollbar tweak (notion now includes by default). - removed: integrated scrollbar tweak (notion now includes by default).
#### todo #### todo
@ -18,6 +19,7 @@
- dragarea height tweak - dragarea height tweak
- tray - tray
- always on top
**changelog below this point is a mix of the app enhancer and all mods.** **changelog below this point is a mix of the app enhancer and all mods.**
**above this, changelogs have been split: see the** **above this, changelogs have been split: see the**

View File

@ -292,6 +292,7 @@ label [data-icon='fa/question-circle'] {
.library--toggle_label > :not(input) .library--toggle { .library--toggle_label > :not(input) .library--toggle {
position: relative; position: relative;
margin: auto 0 auto auto; margin: auto 0 auto auto;
min-width: 2.25rem;
width: 2.25rem; width: 2.25rem;
height: 1.25rem; height: 1.25rem;
display: block; display: block;
@ -406,6 +407,12 @@ label [data-icon='fa/question-circle'] {
overflow-x: auto; overflow-x: auto;
} }
/* is this weird? absolutely. but intentional. cos i wanted markdown __underline__ */
strong {
text-decoration: underline;
font-weight: normal;
}
.tooltip { .tooltip {
position: absolute; position: absolute;
background: var(--theme--tooltip); background: var(--theme--tooltip);

View File

@ -9,8 +9,11 @@
const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e'; const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e';
import { env, storage, web, fmt, fs, registry } from '../../helpers.js'; import { env, storage, web, fmt, fs, registry } from '../../helpers.js';
for (let mod of await registry.get()) { for (let mod of await registry.get(
if (!(await registry.enabled(mod.id))) continue; async (mod) =>
(await registry.enabled(mod.id)) &&
(!mod.environments || mod.environments.includes(env.name))
)) {
for (let sheet of mod.css?.menu || []) { for (let sheet of mod.css?.menu || []) {
web.loadStyleset(`repo/${mod._dir}/${sheet}`); web.loadStyleset(`repo/${mod._dir}/${sheet}`);
} }
@ -83,7 +86,7 @@ components.card = {
tags.includes('theme') && tags.includes('theme') &&
(await storage.get(_id, 'themes.autoresolve', true)) (await storage.get(_id, 'themes.autoresolve', true))
) { ) {
const themes = (await registry.get()).filter( const themes = await registry.get(
(mod) => (mod) =>
mod.tags.includes('theme') && mod.tags.includes('theme') &&
mod.id !== id && mod.id !== id &&
@ -437,8 +440,11 @@ const views = {
async library() { async library() {
document.body.dataset.view = 'library'; document.body.dataset.view = 'library';
document.querySelector('header [data-view-target="library"]').dataset.active = true; 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)); this.$container.append(await components.card._generate(mod));
}
}, },
}; };
views._router = views._router.bind(views); views._router = views._router.bind(views);

View File

@ -1,6 +1,7 @@
/* /*
* notion-enhancer: tweaks * notion-enhancer: tweaks
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/) * (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (c) 2020 arecsu
* (https://notion-enhancer.github.io/) under the MIT license * (https://notion-enhancer.github.io/) under the MIT license
*/ */
@ -44,3 +45,21 @@
--theme--page-width: 100%; --theme--page-width: 100%;
--theme--page-padding: calc(48px + env(safe-area-inset-left)); --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;
}

View File

@ -11,7 +11,7 @@ import { env, storage, web } from '../../helpers.js';
web.whenReady().then(async () => { web.whenReady().then(async () => {
if (['linux', 'win32'].includes(env.name)) { if (['linux', 'win32'].includes(env.name)) {
// 'dragarea_height', // dragarea_height
} }
for (const tweak of [ for (const tweak of [
@ -21,6 +21,7 @@ web.whenReady().then(async () => {
'hide_help', 'hide_help',
'condensed_bullets', 'condensed_bullets',
'scroll_db_toolbars', 'scroll_db_toolbars',
'bracketed_links',
]) { ]) {
if (await storage.get(_id, `tweak.${tweak}`)) { if (await storage.get(_id, `tweak.${tweak}`)) {
document.body.classList.add(`tweak--${tweak}`); document.body.classList.add(`tweak--${tweak}`);

View File

@ -73,6 +73,13 @@
"tooltip": "hold the shift key down while scrolling. up = left, down = right.", "tooltip": "hold the shift key down while scrolling. up = left, down = right.",
"type": "toggle", "type": "toggle",
"value": true "value": true
},
{
"key": "tweak.bracketed_links",
"label": "bracketed links",
"tooltip": "render links surrounded with [[brackets]] instead of __underlined__.",
"type": "toggle",
"value": false
} }
] ]
} }