Fix trade fair links to use bookmark keyword suffixes
This commit is contained in:
@@ -1021,53 +1021,58 @@
|
||||
return td;
|
||||
}
|
||||
|
||||
function buildTradeFairQueries(row) {
|
||||
function buildTradeFairBaseQuery(row) {
|
||||
const base = String(row.messe || '').trim();
|
||||
const city = String(row.stadt || '').trim();
|
||||
const topic = String(row.thema || '').split(',')[0].trim();
|
||||
|
||||
return [...new Set([
|
||||
base,
|
||||
[base, city].filter(Boolean).join(' '),
|
||||
[base, topic].filter(Boolean).join(' ')
|
||||
].map((entry) => entry.trim()).filter(Boolean))];
|
||||
if (base) {
|
||||
return base;
|
||||
}
|
||||
|
||||
function openQueryFallback(query) {
|
||||
const trimmed = String(query || '').trim();
|
||||
const fallback = [row.messe, row.stadt].map((value) => String(value || '').trim()).filter(Boolean).join(' ');
|
||||
return fallback.trim();
|
||||
}
|
||||
|
||||
function openBookmarkLikeFallback(baseQuery) {
|
||||
const trimmed = String(baseQuery || '').trim();
|
||||
if (!trimmed) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const suffixes = ['Gewinnspiel', 'gewinnen', 'verlosen'];
|
||||
let opened = 0;
|
||||
|
||||
suffixes.forEach((suffix) => {
|
||||
const query = `${trimmed} ${suffix}`.trim();
|
||||
if (typeof window.buildBookmarkSearchUrl === 'function') {
|
||||
const built = window.buildBookmarkSearchUrl(trimmed);
|
||||
const built = window.buildBookmarkSearchUrl(query);
|
||||
if (built) {
|
||||
window.open(built, '_blank', 'noopener');
|
||||
return 1;
|
||||
opened += 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const url = new URL('https://www.facebook.com/search/posts');
|
||||
url.searchParams.set('q', trimmed);
|
||||
url.searchParams.set('q', query);
|
||||
window.open(url.toString(), '_blank', 'noopener');
|
||||
return 1;
|
||||
opened += 1;
|
||||
});
|
||||
|
||||
return opened;
|
||||
}
|
||||
|
||||
function openTradeFairSearch(row) {
|
||||
const queries = buildTradeFairQueries(row);
|
||||
if (!queries.length) {
|
||||
const baseQuery = buildTradeFairBaseQuery(row);
|
||||
if (!baseQuery) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let opened = 0;
|
||||
if (typeof window.openBookmarkQueries === 'function') {
|
||||
opened = window.openBookmarkQueries(queries);
|
||||
opened = window.openBookmarkQueries(baseQuery);
|
||||
}
|
||||
|
||||
if (opened === 0) {
|
||||
queries.forEach((query) => {
|
||||
opened += openQueryFallback(query);
|
||||
});
|
||||
opened = openBookmarkLikeFallback(baseQuery);
|
||||
}
|
||||
|
||||
if (opened > 0) {
|
||||
|
||||
Reference in New Issue
Block a user