Skip to content

Commit 16ca816

Browse files
committed
Update
1 parent 197f2b5 commit 16ca816

2 files changed

Lines changed: 49 additions & 19 deletions

File tree

metasearch-hacks.user.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ==UserScript==
2+
// @name Hacks for the cute metasearch engine https://github.com/mat-1/metasearch2
3+
// @version 0.1
4+
// @downloadURL https://userscripts.codonaft.com/metasearch-hacks.user.js
5+
// ==/UserScript==
6+
7+
(_ => {
8+
'use strict';
9+
10+
if (performance.getEntriesByType('navigation')[0]?.responseStatus !== 200) return;
11+
if (document.head?.querySelector('link[type="application/opensearchdescription+xml"]')?.title !== 'metasearch') return;
12+
13+
const FIX_IMAGES = true;
14+
const REDIRECT_ON_FAILURE = true;
15+
16+
const params = new URLSearchParams(window.location.search);
17+
const q = params.get('q');
18+
if (!q) return;
19+
const body = document.body;
20+
21+
const images = body.querySelectorAll('div.image-result');
22+
if (REDIRECT_ON_FAILURE && !body.querySelector('div.search-result') && images.length === 0) {
23+
const categories = params.get('tab') === 'images' ? 'images' : 'general';
24+
const newParams = new URLSearchParams({ q, categories });
25+
window.location.replace(`https://codonaft.com/searxng#${params}`);
26+
}
27+
28+
if (FIX_IMAGES) {
29+
const HIDE = '__hide';
30+
try {
31+
const style = document.createElement('style');
32+
style.innerHTML = `.${HIDE} { display: none !important }`;
33+
body.appendChild(style);
34+
} catch (e) {
35+
console.error(e);
36+
}
37+
38+
images.forEach(i => {
39+
const link = i.querySelector('a.image-result-anchor');
40+
const image = link?.querySelector('div.image-result-img-container img');
41+
const proxyHref = image?.src;
42+
if (!proxyHref) return;
43+
link.href = proxyHref;
44+
if (image.complete && image.naturalWidth === 0) {
45+
link.classList.add(HIDE);
46+
}
47+
});
48+
}
49+
})();

redirect-metasearch-on-failure.user.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)