2022-02-12 20:28:36 +01:00
|
|
|
window.browser = window.browser || window.chrome;
|
|
|
|
|
2022-02-02 15:46:14 +01:00
|
|
|
import commonHelper from './common.js'
|
|
|
|
|
2022-01-31 19:01:16 +01:00
|
|
|
const targets = [
|
2022-02-20 20:47:13 +01:00
|
|
|
/https?:\/\/(www\.|maps\.|search\.|)google\.com(\...|)(\/search\?..*|\/$)/,
|
|
|
|
// /https?:\/\/yandex\.com(\...|)(\/search\/..*|\/$)/,
|
2021-01-11 02:39:26 +01:00
|
|
|
];
|
2022-02-03 11:41:23 +01:00
|
|
|
let redirects = {
|
2022-02-06 03:58:42 +01:00
|
|
|
"searx": {
|
2022-02-20 20:47:13 +01:00
|
|
|
"normal": [],
|
|
|
|
"tor": [],
|
|
|
|
"i2p": []
|
2022-02-01 19:37:43 +01:00
|
|
|
},
|
2022-02-06 03:58:42 +01:00
|
|
|
"whoogle": {
|
2022-02-20 20:47:13 +01:00
|
|
|
"normal": [],
|
2022-02-20 17:00:12 +01:00
|
|
|
"tor": []
|
2022-02-04 16:48:24 +01:00
|
|
|
},
|
2022-02-01 19:37:43 +01:00
|
|
|
};
|
2022-02-04 00:13:37 +01:00
|
|
|
const getRedirects = () => redirects;
|
2022-02-16 16:54:13 +01:00
|
|
|
const getCustomRedirects = () => {
|
2022-02-12 10:30:30 +01:00
|
|
|
return {
|
|
|
|
"searx": {
|
2022-02-20 20:47:13 +01:00
|
|
|
"normal": [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects],
|
|
|
|
"tor": [...searxTorRedirectsChecks, ...searxTorCustomRedirects],
|
2022-02-12 10:30:30 +01:00
|
|
|
},
|
|
|
|
"whoogle": {
|
2022-02-20 20:47:13 +01:00
|
|
|
"normal": [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects],
|
|
|
|
"normal": [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]
|
2022-02-12 10:30:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2022-02-04 00:13:37 +01:00
|
|
|
|
|
|
|
function setSearxRedirects(val) {
|
|
|
|
redirects.searx = val;
|
|
|
|
browser.storage.sync.set({ searchRedirects: redirects })
|
|
|
|
console.log("searxRedirects:", val)
|
2022-02-20 20:47:13 +01:00
|
|
|
for (const item of searxNormalRedirectsChecks) if (!redirects.searx.normal.includes(item)) {
|
|
|
|
var index = searxNormalRedirectsChecks.indexOf(item);
|
|
|
|
if (index !== -1) searxNormalRedirectsChecks.splice(index, 1);
|
2022-02-08 16:28:25 +01:00
|
|
|
}
|
2022-02-20 20:47:13 +01:00
|
|
|
setSearxNormalRedirectsChecks(searxNormalRedirectsChecks);
|
|
|
|
|
|
|
|
for (const item of searxTorRedirectsChecks) if (!redirects.searx.tor.includes(item)) {
|
|
|
|
var index = searxTorRedirectsChecks.indexOf(item);
|
|
|
|
if (index !== -1) searxTorRedirectsChecks.splice(index, 1);
|
|
|
|
}
|
|
|
|
setSearxTorRedirectsChecks(searxTorRedirectsChecks);
|
2022-02-04 00:13:37 +01:00
|
|
|
}
|
2022-02-16 04:41:24 +01:00
|
|
|
|
|
|
|
function setWhoogleRedirects(val) {
|
|
|
|
redirects.whoogle = val;
|
|
|
|
browser.storage.sync.set({ searchRedirects: redirects })
|
|
|
|
console.log("whoogleRedirects:", val)
|
2022-02-20 20:47:13 +01:00
|
|
|
for (const item of whoogleNormalRedirectsChecks) if (!redirects.whoogle.normal.includes(item)) {
|
|
|
|
var index = whoogleNormalRedirectsChecks.indexOf(item);
|
|
|
|
if (index !== -1) whoogleNormalRedirectsChecks.splice(index, 1);
|
|
|
|
}
|
|
|
|
setWhoogleNormalRedirectsChecks(whoogleNormalRedirectsChecks);
|
|
|
|
|
|
|
|
for (const item of whoogleTorRedirectsChecks) if (!redirects.whoogle.tor.includes(item)) {
|
|
|
|
var index = whoogleTorRedirectsChecks.indexOf(item);
|
|
|
|
if (index !== -1) whoogleTorRedirectsChecks.splice(index, 1);
|
2022-02-16 16:54:13 +01:00
|
|
|
}
|
2022-02-20 20:47:13 +01:00
|
|
|
setWhoogleTorRedirectsChecks(whoogleTorRedirectsChecks);
|
2022-02-16 04:41:24 +01:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
let whoogleNormalRedirectsChecks;
|
|
|
|
const getWhoogleNormalRedirectsChecks = () => whoogleNormalRedirectsChecks;
|
|
|
|
function setWhoogleNormalRedirectsChecks(val) {
|
|
|
|
whoogleNormalRedirectsChecks = val;
|
|
|
|
browser.storage.sync.set({ whoogleNormalRedirectsChecks })
|
|
|
|
console.log("whoogleNormalRedirectsChecks: ", val)
|
2022-02-06 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
let whoogleTorRedirectsChecks;
|
|
|
|
const getWhoogleTorRedirectsChecks = () => whoogleTorRedirectsChecks;
|
|
|
|
function setWhoogleTorRedirectsChecks(val) {
|
|
|
|
whoogleTorRedirectsChecks = val;
|
|
|
|
browser.storage.sync.set({ whoogleTorRedirectsChecks })
|
|
|
|
console.log("whoogleTorRedirectsChecks: ", val)
|
2022-02-06 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
let whoogleNormalCustomRedirects = [];
|
|
|
|
const getWhoogleNormalCustomRedirects = () => whoogleNormalCustomRedirects;
|
|
|
|
function setWhoogleNormalCustomRedirects(val) {
|
|
|
|
whoogleNormalCustomRedirects = val;
|
|
|
|
browser.storage.sync.set({ whoogleNormalCustomRedirects })
|
|
|
|
console.log("whoogleNormalCustomRedirects: ", val)
|
2022-02-06 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
let whoogleTorCustomRedirects = [];
|
|
|
|
const getWhoogleTorCustomRedirects = () => whoogleTorCustomRedirects;
|
|
|
|
function setWhoogleTorCustomRedirects(val) {
|
|
|
|
whoogleTorCustomRedirects = val;
|
|
|
|
browser.storage.sync.set({ whoogleTorCustomRedirects })
|
|
|
|
console.log("whoogleTorCustomRedirects: ", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
let searxNormalRedirectsChecks;
|
|
|
|
const getSearxNormalRedirectsChecks = () => searxNormalRedirectsChecks;
|
|
|
|
function setSearxNormalRedirectsChecks(val) {
|
|
|
|
searxNormalRedirectsChecks = val;
|
|
|
|
browser.storage.sync.set({ searxNormalRedirectsChecks })
|
|
|
|
console.log("searxNormalRedirectsChecks: ", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
let searxTorRedirectsChecks;
|
|
|
|
const getSearxTorRedirectsChecks = () => searxTorRedirectsChecks;
|
|
|
|
function setSearxTorRedirectsChecks(val) {
|
|
|
|
searxTorRedirectsChecks = val;
|
|
|
|
browser.storage.sync.set({ searxTorRedirectsChecks })
|
|
|
|
console.log("searxTorRedirectsChecks: ", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
let searxNormalCustomRedirects = [];
|
|
|
|
const getSearxNormalCustomRedirects = () => searxNormalCustomRedirects;
|
|
|
|
function setSearxNormalCustomRedirects(val) {
|
|
|
|
searxNormalCustomRedirects = val;
|
|
|
|
browser.storage.sync.set({ searxNormalCustomRedirects })
|
|
|
|
console.log("searxNormalCustomRedirects: ", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
let searxTorCustomRedirects = [];
|
|
|
|
const getSearxTorCustomRedirects = () => searxTorCustomRedirects;
|
|
|
|
function setSearxTorCustomRedirects(val) {
|
|
|
|
searxTorCustomRedirects = val;
|
|
|
|
browser.storage.sync.set({ searxTorCustomRedirects })
|
|
|
|
console.log("searxTorCustomRedirects: ", val)
|
2022-02-06 15:24:39 +01:00
|
|
|
}
|
2022-02-04 00:13:37 +01:00
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
let disable;
|
|
|
|
const getDisable = () => disable;
|
|
|
|
function setDisable(val) {
|
|
|
|
disable = val;
|
|
|
|
browser.storage.sync.set({ disableSearch: disable })
|
|
|
|
console.log("disableSearch: ", disable)
|
2022-02-01 19:37:43 +01:00
|
|
|
}
|
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
let frontend;
|
|
|
|
const getFrontend = () => frontend;
|
|
|
|
function setFrontend(val) {
|
|
|
|
frontend = val;
|
|
|
|
browser.storage.sync.set({ searchFrontend: frontend })
|
|
|
|
console.log("searchFrontend: ", frontend)
|
2022-02-01 19:37:43 +01:00
|
|
|
};
|
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
let protocol;
|
|
|
|
const getprotocol = () => protocol;
|
|
|
|
function setProtocol(val) {
|
|
|
|
protocol = val;
|
|
|
|
browser.storage.sync.set({ searchProtocol: val })
|
|
|
|
console.log("searchProtocol: ", val)
|
|
|
|
}
|
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
function isSearch(url, initiator) {
|
|
|
|
if (disable) return false;
|
|
|
|
return targets.some((rx) => rx.test(url.href));
|
|
|
|
}
|
2022-02-01 19:37:43 +01:00
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
function redirect(url) {
|
2022-02-06 15:24:39 +01:00
|
|
|
let randomInstance;
|
2022-02-01 19:37:43 +01:00
|
|
|
let path;
|
2022-02-16 04:41:24 +01:00
|
|
|
if (frontend == 'searx') {
|
2022-02-20 20:47:13 +01:00
|
|
|
let instancesList;
|
|
|
|
if (protocol == 'normal') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
|
|
|
|
else if (protocol == 'tor') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
|
2022-02-06 15:24:39 +01:00
|
|
|
if (instancesList.length === 0) return null;
|
|
|
|
randomInstance = commonHelper.getRandomInstance(instancesList)
|
2022-02-16 04:41:24 +01:00
|
|
|
path = "/";
|
2022-02-01 19:37:43 +01:00
|
|
|
}
|
2022-02-16 04:41:24 +01:00
|
|
|
if (frontend == 'whoogle') {
|
2022-02-20 20:47:13 +01:00
|
|
|
let instancesList
|
|
|
|
if (protocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
|
|
|
|
if (protocol == 'tor') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects];
|
2022-02-06 15:24:39 +01:00
|
|
|
if (instancesList.length === 0) return null;
|
|
|
|
randomInstance = commonHelper.getRandomInstance(instancesList)
|
2022-02-16 04:41:24 +01:00
|
|
|
path = "/search";
|
2022-02-01 19:37:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let searchQuery = "";
|
2022-02-09 22:04:00 +01:00
|
|
|
url.search.slice(1).split("&").forEach((input) => {
|
2022-02-01 19:37:43 +01:00
|
|
|
if (input.startsWith("q=")) searchQuery = input;
|
|
|
|
});
|
2022-02-16 04:41:24 +01:00
|
|
|
|
2022-02-06 15:24:39 +01:00
|
|
|
return `${randomInstance}${path}?${searchQuery}`;
|
2022-02-01 19:37:43 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 15:46:14 +01:00
|
|
|
async function init() {
|
2022-02-12 20:28:36 +01:00
|
|
|
return new Promise((resolve) => {
|
2022-02-20 20:47:13 +01:00
|
|
|
fetch('/instances/data.json').then(response => response.text()).then(data => {
|
|
|
|
let dataJson = JSON.parse(data);
|
|
|
|
browser.storage.sync.get(
|
|
|
|
[
|
|
|
|
"disableSearch",
|
|
|
|
"searchFrontend",
|
|
|
|
"searchRedirects",
|
|
|
|
|
|
|
|
"whoogleNormalRedirectsChecks",
|
|
|
|
"whoogleNormalCustomRedirects",
|
|
|
|
|
|
|
|
"whoogleTorRedirectsChecks",
|
|
|
|
"whoogleTorCustomRedirects",
|
|
|
|
|
|
|
|
"searxNormalRedirectsChecks",
|
|
|
|
"searxNormalCustomRedirects",
|
|
|
|
|
|
|
|
"searxTorRedirectsChecks",
|
|
|
|
"searxTorCustomRedirects",
|
|
|
|
|
|
|
|
"searchProtocol",
|
|
|
|
],
|
|
|
|
(result) => {
|
|
|
|
disable = result.disableSearch ?? false;
|
|
|
|
|
|
|
|
protocol = result.searchProtocol ?? 'normal';
|
|
|
|
|
|
|
|
frontend = result.searchFrontend ?? 'searx';
|
|
|
|
|
|
|
|
redirects.searx = dataJson.searx;
|
|
|
|
redirects.whoogle = dataJson.whoogle;
|
|
|
|
if (result.searchRedirects) redirects = result.searchRedirects;
|
|
|
|
|
|
|
|
whoogleNormalRedirectsChecks = result.whoogleNormalRedirectsChecks ?? [...redirects.whoogle.normal];
|
|
|
|
whoogleNormalCustomRedirects = result.whoogleNormalCustomRedirects ?? [];
|
|
|
|
|
|
|
|
whoogleTorRedirectsChecks = result.whoogleTorRedirectsChecks ?? [...redirects.whoogle.tor];
|
|
|
|
whoogleTorCustomRedirects = result.whoogleTorCustomRedirects ?? [];
|
|
|
|
|
|
|
|
searxNormalRedirectsChecks = result.searxNormalRedirectsChecks ?? [...redirects.searx.normal];
|
|
|
|
searxNormalCustomRedirects = result.searxNormalCustomRedirects ?? [];
|
|
|
|
|
|
|
|
searxTorRedirectsChecks = result.searxTorRedirectsChecks ?? [...redirects.searx.tor];
|
|
|
|
searxTorCustomRedirects = result.searxTorCustomRedirects ?? [];
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2022-02-12 20:28:36 +01:00
|
|
|
});
|
2022-02-02 15:46:14 +01:00
|
|
|
}
|
|
|
|
|
2021-01-11 02:39:26 +01:00
|
|
|
export default {
|
2022-02-04 00:13:37 +01:00
|
|
|
isSearch,
|
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
getDisable,
|
|
|
|
setDisable,
|
|
|
|
|
2022-02-04 00:13:37 +01:00
|
|
|
getRedirects,
|
2022-02-12 10:30:30 +01:00
|
|
|
getCustomRedirects,
|
2022-02-04 00:13:37 +01:00
|
|
|
setSearxRedirects,
|
|
|
|
setWhoogleRedirects,
|
|
|
|
|
2022-02-16 04:41:24 +01:00
|
|
|
getFrontend,
|
|
|
|
setFrontend,
|
2022-02-04 00:13:37 +01:00
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
getWhoogleNormalRedirectsChecks,
|
|
|
|
setWhoogleNormalRedirectsChecks,
|
|
|
|
getWhoogleNormalCustomRedirects,
|
|
|
|
setWhoogleNormalCustomRedirects,
|
|
|
|
|
|
|
|
getWhoogleTorRedirectsChecks,
|
|
|
|
setWhoogleTorRedirectsChecks,
|
|
|
|
getWhoogleTorCustomRedirects,
|
|
|
|
setWhoogleTorCustomRedirects,
|
2022-02-06 15:24:39 +01:00
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
getSearxNormalRedirectsChecks,
|
|
|
|
setSearxNormalRedirectsChecks,
|
|
|
|
getSearxNormalCustomRedirects,
|
|
|
|
setSearxNormalCustomRedirects,
|
2022-02-06 15:24:39 +01:00
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
getSearxTorRedirectsChecks,
|
|
|
|
setSearxTorRedirectsChecks,
|
|
|
|
getSearxTorCustomRedirects,
|
|
|
|
setSearxTorCustomRedirects,
|
2022-02-06 15:24:39 +01:00
|
|
|
|
2022-02-20 20:47:13 +01:00
|
|
|
getprotocol,
|
|
|
|
setProtocol,
|
2022-02-06 15:24:39 +01:00
|
|
|
|
2022-02-01 19:37:43 +01:00
|
|
|
redirect,
|
2022-02-02 15:46:14 +01:00
|
|
|
init,
|
2021-01-11 02:39:26 +01:00
|
|
|
};
|