From 3394aec204d20bf4d61841dabb0b7586db042e96 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Wed, 2 Feb 2022 21:22:34 +0300 Subject: renaming some files --- src/assets/javascripts/helpers/common.js | 6 +- src/assets/javascripts/helpers/google-maps.js | 168 --------------- src/assets/javascripts/helpers/google-search.js | 225 --------------------- src/assets/javascripts/helpers/google-translate.js | 109 ---------- src/assets/javascripts/helpers/maps.js | 168 +++++++++++++++ src/assets/javascripts/helpers/search.js | 225 +++++++++++++++++++++ src/assets/javascripts/helpers/translate.js | 109 ++++++++++ src/pages/background/background.js | 10 +- src/pages/options/maps.js | 2 +- src/pages/options/search.js | 2 +- src/pages/options/translate.js | 2 +- src/pages/popup/popup.js | 47 +++-- 12 files changed, 541 insertions(+), 532 deletions(-) delete mode 100644 src/assets/javascripts/helpers/google-maps.js delete mode 100644 src/assets/javascripts/helpers/google-search.js delete mode 100644 src/assets/javascripts/helpers/google-translate.js create mode 100644 src/assets/javascripts/helpers/maps.js create mode 100644 src/assets/javascripts/helpers/search.js create mode 100644 src/assets/javascripts/helpers/translate.js (limited to 'src') diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js index 72a62f66..9337e3f4 100644 --- a/src/assets/javascripts/helpers/common.js +++ b/src/assets/javascripts/helpers/common.js @@ -3,11 +3,11 @@ import youtubeHelper from "./youtube.js"; import instagramHelper from "./instagram.js"; import mediumHelper from "./medium.js"; import redditHelper from "./reddit.js"; -import searchHelper from "./google-search.js"; +import searchHelper from "./search.js"; import data from '../data.js' -import googleTranslateHelper from "./google-translate.js"; +import googleTranslateHelper from "./translate.js"; import wikipediaHelper from "./wikipedia.js"; -import mapsHelper from "./google-maps.js"; +import mapsHelper from "./maps.js"; import medium from "./medium.js"; diff --git a/src/assets/javascripts/helpers/google-maps.js b/src/assets/javascripts/helpers/google-maps.js deleted file mode 100644 index 321d5174..00000000 --- a/src/assets/javascripts/helpers/google-maps.js +++ /dev/null @@ -1,168 +0,0 @@ -import commonHelper from './common.js' - -const targets = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/; -const redirects = { - "normal": [ - "https://openstreetmap.org" - ] -}; -const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; -const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g; -const placeRegex = /\/place\/(.*)\//; -const travelModes = { - driving: "fossgis_osrm_car", - walking: "fossgis_osrm_foot", - bicycling: "fossgis_osrm_bike", - transit: "fossgis_osrm_car", // not implemented on OSM, default to car. -}; -const layers = { - none: "S", - transit: "T", - traffic: "S", // not implemented on OSM, default to standard. - bicycling: "C", -}; -function addressToLatLng(address, callback) { - const xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = () => { - if (xmlhttp.readyState === XMLHttpRequest.DONE) { - if (xmlhttp.status === 200) { - const json = JSON.parse(xmlhttp.responseText)[0]; - if (json) { - callback( - `${json.lat}%2C${json.lon}`, - `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}` - ); - } - } else { - console.info("Error: Status is " + xmlhttp.status); - } - } - }; - xmlhttp.open( - "GET", - `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, - false - ); - xmlhttp.send(); -} - -let disableOsm; -const getDisableOsm = () => disableOsm; -function setDisableOsm(val) { - disableOsm = val; - browser.storage.sync.set({ disableOsm }) -} - -let osmInstance; -const getOsmInstance = () => osmInstance; -function setOsmInstance(val) { - osmInstance = val; - browser.storage.sync.set({ osmInstance }) -}; - -async function redirect(url, initiator) { - await init() - if (disableOsm) - return null; - - if (initiator && initiator.host === "earth.google.com") - return null; - - let redirect; - let link = commonHelper.getRandomInstance(redirects.normal); - let mapCentre = ""; - let params = ""; - // Set map centre if present - if (url.pathname.match(mapCentreRegex)) { - const [, lat, lon, zoom] = url.pathname.match(mapCentreRegex); - mapCentre = `#map=${zoom}/${lat}/${lon}`; - } else if (url.search.includes("center=")) { - const [lat, lon] = url.searchParams.get("center").split(","); - mapCentre = `#map=${url.searchParams.get("zoom") || "17"}/${lat}/${lon}`; - // Set default zoom if mapCentre not present - } else { - params = "&zoom=17"; - } - // Set map layer - params = `${params}&layers=${layers[url.searchParams.get("layer")] || layers["none"] - }`; - // Handle Google Maps Embed API - if (url.pathname.split("/").includes("embed")) { - let query = ""; - if (url.searchParams.has("q")) query = url.searchParams.get("q"); - else if (url.searchParams.has("query")) query = url.searchParams.has("query"); - else if (url.searchParams.has("pb")) { - try { - query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; - } catch (error) { - console.error(error); - // Unable to find map marker in URL. - } - } - let marker, bbox; - addressToLatLng(query, (coords, boundingbox) => { - marker = coords; - bbox = boundingbox; - }); - redirect = `${link}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`; - // Handle Google Maps Directions - } else if (url.pathname.split("/").includes("dir")) { - const travelMode = travelModes[url.searchParams.get("travelmode")] || travelModes["driving"]; - let origin; - addressToLatLng(url.searchParams.get("origin"), (coords) => origin = coords); - let destination; - addressToLatLng(url.searchParams.get("destination"), (coords) => destination = coords); - redirect = `${link}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}${params}`; - // Get marker from data attribute - } else if ( - url.pathname.includes("data=") && - url.pathname.match(dataLatLngRegex) - ) { - const [mlat, mlon] = url.pathname.match(dataLatLngRegex); - redirect = `${link}/?mlat=${mlat.replace("!3d", "")}&mlon=${mlon.replace("!4d", "")}${mapCentre}${params}`; - // Get marker from ll param - } else if (url.searchParams.has("ll")) { - const [mlat, mlon] = url.searchParams.get("ll").split(","); - redirect = `${link}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; - // Get marker from viewpoint param. - } else if (url.searchParams.has("viewpoint")) { - const [mlat, mlon] = url.searchParams.get("viewpoint").split(","); - redirect = `${link}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; - // Use query as search if present. - } else { - let query; - if (url.searchParams.has("q")) query = url.searchParams.get("q"); - else if (url.searchParams.has("query")) query = url.searchParams.get("query"); - else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1]; - - redirect = `${link}/${query ? "search?query=" + query : ""}${mapCentre || "#"}${params}`; - } - return redirect; -} - - -async function init() { - let result = await browser.storage.sync.get([ - "disableOsm", - "osmInstance", - ]) - disableOsm = result.disableOsm; - osmInstance = result.osmInstance; -} - -export default { - targets, - redirects, - mapCentreRegex, - dataLatLngRegex, - placeRegex, - travelModes, - layers, - addressToLatLng, - getDisableOsm, - setDisableOsm, - getOsmInstance, - setOsmInstance, - redirect, - init, -}; diff --git a/src/assets/javascripts/helpers/google-search.js b/src/assets/javascripts/helpers/google-search.js deleted file mode 100644 index 54c8536f..00000000 --- a/src/assets/javascripts/helpers/google-search.js +++ /dev/null @@ -1,225 +0,0 @@ -import commonHelper from './common.js' - -const targets = [ - /https:\/\/google\.com/, - /https:\/\/.*\.google\.com/, - /https?:\/\/(((www|maps)\.)?(google\.).*(\/search)|search\.(google\.).*)/ -]; -const redirects = { - "searx": { - "normal": [ - "https://a.searx.space", - "https://anon.sx", - "https://beezboo.com", - "https://darmarit.org", - "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", - "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.feneas.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", - "https://timdor.noip.me", - "https://trovu.komun.org", - "https://www.gruble.de", - "https://www.perfectpixel.de", - "https://www.searxs.eu", - "https://www.webrats.xyz", - "https://xeek.com", - "searx.roflcopter.fr" - ], - "onion": [ - "https://3afisqjw2rxm6z7mmstyt5rx75qfqrgxnkzftknbp2vhipr2nrmrjdyd.onion", - "https://searxbgetrkiwxhdwi6svpgh7eotopqyxhbqiokrwzg7dcte44t36kyd.onion", - "https://suche.xyzco456vwisukfg.onion", - "https://w5rl6wsd7mzj4bdkbuqvzidet5osdsm5jhg2f7nvfidakfq5exda5wid.onion", - "https://4n53nafyi77iplnbrpmxnp3x4exbswwxigujaxy3b37fvr7bvlopxeyd.onion", - "https://z34ambyi6makk6ta7ksog2sljly2ctt2sa3apekb7wkllk72sxecdtad.onion", - "https://search.4bkxscubgtxwvhpe.onion", - "https://juy4e6eicawzdrz7.onion", - "https://z5vawdol25vrmorm4yydmohsd4u6rdoj2sylvoi3e3nqvxkvpqul7bqd.onion", - "https://zbuc3bbzbfdqqo2x46repx2ddajbha6fpsjeeptjhhhhzji3zopxdqyd.onion", - "https://f4qfqajszpx5b7itzxt6mb7kj4ktpgbdq7lq6xaiqyqx6a7de3epptad.onion", - "https://searx.cwuzdtzlubq5uual.onion", - "https://rq2w52kyrif3xpfihkgjnhqm3a5aqhoikpv72z3drpjglfzc2wr5z4yd.onion", - "https://searx3aolosaf3urwnhpynlhuokqsgz47si4pzz5hvb7uuzyjncl2tid.onion", - "https://searx.bsbvtqi5oq2cqzn32zt4cr2f2z2rwots3dq7gmdcnlyqoxko2wx6reqd.onion", - ], - "i2p": [ - "https://ransack.i2p", - "https://mqamk4cfykdvhw5kjez2gnvse56gmnqxn7vkvvbuor4k4j2lbbnq.b32.i2p", - ] - }, - "whoogle": { - "normal": [ - "https://s.alefvanoon.xyz", - "https://search.albony.xyz", - "https://search.exonip.de", - "https://search.garudalinux.org", - "https://search.sethforprivacy.com", - "https://whoogle.fossho.st", - "https://whooglesearch.net", - "https://www.whooglesearch.ml", - "https://whoogle.dcs0.hu", - ] - } -}; - -let disableSearch; -const getDisableSearch = () => disableSearch; -function setDisableSearch(val) { - disableSearch = val; - browser.storage.sync.set({ disableSearch }) - console.log("disableSearch: ", disableSearch) -} - -let searchInstance; -const getSearchInstance = () => searchInstance; -function setSearchInstance(val) { - searchInstance = val; - browser.storage.sync.set({ searchInstance }) -}; - -let searchFrontend; -const getSearchFrontend = () => searchFrontend; -function setSearchFrontend(val) { - searchFrontend = val; - browser.storage.sync.set({ searchFrontend }) - console.log("searchFrontend: ", searchFrontend) -}; - -async function redirect(url, initiator) { - await init(); - if (disableSearch) - return null; - - let instance; - let path; - if (searchFrontend == 'searx') { - instance = commonHelper.getRandomInstance(redirects.searx.normal); - path = "/" - } - if (searchFrontend == 'whoogle') { - instance = commonHelper.getRandomInstance(redirects.whoogle.normal); - path = "/search" - } - - let searchQuery = ""; - url.search.slice(1).split("&").forEach(function (input) { - if (input.startsWith("q=")) searchQuery = input; - }); - console.log("Will return"); - return `${instance}${path}?${searchQuery}`; -} - -async function init() { - console.log("Init Search Helper"); - let result = await browser.storage.sync.get([ - "disableSearch", - "searchInstance", - "searchFrontend", - ]) - disableSearch = result.disableSearch; - searchInstance = result.searchInstance; - searchFrontend = result.searchFrontend; -} - -export default { - targets, - redirects, - getDisableSearch, - setDisableSearch, - getSearchInstance, - setSearchInstance, - getSearchFrontend, - setSearchFrontend, - redirect, - init, -}; diff --git a/src/assets/javascripts/helpers/google-translate.js b/src/assets/javascripts/helpers/google-translate.js deleted file mode 100644 index b9a783ff..00000000 --- a/src/assets/javascripts/helpers/google-translate.js +++ /dev/null @@ -1,109 +0,0 @@ -import commonHelper from './common.js' - -const targets = [ - "translate.google.com", - "translate.google.no" -]; - -const redirects = { - "simplyTranslate": { - "normal": [ - "https://simplytranslate.org", - "https://st.alefvanoon.xyz", - "https://translate.josias.dev", - "https://translate.namazso.eu", - "https://translate.riverside.rocks", - "https://manerakai.asuscomm.com:447", - "https://translate.bus-hit.me", - "https://simplytranslate.pussthecat.org", - ] - }, - - "lingva": { - "normal": [ - "https://lingva.ml", - "https://translate.alefvanoon.xyz", - "https://translate.igna.rocks", - "https://lingva.pussthecat.org", - "https://translate.datatunnel.xyz", - ] - } - -}; - -let disableSimplyTranslate; -const getDisableSimplyTranslate = () => disableSimplyTranslate; -function setDisableSimplyTranslate(val) { - disableSimplyTranslate = val; - browser.storage.sync.set({ disableSimplyTranslate }) - console.log("disableSimplyTranslate: ", disableSimplyTranslate) -} - -let simplyTranslateInstance; -const getSimplyTranslateInstance = () => simplyTranslateInstance; -function setSimplyTranslateInstance(val) { - simplyTranslateInstance = val; - browser.storage.sync.set({ simplyTranslateInstance }) -}; - -let translateFrontend; -const getFrontend = () => translateFrontend; -function setFrontend(val) { - translateFrontend = val; - browser.storage.sync.set({ translateFrontend }) - console.log("Translate frontend: ", frontend) -} - -async function redirect(url, initiator) { - await init() - if (disableSimplyTranslate) { - console.log("SImplyTranslte disabled") - return null - }; - - let link; - if (translateFrontend == 'simplyTransalte') { - link = commonHelper.getRandomInstance(redirects.simplyTranslate.normal); - console.log(`${link}/${url.search}`); - return `${link}/${url.search}`; - } - else if (translateFrontend == 'lingva') { - let params_arr = url.search.split('&'); - params_arr[0] = params_arr[0].substring(1); - let myMap = new Map(); - for (let i = 0; i < params_arr.length; i++) { - let pair = params_arr[i].split('='); - myMap.set(pair[0], pair[1]); - } - link = commonHelper.getRandomInstance(redirects.lingva.normal); - if (myMap.get("sl") && myMap.get("tl") && myMap.get("text")) - return `${link}/${myMap.get("sl")}/${myMap.get("tl")}/${myMap.get("text")}`; - else - return link; - } -} - - -async function init() { - let result = await browser.storage.sync.get([ - "disableSimplyTranslate", - "simplyTranslateInstance", - "translateFrontend" - ]); - disableSimplyTranslate = result.disableSimplyTranslate || false; - simplyTranslateInstance = result.simplyTranslateInstance; - translateFrontend = result.translateFrontend || "simplyTransalte"; -} - -export default { - targets, - redirects, - getDisableSimplyTranslate, - setDisableSimplyTranslate, - getSimplyTranslateInstance, - setSimplyTranslateInstance, - getFrontend, - setFrontend, - redirect, - init, -}; diff --git a/src/assets/javascripts/helpers/maps.js b/src/assets/javascripts/helpers/maps.js new file mode 100644 index 00000000..321d5174 --- /dev/null +++ b/src/assets/javascripts/helpers/maps.js @@ -0,0 +1,168 @@ +import commonHelper from './common.js' + +const targets = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/; +const redirects = { + "normal": [ + "https://openstreetmap.org" + ] +}; +const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; +const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g; +const placeRegex = /\/place\/(.*)\//; +const travelModes = { + driving: "fossgis_osrm_car", + walking: "fossgis_osrm_foot", + bicycling: "fossgis_osrm_bike", + transit: "fossgis_osrm_car", // not implemented on OSM, default to car. +}; +const layers = { + none: "S", + transit: "T", + traffic: "S", // not implemented on OSM, default to standard. + bicycling: "C", +}; +function addressToLatLng(address, callback) { + const xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = () => { + if (xmlhttp.readyState === XMLHttpRequest.DONE) { + if (xmlhttp.status === 200) { + const json = JSON.parse(xmlhttp.responseText)[0]; + if (json) { + callback( + `${json.lat}%2C${json.lon}`, + `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}` + ); + } + } else { + console.info("Error: Status is " + xmlhttp.status); + } + } + }; + xmlhttp.open( + "GET", + `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, + false + ); + xmlhttp.send(); +} + +let disableOsm; +const getDisableOsm = () => disableOsm; +function setDisableOsm(val) { + disableOsm = val; + browser.storage.sync.set({ disableOsm }) +} + +let osmInstance; +const getOsmInstance = () => osmInstance; +function setOsmInstance(val) { + osmInstance = val; + browser.storage.sync.set({ osmInstance }) +}; + +async function redirect(url, initiator) { + await init() + if (disableOsm) + return null; + + if (initiator && initiator.host === "earth.google.com") + return null; + + let redirect; + let link = commonHelper.getRandomInstance(redirects.normal); + let mapCentre = ""; + let params = ""; + // Set map centre if present + if (url.pathname.match(mapCentreRegex)) { + const [, lat, lon, zoom] = url.pathname.match(mapCentreRegex); + mapCentre = `#map=${zoom}/${lat}/${lon}`; + } else if (url.search.includes("center=")) { + const [lat, lon] = url.searchParams.get("center").split(","); + mapCentre = `#map=${url.searchParams.get("zoom") || "17"}/${lat}/${lon}`; + // Set default zoom if mapCentre not present + } else { + params = "&zoom=17"; + } + // Set map layer + params = `${params}&layers=${layers[url.searchParams.get("layer")] || layers["none"] + }`; + // Handle Google Maps Embed API + if (url.pathname.split("/").includes("embed")) { + let query = ""; + if (url.searchParams.has("q")) query = url.searchParams.get("q"); + else if (url.searchParams.has("query")) query = url.searchParams.has("query"); + else if (url.searchParams.has("pb")) { + try { + query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; + } catch (error) { + console.error(error); + // Unable to find map marker in URL. + } + } + let marker, bbox; + addressToLatLng(query, (coords, boundingbox) => { + marker = coords; + bbox = boundingbox; + }); + redirect = `${link}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`; + // Handle Google Maps Directions + } else if (url.pathname.split("/").includes("dir")) { + const travelMode = travelModes[url.searchParams.get("travelmode")] || travelModes["driving"]; + let origin; + addressToLatLng(url.searchParams.get("origin"), (coords) => origin = coords); + let destination; + addressToLatLng(url.searchParams.get("destination"), (coords) => destination = coords); + redirect = `${link}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}${params}`; + // Get marker from data attribute + } else if ( + url.pathname.includes("data=") && + url.pathname.match(dataLatLngRegex) + ) { + const [mlat, mlon] = url.pathname.match(dataLatLngRegex); + redirect = `${link}/?mlat=${mlat.replace("!3d", "")}&mlon=${mlon.replace("!4d", "")}${mapCentre}${params}`; + // Get marker from ll param + } else if (url.searchParams.has("ll")) { + const [mlat, mlon] = url.searchParams.get("ll").split(","); + redirect = `${link}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; + // Get marker from viewpoint param. + } else if (url.searchParams.has("viewpoint")) { + const [mlat, mlon] = url.searchParams.get("viewpoint").split(","); + redirect = `${link}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; + // Use query as search if present. + } else { + let query; + if (url.searchParams.has("q")) query = url.searchParams.get("q"); + else if (url.searchParams.has("query")) query = url.searchParams.get("query"); + else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1]; + + redirect = `${link}/${query ? "search?query=" + query : ""}${mapCentre || "#"}${params}`; + } + return redirect; +} + + +async function init() { + let result = await browser.storage.sync.get([ + "disableOsm", + "osmInstance", + ]) + disableOsm = result.disableOsm; + osmInstance = result.osmInstance; +} + +export default { + targets, + redirects, + mapCentreRegex, + dataLatLngRegex, + placeRegex, + travelModes, + layers, + addressToLatLng, + getDisableOsm, + setDisableOsm, + getOsmInstance, + setOsmInstance, + redirect, + init, +}; diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js new file mode 100644 index 00000000..54c8536f --- /dev/null +++ b/src/assets/javascripts/helpers/search.js @@ -0,0 +1,225 @@ +import commonHelper from './common.js' + +const targets = [ + /https:\/\/google\.com/, + /https:\/\/.*\.google\.com/, + /https?:\/\/(((www|maps)\.)?(google\.).*(\/search)|search\.(google\.).*)/ +]; +const redirects = { + "searx": { + "normal": [ + "https://a.searx.space", + "https://anon.sx", + "https://beezboo.com", + "https://darmarit.org", + "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", + "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.feneas.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", + "https://timdor.noip.me", + "https://trovu.komun.org", + "https://www.gruble.de", + "https://www.perfectpixel.de", + "https://www.searxs.eu", + "https://www.webrats.xyz", + "https://xeek.com", + "searx.roflcopter.fr" + ], + "onion": [ + "https://3afisqjw2rxm6z7mmstyt5rx75qfqrgxnkzftknbp2vhipr2nrmrjdyd.onion", + "https://searxbgetrkiwxhdwi6svpgh7eotopqyxhbqiokrwzg7dcte44t36kyd.onion", + "https://suche.xyzco456vwisukfg.onion", + "https://w5rl6wsd7mzj4bdkbuqvzidet5osdsm5jhg2f7nvfidakfq5exda5wid.onion", + "https://4n53nafyi77iplnbrpmxnp3x4exbswwxigujaxy3b37fvr7bvlopxeyd.onion", + "https://z34ambyi6makk6ta7ksog2sljly2ctt2sa3apekb7wkllk72sxecdtad.onion", + "https://search.4bkxscubgtxwvhpe.onion", + "https://juy4e6eicawzdrz7.onion", + "https://z5vawdol25vrmorm4yydmohsd4u6rdoj2sylvoi3e3nqvxkvpqul7bqd.onion", + "https://zbuc3bbzbfdqqo2x46repx2ddajbha6fpsjeeptjhhhhzji3zopxdqyd.onion", + "https://f4qfqajszpx5b7itzxt6mb7kj4ktpgbdq7lq6xaiqyqx6a7de3epptad.onion", + "https://searx.cwuzdtzlubq5uual.onion", + "https://rq2w52kyrif3xpfihkgjnhqm3a5aqhoikpv72z3drpjglfzc2wr5z4yd.onion", + "https://searx3aolosaf3urwnhpynlhuokqsgz47si4pzz5hvb7uuzyjncl2tid.onion", + "https://searx.bsbvtqi5oq2cqzn32zt4cr2f2z2rwots3dq7gmdcnlyqoxko2wx6reqd.onion", + ], + "i2p": [ + "https://ransack.i2p", + "https://mqamk4cfykdvhw5kjez2gnvse56gmnqxn7vkvvbuor4k4j2lbbnq.b32.i2p", + ] + }, + "whoogle": { + "normal": [ + "https://s.alefvanoon.xyz", + "https://search.albony.xyz", + "https://search.exonip.de", + "https://search.garudalinux.org", + "https://search.sethforprivacy.com", + "https://whoogle.fossho.st", + "https://whooglesearch.net", + "https://www.whooglesearch.ml", + "https://whoogle.dcs0.hu", + ] + } +}; + +let disableSearch; +const getDisableSearch = () => disableSearch; +function setDisableSearch(val) { + disableSearch = val; + browser.storage.sync.set({ disableSearch }) + console.log("disableSearch: ", disableSearch) +} + +let searchInstance; +const getSearchInstance = () => searchInstance; +function setSearchInstance(val) { + searchInstance = val; + browser.storage.sync.set({ searchInstance }) +}; + +let searchFrontend; +const getSearchFrontend = () => searchFrontend; +function setSearchFrontend(val) { + searchFrontend = val; + browser.storage.sync.set({ searchFrontend }) + console.log("searchFrontend: ", searchFrontend) +}; + +async function redirect(url, initiator) { + await init(); + if (disableSearch) + return null; + + let instance; + let path; + if (searchFrontend == 'searx') { + instance = commonHelper.getRandomInstance(redirects.searx.normal); + path = "/" + } + if (searchFrontend == 'whoogle') { + instance = commonHelper.getRandomInstance(redirects.whoogle.normal); + path = "/search" + } + + let searchQuery = ""; + url.search.slice(1).split("&").forEach(function (input) { + if (input.startsWith("q=")) searchQuery = input; + }); + console.log("Will return"); + return `${instance}${path}?${searchQuery}`; +} + +async function init() { + console.log("Init Search Helper"); + let result = await browser.storage.sync.get([ + "disableSearch", + "searchInstance", + "searchFrontend", + ]) + disableSearch = result.disableSearch; + searchInstance = result.searchInstance; + searchFrontend = result.searchFrontend; +} + +export default { + targets, + redirects, + getDisableSearch, + setDisableSearch, + getSearchInstance, + setSearchInstance, + getSearchFrontend, + setSearchFrontend, + redirect, + init, +}; diff --git a/src/assets/javascripts/helpers/translate.js b/src/assets/javascripts/helpers/translate.js new file mode 100644 index 00000000..b9a783ff --- /dev/null +++ b/src/assets/javascripts/helpers/translate.js @@ -0,0 +1,109 @@ +import commonHelper from './common.js' + +const targets = [ + "translate.google.com", + "translate.google.no" +]; + +const redirects = { + "simplyTranslate": { + "normal": [ + "https://simplytranslate.org", + "https://st.alefvanoon.xyz", + "https://translate.josias.dev", + "https://translate.namazso.eu", + "https://translate.riverside.rocks", + "https://manerakai.asuscomm.com:447", + "https://translate.bus-hit.me", + "https://simplytranslate.pussthecat.org", + ] + }, + + "lingva": { + "normal": [ + "https://lingva.ml", + "https://translate.alefvanoon.xyz", + "https://translate.igna.rocks", + "https://lingva.pussthecat.org", + "https://translate.datatunnel.xyz", + ] + } + +}; + +let disableSimplyTranslate; +const getDisableSimplyTranslate = () => disableSimplyTranslate; +function setDisableSimplyTranslate(val) { + disableSimplyTranslate = val; + browser.storage.sync.set({ disableSimplyTranslate }) + console.log("disableSimplyTranslate: ", disableSimplyTranslate) +} + +let simplyTranslateInstance; +const getSimplyTranslateInstance = () => simplyTranslateInstance; +function setSimplyTranslateInstance(val) { + simplyTranslateInstance = val; + browser.storage.sync.set({ simplyTranslateInstance }) +}; + +let translateFrontend; +const getFrontend = () => translateFrontend; +function setFrontend(val) { + translateFrontend = val; + browser.storage.sync.set({ translateFrontend }) + console.log("Translate frontend: ", frontend) +} + +async function redirect(url, initiator) { + await init() + if (disableSimplyTranslate) { + console.log("SImplyTranslte disabled") + return null + }; + + let link; + if (translateFrontend == 'simplyTransalte') { + link = commonHelper.getRandomInstance(redirects.simplyTranslate.normal); + console.log(`${link}/${url.search}`); + return `${link}/${url.search}`; + } + else if (translateFrontend == 'lingva') { + let params_arr = url.search.split('&'); + params_arr[0] = params_arr[0].substring(1); + let myMap = new Map(); + for (let i = 0; i < params_arr.length; i++) { + let pair = params_arr[i].split('='); + myMap.set(pair[0], pair[1]); + } + link = commonHelper.getRandomInstance(redirects.lingva.normal); + if (myMap.get("sl") && myMap.get("tl") && myMap.get("text")) + return `${link}/${myMap.get("sl")}/${myMap.get("tl")}/${myMap.get("text")}`; + else + return link; + } +} + + +async function init() { + let result = await browser.storage.sync.get([ + "disableSimplyTranslate", + "simplyTranslateInstance", + "translateFrontend" + ]); + disableSimplyTranslate = result.disableSimplyTranslate || false; + simplyTranslateInstance = result.simplyTranslateInstance; + translateFrontend = result.translateFrontend || "simplyTransalte"; +} + +export default { + targets, + redirects, + getDisableSimplyTranslate, + setDisableSimplyTranslate, + getSimplyTranslateInstance, + setSimplyTranslateInstance, + getFrontend, + setFrontend, + redirect, + init, +}; diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 07335468..cc15e146 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -1,16 +1,16 @@ "use strict"; -import mapsHelper from "../../assets/javascripts/helpers/google-maps.js"; +import mapsHelper from "../../assets/javascripts/helpers/maps.js"; import twitterHelper from "../../assets/javascripts/helpers/twitter.js"; import youtubeHelper from "../../assets/javascripts/helpers/youtube.js"; import instagramHelper from "../../assets/javascripts/helpers/instagram.js"; import mediumHelper from "../../assets/javascripts/helpers/medium.js"; import redditHelper from "../../assets/javascripts/helpers/reddit.js"; -import searchHelper from "../../assets/javascripts/helpers/google-search.js"; -import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js"; +import searchHelper from "../../assets/javascripts/helpers/search.js"; +import googleTranslateHelper from "../../assets/javascripts/helpers/translate.js"; import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; import data from "../../assets/javascripts/data.js"; -import googleMaps from "../../assets/javascripts/helpers/google-maps.js"; +import googleMaps from "../../assets/javascripts/helpers/maps.js"; window.browser = window.browser || window.chrome; @@ -60,10 +60,8 @@ browser.webRequest.onBeforeRequest.addListener( else if (googleTranslateHelper.targets.includes(url.host)) newUrl = await googleTranslateHelper.redirect(url, initiator); - else if (searchHelper.targets.some((rx) => rx.test(url.href))) newUrl = await searchHelper.redirect(url, initiator) - else if (url.host.match(wikipediaHelper.targets)) newUrl = await wikipediaHelper.redirect(url, initiator); if (newUrl) { diff --git a/src/pages/options/maps.js b/src/pages/options/maps.js index a8819a50..b9845f69 100644 --- a/src/pages/options/maps.js +++ b/src/pages/options/maps.js @@ -1,4 +1,4 @@ -import mapsHelper from "../../assets/javascripts/helpers/google-maps.js"; +import mapsHelper from "../../assets/javascripts/helpers/maps.js"; let disableOsmElement = document.getElementById("disable-osm"); diff --git a/src/pages/options/search.js b/src/pages/options/search.js index 37e095a0..2029392c 100644 --- a/src/pages/options/search.js +++ b/src/pages/options/search.js @@ -1,4 +1,4 @@ -import searchHelper from "../../assets/javascripts/helpers/google-search.js"; +import searchHelper from "../../assets/javascripts/helpers/search.js"; let disableSearchElement = document.getElementById("disable-search"); let searchFrontendElement = document.getElementById("search-frontend"); diff --git a/src/pages/options/translate.js b/src/pages/options/translate.js index 639b87b7..11a97340 100644 --- a/src/pages/options/translate.js +++ b/src/pages/options/translate.js @@ -1,4 +1,4 @@ -import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js"; +import googleTranslateHelper from "../../assets/javascripts/helpers/translate.js"; let disableSimplyTranslateElement = document.getElementById("disable-simplyTranslate"); let translateFrontendElement = document.getElementById("translate-frontend"); diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 30587d3e..8ce57e3a 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -2,13 +2,13 @@ import commonHelper from "../../assets/javascripts/helpers/common.js"; import data from "../../assets/javascripts/data.js"; -import twitterHelper from "../../assets/javascripts/helpers/twitter.js"; import youtubeHelper from "../../assets/javascripts/helpers/youtube.js"; +import twitterHelper from "../../assets/javascripts/helpers/twitter.js"; import instagramHelper from "../../assets/javascripts/helpers/instagram.js"; -import mapsHelper from "../../assets/javascripts/helpers/google-maps.js"; +import mapsHelper from "../../assets/javascripts/helpers/maps.js"; import redditHelper from "../../assets/javascripts/helpers/reddit.js"; -import searchHelper from "../../assets/javascripts/helpers/google-search.js"; -import translateHelper from "../../assets/javascripts/helpers/google-translate.js"; +import searchHelper from "../../assets/javascripts/helpers/search.js"; +import translateHelper from "../../assets/javascripts/helpers/translate.js"; import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; import mediumHelper from "../../assets/javascripts/helpers/medium.js"; @@ -24,19 +24,31 @@ let disableScribeElement = document.querySelector("#disable-scribe"); window.browser = window.browser || window.chrome; -// Complete change to the global variables in data.js - -if (data.theme) document.body.classList.add(data.theme); -disableNitterElement.checked = !data.disableNitter; -disableInvidiousElement.checked = !data.disableInvidious; -disableBibliogramElement.checked = !data.disableBibliogram; -disableOsmElement.checked = !data.disableOsm; -disableRedditElement.checked = !data.disableReddit; -disableSearchElement.checked = !data.disableSearch; -disableSimplyTranslateElement.checked = !data.disableSimplyTranslate; -disableWikipediaElement.checked = !data.disableWikipedia; -disableScribeElement.checked = !data.disableScribe; - +async function wholeInit() { + console.log("staring async func") + await youtubeHelper.init(); + await twitterHelper.init(); + await instagramHelper.init(); + await mapsHelper.init(); + await redditHelper.init(); + await searchHelper.init(); + await translateHelper.init(); + await wikipediaHelper.init(); + await mediumHelper.init(); +}; + +wholeInit().then(() => { + if (data.theme) document.body.classList.add(data.theme); + disableNitterElement.checked = !twitterHelper.getDisableNitter(); + disableInvidiousElement.checked = !youtubeHelper.getDisableInvidious(); + disableBibliogramElement.checked = !instagramHelper.getDisableBibliogram(); + disableOsmElement.checked = !mapsHelper.getDisableOsm(); + disableRedditElement.checked = !redditHelper.getDisableReddit(); + disableSearchElement.checked = !searchHelper.getDisableSearch(); + disableSimplyTranslateElement.checked = !translateHelper.getDisableSimplyTranslate(); + disableWikipediaElement.checked = !wikipediaHelper.getDisableWikipedia(); + disableScribeElement.checked = !mediumHelper.getDisableScribe(); +}) disableNitterElement.addEventListener("change", (event) => twitterHelper.setDisableNitter(!event.target.checked) @@ -74,7 +86,6 @@ disableScribeElement.addEventListener("change", (event) => mediumHelper.setDisableScribe(!event.target.checked) ); - document.querySelector("#update-instances").addEventListener("click", () => { document.querySelector("#update-instances").innerHTML = '...'; if (commonHelper.updateInstances()) -- cgit 1.4.1