Aktueller Stand
This commit is contained in:
86
web/app.js
86
web/app.js
@@ -1287,13 +1287,97 @@ function buildBookmarkSearchUrl(query) {
|
||||
return searchUrl.toString();
|
||||
}
|
||||
|
||||
function splitBookmarkGroupOptions(rawGroup) {
|
||||
if (typeof rawGroup !== 'string') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return rawGroup
|
||||
.split(',')
|
||||
.map((entry) => entry.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function expandBookmarkQueryVariants(baseQuery) {
|
||||
const trimmed = typeof baseQuery === 'string' ? baseQuery.trim() : '';
|
||||
if (!trimmed) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const variants = [''];
|
||||
let cursor = 0;
|
||||
|
||||
while (cursor < trimmed.length) {
|
||||
const openIndex = trimmed.indexOf('(', cursor);
|
||||
if (openIndex === -1) {
|
||||
const tail = trimmed.slice(cursor);
|
||||
for (let i = 0; i < variants.length; i += 1) {
|
||||
variants[i] = `${variants[i]}${tail}`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const closeIndex = trimmed.indexOf(')', openIndex + 1);
|
||||
if (closeIndex === -1) {
|
||||
const tail = trimmed.slice(cursor);
|
||||
for (let i = 0; i < variants.length; i += 1) {
|
||||
variants[i] = `${variants[i]}${tail}`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const before = trimmed.slice(cursor, openIndex);
|
||||
if (before) {
|
||||
for (let i = 0; i < variants.length; i += 1) {
|
||||
variants[i] = `${variants[i]}${before}`;
|
||||
}
|
||||
}
|
||||
|
||||
const groupRaw = trimmed.slice(openIndex + 1, closeIndex);
|
||||
const options = splitBookmarkGroupOptions(groupRaw);
|
||||
|
||||
if (options.length) {
|
||||
const expanded = [];
|
||||
variants.forEach((prefix) => {
|
||||
options.forEach((option) => {
|
||||
expanded.push(`${prefix}${option}`);
|
||||
});
|
||||
});
|
||||
variants.splice(0, variants.length, ...expanded);
|
||||
} else {
|
||||
const literalGroup = trimmed.slice(openIndex, closeIndex + 1);
|
||||
for (let i = 0; i < variants.length; i += 1) {
|
||||
variants[i] = `${variants[i]}${literalGroup}`;
|
||||
}
|
||||
}
|
||||
|
||||
cursor = closeIndex + 1;
|
||||
}
|
||||
|
||||
return variants
|
||||
.map((variant) => variant.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function buildBookmarkSearchQueries(baseQuery) {
|
||||
const trimmed = typeof baseQuery === 'string' ? baseQuery.trim() : '';
|
||||
if (!trimmed) {
|
||||
return [...BOOKMARK_SUFFIXES];
|
||||
}
|
||||
|
||||
return BOOKMARK_SUFFIXES.map((suffix) => `${trimmed} ${suffix}`.trim());
|
||||
const baseVariants = expandBookmarkQueryVariants(trimmed);
|
||||
if (!baseVariants.length) {
|
||||
return BOOKMARK_SUFFIXES.map((suffix) => `${trimmed} ${suffix}`.trim());
|
||||
}
|
||||
|
||||
const queries = [];
|
||||
baseVariants.forEach((variant) => {
|
||||
BOOKMARK_SUFFIXES.forEach((suffix) => {
|
||||
queries.push(`${variant} ${suffix}`.trim());
|
||||
});
|
||||
});
|
||||
|
||||
return [...new Set(queries)];
|
||||
}
|
||||
|
||||
function openBookmarkQueries(baseQuery) {
|
||||
|
||||
Reference in New Issue
Block a user