Skip to content

Commit ca86daf

Browse files
committed
Update
1 parent c6eb9ae commit ca86daf

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

searxng.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,27 @@
7373
return detected[0].lang;
7474
};
7575

76-
const redirect = (url, query) => {
76+
const redirect = (url, queryFromForm) => {
7777
params
7878
.entries()
7979
.filter(([k, _]) => k !== 'fast' && k !== 'allowed_languages')
8080
.forEach(([k, v]) => url.searchParams.set(k, v));
81-
url.searchParams.set('q', query)
82-
url.searchParams.set('language', detectLanguage(query));
83-
console.log(url);
84-
window.location.replace(url.toString());
81+
url.searchParams.set('language', detectLanguage(params.get('q') || queryFromForm));
82+
if (queryFromForm) {
83+
url.searchParams.set('q', queryFromForm)
84+
window.location.href = url.toString();
85+
} else {
86+
window.location.replace(url.toString());
87+
}
8588
};
8689

8790
const pick = xs => xs[Math.floor(Math.random() * xs.length)];
8891
const targetUrl = new URL(pick(await loadInstances()));
8992
targetUrl.pathname = '/search';
9093
targetUrl.searchParams.set('safesearch', params.get('safesearch') || '0');
9194

92-
const query = params.get('q');
93-
if (query) {
94-
redirect(targetUrl, query);
95+
if (params.has('q')) {
96+
redirect(targetUrl);
9597
} else {
9698
const pageUrl = window.location.origin + window.location.pathname;
9799
document.body.innerHTML = `<p>This page accepts SearXNG <a target="_blank" href="https://docs.searxng.org/dev/search_api.html">GET parameters</a> and optional parameters:<p><p><ul><li><code>fast=1</code> for hardcoded instances</li><li><code>allowed_languages=en,fr,ru</code> for automatic language filter derived from the query</li></ul></p><p>Example for browser settings (<code>about:preferences#search</code> or <code>chrome://settings/search</code>):</p><p><code>${pageUrl}?q=%s&fast=1&image_proxy=True&categories=images</code></p><p>Use this page locally for the best performance: <code>wget ${pageUrl} -O searxng.html</code></p>`;

0 commit comments

Comments
 (0)