Skip to content

Commit 363c381

Browse files
committed
Update
1 parent 90eedab commit 363c381

1 file changed

Lines changed: 52 additions & 14 deletions

File tree

searxng.html

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="icon" href="https://searx.space/favicon.png" sizes="any">
1010
<link rel="icon" href="https://searx.space/favicon.svg" type="image/svg+xml">
1111
<link rel="apple-touch-icon" href="https://searx.space/favicon.png">
12-
<title>SearXNG Random Instance Redirector</title>
12+
<title>Random SearXNG Redirector</title>
1313
<style>
1414
code { background-color: rgba(128, 128, 128, 0.4); padding: 0.1rem 0.25rem 0.1rem 0.25rem }
1515
.pale { color: #808080 }
@@ -19,6 +19,7 @@
1919
<script type="module">
2020
import { detectAll } from '{{ site.url }}/assets/js/vendor/tinyld.min.js';
2121

22+
const INSTANCES_URL = 'https://searx.space/data/instances.json';
2223
const INSTANCES = ['search.charliewhiskey.net', 'search.im-in.space', 'search.ipsys.bf', 'search.mycotrip.tech', 'search.ononoki.org', 'search.pollorebozado.com', 'search.rowie.at', 'search.system51.co.uk', 'search.undertale.uk', 'search.url4irl.com', 'searx.bndkt.io', 'searx.dresden.network', 'searx.foss.family', 'searx.oloke.xyz', 'searx.ox2.fr', 'searx.party', 'searx.perennialte.ch', 'searx.tiekoetter.com', 'searx.zhenyapav.com', 'searxng.shreven.org']
2324
const LANGUAGES = ['en'];
2425
const TIMEOUT = 5000;
@@ -36,7 +37,7 @@
3637
});
3738
if (params.get('fast') === '1') return instances;
3839

39-
const response = await fetch('https://searx.space/data/instances.json');
40+
const response = await fetch(INSTANCES_URL);
4041
if (!response.ok) {
4142
console.log('failed to load instances');
4243
return instances;
@@ -117,31 +118,52 @@
117118

118119
const targetUrl = new URL(shuffledInstances[0]);
119120
targetUrl.pathname = '/search';
120-
targetUrl.searchParams.set('safesearch', params.get('safesearch') || '0');
121121

122+
const newParams = new Map;
122123
params
123124
.entries()
124125
.filter(([k, _]) => !CUSTOM_PARAMS.includes(k))
125-
.forEach(([k, v]) => targetUrl.searchParams.set(k, v));
126+
.forEach(([k, v]) => newParams.set(k, v));
126127

127128
const query = queryFromForm || params.get('q') || '';
128-
targetUrl.searchParams.set('language', detectLanguage(query, params));
129-
targetUrl.searchParams.set('q', query);
129+
newParams.set('language', detectLanguage(query, params));
130+
newParams.set('q', query);
131+
newParams.set('safesearch', params.get('safesearch') || '0');
130132

131133
const timeout = Number(params.get('timeout')) || TIMEOUT;
134+
const getMethod = params.get('get') === '1';
132135
for (let i = 0; i < shuffledInstances.length; i++) setTimeout(_ => {
133136
window.stop();
134137
const retryTargetUrl = new URL(targetUrl.toString());
135138
retryTargetUrl.host = new URL(shuffledInstances[i]).host;
136139
if (i > 0) {
137140
messageElement.innerHTML = `Attempt ${i + 1}/${shuffledInstances.length}: ${retryTargetUrl.host}`;
138141
}
139-
const href = retryTargetUrl.toString();
140-
console.log('trying', href);
141-
if (queryFromForm) {
142-
window.location.href = href;
142+
if (getMethod) {
143+
newParams.forEach((value, key) => retryTargetUrl.searchParams.set(key, value));
144+
const href = retryTargetUrl.toString();
145+
console.log('get', href);
146+
if (queryFromForm) {
147+
window.location.href = href;
148+
} else {
149+
window.location.replace(href);
150+
}
143151
} else {
144-
window.location.replace(href);
152+
const href = retryTargetUrl.toString();
153+
console.log('post', href);
154+
const form = document.createElement('form');
155+
form.method = 'POST';
156+
form.action = href;
157+
newParams.forEach((value, key) => {
158+
const input = document.createElement('input');
159+
input.type = 'hidden';
160+
input.name = key;
161+
input.value = value;
162+
form.appendChild(input);
163+
});
164+
document.body.appendChild(form);
165+
form.submit();
166+
document.body.removeChild(form);
145167
}
146168
}, i * timeout);
147169

@@ -153,9 +175,6 @@
153175
if (params.has('q')) {
154176
redirect(params);
155177
} else {
156-
const pageUrl = window.location.origin + window.location.pathname;
157-
document.body.innerHTML = `<p>This page redirects to a <a rel="noopener noreferrer nofollow" href="${pageUrl}#q=" onclick="window.location.replace('${pageUrl}#q=')">random SearXNG</a> instance.</p><p>It also supports the <a rel="noopener noreferrer nofollow" target="_blank" href="https://docs.searxng.org/dev/search_api.html">GET parameters</a> (provided as an anchor for privacy) and the optional parameters:<p><p><ul><li><code>languages=en,fr,ru</code> to use automatic language filter derived from the query; default is <code>${LANGUAGES.join(',')}</code></li><li><code>fast=1</code> to force use of predefined instances (instead of fetching them using the <a rel="noopener noreferrer nofollow" target="_blank" href="https://searx.space/data/instances.json">API</a>); default is <code>0</code></li><li><code>instances=search.ononoki.org,searx.bndkt.io</code> to predefine the instances; default is <code>${INSTANCES.join(',')}</code></li><li><code>timeout</code> in milliseconds until attempting the next instance; default is <code>${TIMEOUT}</code></li><li><code>attempts</code> how many instances to try; default is <code>${ATTEMPTS}</code></li></ul></p><p>Example for <strong>browser search engine settings</strong> (<code>about:preferences#search</code> or <code>chrome://settings/search</code>): <code>${pageUrl}#q=%s&fast=1&image_proxy=True&categories=images&languages=en,fr,ru</code>.</p><p>For local use: <code>wget ${pageUrl} -O searxng.html</code>.</p><p>Additionally can be combined with the Violentmonkey <a rel="noopener noreferrer nofollow" target="_blank" href="https://userscripts.codonaft.com/searxng-redirect-on-failure.js">userscript</a> to turn search failures into redirects as well.</p>`;
158-
159178
const input = document.createElement('input');
160179
input.name = 'q';
161180
input.placeholder = 'Search for...';
@@ -165,6 +184,7 @@
165184
input.autocorrect = 'off';
166185
input.dir = 'auto';
167186
input.style.width = '99%';
187+
input.style.margin = '2rem 0 0 0';
168188

169189
const form = document.createElement('form');
170190
form.addEventListener('submit', event => {
@@ -174,6 +194,24 @@
174194

175195
form.appendChild(input);
176196
document.body.appendChild(form);
197+
198+
const pageUrl = window.location.origin + window.location.pathname;
199+
const div = document.createElement('div');
200+
div.innerHTML = `
201+
<p>This page redirects to a <a rel="noopener noreferrer nofollow" href="${pageUrl}#q=" onclick="window.location.replace('${pageUrl}#q=')">random SearXNG</a> instance.</p>
202+
<p>It also supports the <a rel="noopener noreferrer nofollow" target="_blank" href="https://docs.searxng.org/dev/search_api.html">GET parameters</a> (provided as an anchor for privacy) and the optional parameters:</p>
203+
<ul>
204+
<li><code>languages</code> use automatic language filter derived from the query; comma-separated, default is <code>${LANGUAGES.join(',')}</code></li>
205+
<li><code>get</code> pass parameters to the instance using GET method; default is <code>0</code></li>
206+
<li><code>timeout</code> in milliseconds until attempting the next instance; default is <code>${TIMEOUT}</code></li>
207+
<li><code>attempts</code> how many instances to try; default is <code>${ATTEMPTS}</code></li>
208+
<li><code>fast</code> always use predefined instances (instead of fetching them using the <a rel="noopener noreferrer nofollow" target="_blank" href="${INSTANCES_URL}">API</a>); default is <code>0</code></li>
209+
<li><code>instances</code> predefined instances; comma-separated, default is <code>${INSTANCES.join(',')}</code>.</li>
210+
</ul>
211+
<p>Example for <strong>browser search engine settings</strong> (<code>about:preferences#search</code> or <code>chrome://settings/search</code>): <code>${pageUrl}#q=%s&fast=1&image_proxy=True&categories=images&languages=en,fr,ru</code>.</p>
212+
<p>For local use: <code>wget ${pageUrl} -O searxng.html</code>.</p>
213+
<p>Additionally can be combined with the Violentmonkey <a rel="noopener noreferrer nofollow" target="_blank" href="https://userscripts.codonaft.com/searxng-redirect-on-failure.js">userscript</a> to turn search failures into redirects as well.</p>`;
214+
document.body.appendChild(div);
177215
}
178216
};
179217

0 commit comments

Comments
 (0)