mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 05:29:02 +00:00
ext. menu search upgrades (more stuff is searchable + case insensitive + cmd/ctrl f)
This commit is contained in:
parent
63e4b574a9
commit
c5f5ce30e5
@ -45,12 +45,13 @@ window['__start'] = async () => {
|
|||||||
event.key === 'Escape')
|
event.key === 'Escape')
|
||||||
)
|
)
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
} else if (
|
} else if (meta && event.key === '/')
|
||||||
(meta && event.key === '/') ||
|
document.querySelector('#search > input').focus();
|
||||||
((event.ctrlKey || event.metaKey) &&
|
if (
|
||||||
event.key === 'f' &&
|
(event.ctrlKey || event.metaKey) &&
|
||||||
!event.altKey &&
|
event.key === 'f' &&
|
||||||
!event.shiftKey)
|
!event.altKey &&
|
||||||
|
!event.shiftKey
|
||||||
)
|
)
|
||||||
document.querySelector('#search > input').focus();
|
document.querySelector('#search > input').focus();
|
||||||
});
|
});
|
||||||
@ -171,7 +172,7 @@ window['__start'] = async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// search
|
// search
|
||||||
const search_query = {
|
const search_filters = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
disabled: true,
|
disabled: true,
|
||||||
tags: new Set(
|
tags: new Set(
|
||||||
@ -181,19 +182,28 @@ window['__start'] = async () => {
|
|||||||
.sort()
|
.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() {
|
function search() {
|
||||||
modules.loaded.forEach((mod) => {
|
modules.loaded.forEach((mod) => {
|
||||||
const $search_input = document.querySelector('#search > input');
|
const $search_input = document.querySelector('#search > input');
|
||||||
if (
|
if (
|
||||||
(mod.elem.classList.contains('enabled') && !search_query.enabled) ||
|
(mod.elem.classList.contains('enabled') && !search_filters.enabled) ||
|
||||||
(mod.elem.classList.contains('disabled') && !search_query.disabled) ||
|
(mod.elem.classList.contains('disabled') && !search_filters.disabled) ||
|
||||||
!mod.tags.some((tag) => search_query.tags.has(tag)) ||
|
!mod.tags.some((tag) => search_filters.tags.has(tag)) ||
|
||||||
($search_input.value &&
|
($search_input.value &&
|
||||||
!(
|
!innerText(mod.elem)
|
||||||
mod.name +
|
.toLowerCase()
|
||||||
mod.tags.map((tag) => `#${tag}`).join(' ') +
|
.includes($search_input.value.toLowerCase()))
|
||||||
mod.desc
|
|
||||||
).includes($search_input.value))
|
|
||||||
)
|
)
|
||||||
return (mod.elem.style.display = 'none');
|
return (mod.elem.style.display = 'none');
|
||||||
mod.elem.style.display = 'block';
|
mod.elem.style.display = 'block';
|
||||||
@ -220,17 +230,17 @@ window['__start'] = async () => {
|
|||||||
}
|
}
|
||||||
createTag(
|
createTag(
|
||||||
'enabled',
|
'enabled',
|
||||||
(state) => [(search_query.enabled = state), search()]
|
(state) => [(search_filters.enabled = state), search()]
|
||||||
// 'var(--theme--bg_green)'
|
// 'var(--theme--bg_green)'
|
||||||
);
|
);
|
||||||
createTag(
|
createTag(
|
||||||
'disabled',
|
'disabled',
|
||||||
(state) => [(search_query.disabled = state), search()]
|
(state) => [(search_filters.disabled = state), search()]
|
||||||
// 'var(--theme--bg_red)'
|
// 'var(--theme--bg_red)'
|
||||||
);
|
);
|
||||||
for (let tag of search_query.tags)
|
for (let tag of search_filters.tags)
|
||||||
createTag(`#${tag}`, (state) => [
|
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(),
|
search(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user