libredirect/src/assets/javascripts/helpers/search.js

296 lines
9.1 KiB
JavaScript
Raw Normal View History

import commonHelper from './common.js'
const targets = [
/https:\/\/google\.com/,
/https:\/\/.*\.google\.com/,
/https?:\/\/(((www|maps)\.)?(google\.).*(\/search)|search\.(google\.).*)/
];
let redirects = {
2022-02-06 03:58:42 +01:00
"searx": {
2022-02-01 19:37:43 +01:00
"normal": [
"https://a.searx.space",
"https://anon.sx",
"https://beezboo.com",
2022-02-04 16:48:24 +01:00
"https://darmarit.org/searx",
"https://dynabyte.ca",
"https://engo.mint.lgbt",
"https://jsearch.pw",
"https://metasearch.nl",
"https://nibblehole.com",
"https://northboot.xyz",
"https://paulgo.io",
"https://procurx.pt",
"https://putin.agency",
"https://quickso.eu.org",
"https://s.zhaocloud.net",
"https://search.076.ne.jp",
"https://search.activemail.de",
"https://search.anonymize.com",
"https://search.antonkling.se",
"https://search.asynchronousexchange.com",
"https://search.biboumail.fr",
"https://search.blou.xyz",
"https://search.bluelock.org",
"https://search.bus-hit.me",
"https://search.disroot.org",
"https://search.ethibox.fr",
"https://search.jigsaw-security.com",
"https://search.jpope.org",
"https://search.mdosch.de",
2022-02-04 16:48:24 +01:00
"https://search.neet.works",
"https://search.ononoki.org",
"https://search.snopyta.org",
"https://search.st8.at",
"https://search.stinpriza.org",
"https://search.trom.tf",
"https://search.zdechov.net",
"https://searx.bar",
"https://searx.be",
"https://searx.bissisoft.com",
"https://searx.divided-by-zero.eu",
"https://searx.dresden.network",
"https://searx.esmailelbob.xyz",
"https://searx.everdot.org",
"https://searx.fmac.xyz",
"https://searx.fossencdi.org",
"https://searx.gnous.eu",
"https://searx.gnu.style",
"https://searx.hardwired.link",
"https://searx.hummel-web.at",
"https://searx.lavatech.top",
"https://searx.mastodontech.de",
"https://searx.mha.fi",
"https://searx.mxchange.org",
"https://searx.nakhan.net",
"https://searx.netzspielplatz.de",
"https://searx.nevrlands.de",
"https://searx.ninja",
"https://searx.nixnet.services",
"https://searx.openhoofd.nl",
"https://searx.operationtulip.com",
"https://searx.org",
"https://searx.prvcy.eu",
"https://searx.pwoss.org",
"https://searx.rasp.fr",
"https://searx.roughs.ru",
"https://searx.ru",
"https://searx.run",
"https://searx.s1gm4.eu",
"https://searx.sadblog.xyz",
"https://searx.semipvt.com",
"https://searx.slash-dev.de",
"https://searx.solusar.de",
"https://searx.sp-codes.de",
"https://searx.stuehieyr.com",
"https://searx.sunless.cloud",
"https://searx.theanonymouse.xyz",
"https://searx.thegreenwebfoundation.org",
"https://searx.tiekoetter.com",
"https://searx.tk",
"https://searx.tux.land",
"https://searx.tuxcloud.net",
"https://searx.tyil.nl",
"https://searx.vitanetworks.link",
"https://searx.webheberg.info",
"https://searx.xkek.net",
"https://searx.xyz",
"https://searx.zackptg5.com",
"https://searx.zapashcanon.fr",
"https://searx.zecircle.xyz",
"https://searxzh.cn",
"https://seeks.hsbp.org",
"https://serx.cf",
"https://spot.ecloud.global",
"https://suche.dasnetzundich.de",
"https://suche.uferwerk.org",
"https://swag.pw",
"https://sx.catgirl.cloud",
"https://sx.fedi.tech",
2022-02-04 16:48:24 +01:00
"https://timdor.noip.me/searx",
"https://trovu.komun.org",
"https://www.gruble.de",
2022-02-04 16:48:24 +01:00
"https://www.perfectpixel.de/searx",
"https://www.searxs.eu",
"https://www.webrats.xyz",
"https://xeek.com",
2022-02-04 16:48:24 +01:00
"https://searx.roflcopter.fr"
],
2022-02-01 19:37:43 +01:00
"onion": [
2022-02-04 16:48:24 +01:00
"http://3afisqjw2rxm6z7mmstyt5rx75qfqrgxnkzftknbp2vhipr2nrmrjdyd.onion",
"http://searxbgetrkiwxhdwi6svpgh7eotopqyxhbqiokrwzg7dcte44t36kyd.onion",
"http://suche.xyzco456vwisukfg.onion",
"http://w5rl6wsd7mzj4bdkbuqvzidet5osdsm5jhg2f7nvfidakfq5exda5wid.onion",
"http://4n53nafyi77iplnbrpmxnp3x4exbswwxigujaxy3b37fvr7bvlopxeyd.onion",
"http://z34ambyi6makk6ta7ksog2sljly2ctt2sa3apekb7wkllk72sxecdtad.onion",
"http://search.4bkxscubgtxwvhpe.onion",
"http://juy4e6eicawzdrz7.onion",
"http://z5vawdol25vrmorm4yydmohsd4u6rdoj2sylvoi3e3nqvxkvpqul7bqd.onion",
"http://zbuc3bbzbfdqqo2x46repx2ddajbha6fpsjeeptjhhhhzji3zopxdqyd.onion",
"http://f4qfqajszpx5b7itzxt6mb7kj4ktpgbdq7lq6xaiqyqx6a7de3epptad.onion",
"http://searx.cwuzdtzlubq5uual.onion",
"http://rq2w52kyrif3xpfihkgjnhqm3a5aqhoikpv72z3drpjglfzc2wr5z4yd.onion",
"http://searx3aolosaf3urwnhpynlhuokqsgz47si4pzz5hvb7uuzyjncl2tid.onion",
"http://searx.bsbvtqi5oq2cqzn32zt4cr2f2z2rwots3dq7gmdcnlyqoxko2wx6reqd.onion"
2022-02-01 19:37:43 +01:00
],
"i2p": [
2022-02-04 16:48:24 +01:00
"http://ransack.i2p",
"http://mqamk4cfykdvhw5kjez2gnvse56gmnqxn7vkvvbuor4k4j2lbbnq.b32.i2p"
2022-02-01 19:37:43 +01:00
]
},
2022-02-06 03:58:42 +01:00
"whoogle": {
2022-02-01 19:37:43 +01:00
"normal": [
"https://s.alefvanoon.xyz",
"https://search.albony.xyz",
"https://search.garudalinux.org",
"https://search.sethforprivacy.com",
"https://whoogle.fossho.st",
"https://whooglesearch.net",
"https://www.whooglesearch.ml",
2022-02-04 16:48:24 +01:00
"https://whoogle.dcs0.hu"
]
2022-02-04 16:48:24 +01:00
},
2022-02-01 19:37:43 +01:00
};
const getRedirects = () => redirects;
function setSearxRedirects(val) {
redirects.searx = val;
browser.storage.sync.set({ searchRedirects: redirects })
console.log("searxRedirects:", val)
}
let whoogleRedirectsChecks;
const getWhoogleRedirectsChecks = () => whoogleRedirectsChecks;
function setWhoogleRedirectsChecks(val) {
whoogleRedirectsChecks = val;
browser.storage.sync.set({ whoogleRedirectsChecks })
console.log("whoogleRedirectsChecks: ", val)
}
let whoogleCustomRedirects = [];
const getWhoogleCustomRedirects = () => whoogleCustomRedirects;
function setWhoogleCustomRedirects(val) {
whoogleCustomRedirects = val;
browser.storage.sync.set({ whoogleCustomRedirects })
console.log("whoogleCustomRedirects: ", val)
}
let searxRedirectsChecks;
const getSearxRedirectsChecks = () => searxRedirectsChecks;
function setSearxRedirectsChecks(val) {
searxRedirectsChecks = val;
browser.storage.sync.set({ searxRedirectsChecks })
console.log("searxRedirectsChecks: ", val)
}
let searxCustomRedirects = [];
const getSearxCustomRedirects = () => searxCustomRedirects;
function setSearxCustomRedirects(val) {
searxCustomRedirects = val;
browser.storage.sync.set({ searxCustomRedirects })
console.log("searxCustomRedirects: ", val)
}
function setWhoogleRedirects(val) {
redirects.whoogle = val;
browser.storage.sync.set({ searchRedirects: redirects })
console.log("whoogleRedirects:", val)
}
2022-02-01 19:37:43 +01:00
let disableSearch;
const getDisableSearch = () => disableSearch;
function setDisableSearch(val) {
disableSearch = val;
browser.storage.sync.set({ disableSearch })
console.log("disableSearch: ", disableSearch)
2022-02-01 19:37:43 +01:00
}
let searchFrontend;
const getSearchFrontend = () => searchFrontend;
function setSearchFrontend(val) {
searchFrontend = val;
browser.storage.sync.set({ searchFrontend })
console.log("searchFrontend: ", searchFrontend)
2022-02-01 19:37:43 +01:00
};
function redirect(url, initiator) {
if (disableSearch)
2022-02-01 19:37:43 +01:00
return null;
let randomInstance;
2022-02-01 19:37:43 +01:00
let path;
if (searchFrontend == 'searx') {
let instancesList = [...searxRedirectsChecks, ...searxCustomRedirects];
if (instancesList.length === 0) return null;
randomInstance = commonHelper.getRandomInstance(instancesList)
2022-02-01 19:37:43 +01:00
path = "/"
}
if (searchFrontend == 'whoogle') {
let instancesList = [...whoogleRedirectsChecks, ...whoogleCustomRedirects];
if (instancesList.length === 0) return null;
randomInstance = commonHelper.getRandomInstance(instancesList)
2022-02-01 19:37:43 +01:00
path = "/search"
}
let searchQuery = "";
url.search.slice(1).split("&").forEach(function (input) {
if (input.startsWith("q=")) searchQuery = input;
});
return `${randomInstance}${path}?${searchQuery}`;
2022-02-01 19:37:43 +01:00
}
function isSearch(url) {
return targets.some((rx) => rx.test(url.href));
}
async function init() {
let result = await browser.storage.sync.get([
"disableSearch",
"searchFrontend",
"searchRedirects",
"whoogleRedirectsChecks",
"whoogleCustomRedirects",
"searxRedirectsChecks",
"searxCustomRedirects",
])
2022-02-03 15:33:24 +01:00
disableSearch = result.disableSearch ?? false;
searchFrontend = result.searchFrontend ?? 'searx';
if (result.searchRedirects)
redirects = result.searchRedirects;
whoogleRedirectsChecks = result.whoogleRedirectsChecks ?? [...redirects.whoogle.normal];
whoogleCustomRedirects = result.whoogleCustomRedirects ?? [];
2022-02-06 19:59:55 +01:00
searxRedirectsChecks = result.searxRedirectsChecks ?? [...redirects.searx.normal];
searxCustomRedirects = result.searxCustomRedirects ?? [];
}
export default {
targets,
isSearch,
getRedirects,
setSearxRedirects,
setWhoogleRedirects,
2022-02-01 19:37:43 +01:00
getDisableSearch,
setDisableSearch,
2022-02-01 19:37:43 +01:00
getSearchFrontend,
setSearchFrontend,
getWhoogleRedirectsChecks,
setWhoogleRedirectsChecks,
getWhoogleCustomRedirects,
setWhoogleCustomRedirects,
getSearxRedirectsChecks,
setSearxRedirectsChecks,
getSearxCustomRedirects,
setSearxCustomRedirects,
2022-02-01 19:37:43 +01:00
redirect,
init,
};