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 = {};
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();

View File

@ -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}`);
}

View File

@ -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**

View File

@ -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);

View File

@ -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);

View File

@ -1,6 +1,7 @@
/*
* notion-enhancer: tweaks
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (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;
}

View File

@ -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}`);

View File

@ -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
}
]
}