From 67f9ffaddbd6f2f3ad857cac959fcc00883c52df Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Wed, 2 Sep 2020 22:21:17 +1000 Subject: [PATCH] ext. menu search upgrades (more stuff is searchable + case insensitive + cmd/ctrl f) --- CHANGELOG.md | 5 +++-- README.md | 2 +- mods/core/menu.js | 48 ++++++++++++++++++++++++++++------------------- pkg/apply.js | 4 ++-- pkg/remove.js | 2 +- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cad25d..4da52a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,14 @@ a feature and cleanup update. - improved: font imports must be define in the `mod.js` so that they can also be used in the enhancements menu. - improved: tiling window-manager support (can hide titlebars entirely without dragarea/buttons). +- improved: extensions menu search is now case insensitive and includes options, inputs and versions. + the search box can also for focused with `CMD/CTRL+F`. - bugfix: enhancer settings should no longer reset on update (though this will not have effect until the release after this one). - bugfix: blue select tags are no longer purple. - bugfix: page titles now respond to small-text mode. - bugfix: weekly calendar view height is now sized correctly according to its contents. -- bugfix: made the open enhancements menu hotkey configurable and changed the default to `alt + e` +- bugfix: made the open enhancements menu hotkey configurable and changed the default to `ALT+E` to remove conflict with the inline code highlight shortcut. - themes: "littlepig" (light + dark) = monospaced themes using emojis and colourful text. - extension: "font chooser" = customize fonts. for each option, type in the name of the font you would like to use, @@ -30,7 +32,6 @@ a feature and cleanup update. // todo -- improved: extensions menu search now includes options. - improved: added individual text-colour rules for different background colours. - improved: added variables for callout colouring. - bugfix: block-level text colours are now changed properly. diff --git a/README.md b/README.md index 518da63..cadfd0d 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ team to take to heart for future improvements." ## features once applied, modules can be configured via the graphical menu, which is opened from -the tray/menubar icon or with `CMD/CTRL+E`. +the tray/menubar icon or with `ALT+E`. ![](https://user-images.githubusercontent.com/16874139/91446210-84ee6b00-e8ba-11ea-9f40-187a150e4a82.png) diff --git a/mods/core/menu.js b/mods/core/menu.js index 2577e9c..682cd98 100644 --- a/mods/core/menu.js +++ b/mods/core/menu.js @@ -45,12 +45,13 @@ window['__start'] = async () => { event.key === 'Escape') ) document.activeElement.blur(); - } else if ( - (meta && event.key === '/') || - ((event.ctrlKey || event.metaKey) && - event.key === 'f' && - !event.altKey && - !event.shiftKey) + } else if (meta && event.key === '/') + document.querySelector('#search > input').focus(); + if ( + (event.ctrlKey || event.metaKey) && + event.key === 'f' && + !event.altKey && + !event.shiftKey ) document.querySelector('#search > input').focus(); }); @@ -171,7 +172,7 @@ window['__start'] = async () => { ); // search - const search_query = { + const search_filters = { enabled: true, disabled: true, tags: new Set( @@ -181,19 +182,28 @@ window['__start'] = async () => { .sort() ), }; + function innerText(elem) { + let text = ''; + for (let node of elem.childNodes) { + if (node.nodeType === 3) text += node.textContent; + if (node.nodeType === 1) + text += ['text', 'number'].includes(node.type) + ? node.value + : innerText(node); + } + return text; + } function search() { modules.loaded.forEach((mod) => { const $search_input = document.querySelector('#search > input'); if ( - (mod.elem.classList.contains('enabled') && !search_query.enabled) || - (mod.elem.classList.contains('disabled') && !search_query.disabled) || - !mod.tags.some((tag) => search_query.tags.has(tag)) || + (mod.elem.classList.contains('enabled') && !search_filters.enabled) || + (mod.elem.classList.contains('disabled') && !search_filters.disabled) || + !mod.tags.some((tag) => search_filters.tags.has(tag)) || ($search_input.value && - !( - mod.name + - mod.tags.map((tag) => `#${tag}`).join(' ') + - mod.desc - ).includes($search_input.value)) + !innerText(mod.elem) + .toLowerCase() + .includes($search_input.value.toLowerCase())) ) return (mod.elem.style.display = 'none'); mod.elem.style.display = 'block'; @@ -220,17 +230,17 @@ window['__start'] = async () => { } createTag( 'enabled', - (state) => [(search_query.enabled = state), search()] + (state) => [(search_filters.enabled = state), search()] // 'var(--theme--bg_green)' ); createTag( 'disabled', - (state) => [(search_query.disabled = state), search()] + (state) => [(search_filters.disabled = state), search()] // 'var(--theme--bg_red)' ); - for (let tag of search_query.tags) + for (let tag of search_filters.tags) createTag(`#${tag}`, (state) => [ - state ? search_query.tags.add(tag) : search_query.tags.delete(tag), + state ? search_filters.tags.add(tag) : search_filters.tags.delete(tag), search(), ]); diff --git a/pkg/apply.js b/pkg/apply.js index fb4a9a3..f360ea3 100644 --- a/pkg/apply.js +++ b/pkg/apply.js @@ -30,10 +30,10 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) { const check_app = await require('./check.js')(); switch (check_app.code) { case 1: - console.log(`~~ notion-enhancer v${version} already applied.`); + console.info(`~~ notion-enhancer v${version} already applied.`); return true; case 2: - console.log(` * ${check_app.msg}`); + console.warn(` * ${check_app.msg}`); do { process.stdout.write(' > overwrite? [Y/n]: '); overwrite_version = await helpers.readline(); diff --git a/pkg/remove.js b/pkg/remove.js index 98d608c..19917a5 100644 --- a/pkg/remove.js +++ b/pkg/remove.js @@ -68,7 +68,7 @@ module.exports = async function ({ // cleaning data folder: ~/.notion-enhancer if (await fs.pathExists(helpers.data_folder)) { - console.log(` ...data folder ${helpers.data_folder} found.`); + console.info(` ...data folder ${helpers.data_folder} found.`); if (delete_data === undefined) { do { process.stdout.write(' > delete? [Y/n]: ');