Skip to content

Commit 212bbb9

Browse files
committed
Update
1 parent a452abb commit 212bbb9

2 files changed

Lines changed: 21 additions & 26 deletions

File tree

force-searxng-parameters.user.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Force SearXNG Parameters
33
// @icon https://external-content.duckduckgo.com/ip3/searx.space.ico
4-
// @version 0.16
4+
// @version 0.17
55
// @downloadURL https://userscripts.codonaft.com/force-searxng-parameters.user.js
66
// ==/UserScript==
77

@@ -54,7 +54,7 @@ const params = {
5454
'enabled_plugins': ENABLED_PLUGINS.join(','),
5555
'image_proxy': 'True',
5656
'safesearch': 0,
57-
...Object.fromEntries(hashParams.entries()),
57+
...Object.fromEntries(Array.from(hashParams.entries())), // NOTE: fails on Firefox without Array.from
5858
};
5959

6060
const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
@@ -87,13 +87,26 @@ const form = b.querySelector('form#search');
8787
const queryInput = b.querySelector('input#q[type="text"]');
8888
if (form && queryInput) {
8989
try {
90+
form.method = METHOD;
91+
9092
const action = form.action.split('#')[0];
9193
queryInput.addEventListener('input', _ => {
9294
console.log('query', queryInput.value);
9395
const newParams = new URLSearchParams({ ...params, q: queryInput.value });
9496
form.action = `${action}#${newParams}`;
97+
if (!params.autocomplete) {
98+
event.preventDefault();
99+
event.stopImmediatePropagation();
100+
}
95101
}, true);
96-
form.method = METHOD;
102+
103+
if (!params.autocomplete) {
104+
['click', 'mousedown', 'keyup', 'Tab', 'Enter'].forEach(i => queryInput.addEventListener(i, event => {
105+
event.preventDefault();
106+
event.stopImmediatePropagation();
107+
}));
108+
}
109+
97110
Object.entries(params).forEach(([k, v]) => {
98111
if (k === 'q') return;
99112
const input = document.createElement('input');
@@ -109,13 +122,6 @@ if (form && queryInput) {
109122

110123
Object.entries(cookies).forEach(([k, v]) => document.cookie = `${k}=${v}`);
111124

112-
if (!params.autocomplete) {
113-
const autocomplete = b.querySelector('div.autocomplete');
114-
if (autocomplete) {
115-
autocomplete.style.display = 'none !important';
116-
}
117-
}
118-
119125
/*const subscribeOnChanges = (node, selector, f) => {
120126
const apply = (node, observer) => {
121127
if (node?.nodeType !== 1) return;

metasearch-hacks.user.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Hacks for the cute metasearch engine https://github.com/mat-1/metasearch2
3-
// @version 0.1
3+
// @version 0.2
44
// @downloadURL https://userscripts.codonaft.com/metasearch-hacks.user.js
55
// ==/UserScript==
66

@@ -10,27 +10,16 @@
1010
if (performance.getEntriesByType('navigation')[0]?.responseStatus !== 200) return;
1111
if (document.head?.querySelector('link[type="application/opensearchdescription+xml"]')?.title !== 'metasearch') return;
1212

13-
const DISABLE_AUTOCOMPLETE = true;
1413
const REDIRECT_ON_FAILURE = true;
1514
const FIX_IMAGES = true;
1615

1716
const body = document.body;
1817
const params = new URLSearchParams(window.location.search);
19-
const q = params.get('q');
20-
if (!body || !q) return;
21-
22-
if (DISABLE_AUTOCOMPLETE) {
23-
const input = body.querySelector('input#search-input');
24-
['click', 'input'].forEach(i => {
25-
input?.addEventListener(i, event => {
26-
event.preventDefault();
27-
event.stopImmediatePropagation();
28-
}, true);
29-
});
30-
}
18+
if (!body) return;
3119

20+
const q = params.get('q');
3221
const images = body.querySelectorAll('div.image-result');
33-
if (REDIRECT_ON_FAILURE && !body.querySelector('div.search-result') && images.length === 0) {
22+
if (REDIRECT_ON_FAILURE && q && images.length === 0 && !body.querySelector('div.search-result')) {
3423
const categories = params.get('tab') === 'images' ? 'images' : 'general';
3524
const newParams = new URLSearchParams({ q, categories });
3625
window.location.replace(`https://codonaft.com/searxng#${params}`);
@@ -53,7 +42,7 @@ if (FIX_IMAGES) {
5342
if (!proxyHref) return;
5443
link.href = proxyHref;
5544
if (image.complete && image.naturalWidth === 0) {
56-
link.classList.add(HIDE);
45+
link.closest('div.image-result')?.classList.add(HIDE);
5746
}
5847
});
5948
}

0 commit comments

Comments
 (0)