File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 11// ==UserScript==
22// @name SearXNG Redirect On Failure
33// @description Redirect to a random SearXNG instance in case of error and empty result
4- // @version 0.2
4+ // @version 0.3
55// @downloadURL https://userscripts.codonaft.com/searxng-redirect-on-failure.js
66// ==/UserScript==
77
88( _ => {
99 'use strict' ;
1010
1111 if ( performance . getEntriesByType ( 'navigation' ) [ 0 ] ?. responseStatus !== 200 ) return ;
12- if ( ! document . head . querySelector ( 'link[title="SearXNG"][ type="application/opensearchdescription+xml"]' ) ) return ;
12+ if ( ! document . head . querySelector ( 'link[type="application/opensearchdescription+xml"]' ) ?. title ?. includes ( 'SearXNG' ) && ! document . body . querySelector ( 'a[href="https://searx.space"]' ) ?. textContent ?. includes ( 'Public instances ') ) return ;
1313
1414 if ( ! document . body . querySelector ( 'td.response-time' ) && document . body . querySelector ( 'td.response-error' ) ) {
1515 const url = new URL ( window . location . href ) ;
2222 }
2323 url . pathname = '/searxng' ;
2424 url . searchParams . set ( 'fast' , '0' ) ;
25- window . location . replace ( url . toString ( ) ) ;
25+ const params = url . searchParams . toString ( ) ;
26+ url . searchParams . forEach ( ( _ , i ) => url . searchParams . delete ( i ) ) ;
27+ window . location . replace ( `${ url . toString ( ) } #${ params } ` ) ;
2628 }
2729} ) ( )
You can’t perform that action at this time.
0 commit comments