random-searx.user.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // ==UserScript==
  2. // @name random searx
  3. // @description gives a random searx instance
  4. // @version 1
  5. // @run-at document-start
  6. // @grant none
  7. // @namespace ?q=test
  8. // ==/UserScript==
  9. const domainCheck = /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/g;
  10. const url = 'https://2/data/instances.json';
  11. let currentURL = window.location.toString();
  12. let answer = [];
  13. // Fallback instance is set as search.fshm.in if the fetch query fails for some reason
  14. let randomInstance = 'search.fshm.in';
  15. if(currentURL.match(domainCheck)) {
  16. console.log("it's a domain");
  17. console.log(currentURL);
  18. }
  19. else {
  20. fetch(url)
  21. .then(response => response.json())
  22. .then(response => {
  23. searx_data = response.instances;
  24. for (let key in searx_data)
  25. if (searx_data[key]['http']['grade']=='A+')
  26. if ('tls' in searx_data[key])
  27. if (searx_data[key]['tls']['grade']=='A+')
  28. if ('html' in searx_data[key]) {
  29. temp = searx_data[key]['html']['grade'];
  30. if (temp=='V' || temp=='C')
  31. answer.push(key);
  32. }
  33. randomInstance = answer[Math.floor(Math.random() * answer.length)];
  34. console.log("instance search done");
  35. console.log(randomInstance)
  36. })
  37. const randomInstanceNoProtocol = randomInstance.replace(/^https?\:\/\//i, "");
  38. window.location = currentURL.replace(currentURL, randomInstanceNoProtocol+'?q='+currentURL);
  39. }
  40. // if (currentUrl.indexOf('blog.sahilister.in') !== - 1) {
  41. // const randomInstanceNoProtocol = randomInstance.replace(/^https?\:\/\//i, "");
  42. // window.location = currentURL.replace('blog.sahilister.in/', randomInstanceNoProtocol+'?q=');