non-breaking optimizations to search and librex support

This commit is contained in:
BobIsMyManager 2022-07-14 11:40:19 +01:00
parent 21000150ca
commit ddcbb9725d
4 changed files with 304 additions and 39 deletions

View File

@ -5,8 +5,12 @@ import utils from './utils.js'
const targets = [ const targets = [
/^https?:\/{2}search\.libredirect\.invalid/, /^https?:\/{2}search\.libredirect\.invalid/,
]; ];
// Ill optimise all of assets/javascripts at a later date. For now, I'll just add librex and optimse options javascript
const frontends = new Array("searx", "searxng", "whoogle", "librex")
const protocols = new Array("normal", "tor", "i2p")
let redirects = { const redirects = {}
/*
"searx": { "searx": {
"normal": [], "normal": [],
"tor": [], "tor": [],
@ -22,7 +26,27 @@ let redirects = {
"tor": [], "tor": [],
"i2p": [] "i2p": []
} }
}; */
//};
//let tmp = "{"
for (let i = 0; i < frontends.length; i++) {
//redirects.frontends[i] = {}
//redirects.push(frontends[i])
//tmp = frontends[i]
//tmp = tmp + '\n"' + frontends[i] + '": {'
redirects[frontends[i]] = {}
for (let x = 0; x < protocols.length; x++) {
//redirects.frontends[i].protocols = []
//tmp = tmp + '\n"' + protocols[x] + '": [],'
redirects[frontends[i]][protocols[x]] = []
}
//tmp = tmp + "\n},"
}
//tmp = tmp + "\n}"
//const redirects = JSON.parse(tmp)
function setRedirects(val) { function setRedirects(val) {
browser.storage.local.get('cloudflareBlackList', r => { browser.storage.local.get('cloudflareBlackList', r => {
@ -30,6 +54,7 @@ function setRedirects(val) {
searxNormalRedirectsChecks = [...redirects.searx.normal]; searxNormalRedirectsChecks = [...redirects.searx.normal];
searxngNormalRedirectsChecks = [...redirects.searxng.normal]; searxngNormalRedirectsChecks = [...redirects.searxng.normal];
whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; whoogleNormalRedirectsChecks = [...redirects.whoogle.normal];
librexNormalRedirectsChecks = [...redirects.librex.normal];
for (const instance of r.cloudflareBlackList) { for (const instance of r.cloudflareBlackList) {
const a = searxNormalRedirectsChecks.indexOf(instance); const a = searxNormalRedirectsChecks.indexOf(instance);
if (a > -1) searxNormalRedirectsChecks.splice(a, 1); if (a > -1) searxNormalRedirectsChecks.splice(a, 1);
@ -39,12 +64,16 @@ function setRedirects(val) {
const c = whoogleNormalRedirectsChecks.indexOf(instance); const c = whoogleNormalRedirectsChecks.indexOf(instance);
if (c > -1) whoogleNormalRedirectsChecks.splice(c, 1); if (c > -1) whoogleNormalRedirectsChecks.splice(c, 1);
const d = librexNormalRedirectsChecks.indexOf(instance);
if (c > -1) librexNormalRedirectsChecks.splice(d, 1);
} }
browser.storage.local.set({ browser.storage.local.set({
searchRedirects: redirects, searchRedirects: redirects,
searxNormalRedirectsChecks, searxNormalRedirectsChecks,
searxngNormalRedirectsChecks, searxngNormalRedirectsChecks,
whoogleNormalRedirectsChecks, whoogleNormalRedirectsChecks,
librexNormalRedirectsChecks,
}); });
}) })
} }
@ -71,7 +100,13 @@ let
searxngTorRedirectsChecks, searxngTorRedirectsChecks,
searxngTorCustomRedirects, searxngTorCustomRedirects,
searxngI2pRedirectsChecks, searxngI2pRedirectsChecks,
searxngI2pCustomRedirects; searxngI2pCustomRedirects,
librexNormalRedirectsChecks,
librexNormalCustomRedirects,
librexTorRedirectsChecks,
librexTorCustomRedirects,
librexI2pRedirectsChecks,
librexI2pCustomRedirects;
function init() { function init() {
return new Promise(async resolve => { return new Promise(async resolve => {
@ -99,6 +134,12 @@ function init() {
"searxngTorCustomRedirects", "searxngTorCustomRedirects",
"searxngI2pRedirectsChecks", "searxngI2pRedirectsChecks",
"searxngI2pCustomRedirects", "searxngI2pCustomRedirects",
"librexNormalRedirectsChecks",
"librexNormalCustomRedirects",
"librexTorRedirectsChecks",
"librexTorCustomRedirects",
"librexI2pRedirectsChecks",
"librexI2pCustomRedirects"
], ],
r => { r => {
disableSearch = r.disableSearch; disableSearch = r.disableSearch;
@ -123,6 +164,12 @@ function init() {
searxngTorCustomRedirects = r.searxngTorCustomRedirects; searxngTorCustomRedirects = r.searxngTorCustomRedirects;
searxngI2pRedirectsChecks = r.searxngI2pRedirectsChecks; searxngI2pRedirectsChecks = r.searxngI2pRedirectsChecks;
searxngI2pCustomRedirects = r.searxngI2pCustomRedirects; searxngI2pCustomRedirects = r.searxngI2pCustomRedirects;
librexNormalRedirectsChecks = r.librexNormalRedirectsChecks;
librexNormalCustomRedirects = r.librexNormalCustomRedirects;
librexTorRedirectsChecks = r.librexTorRedirectsChecks;
librexTorCustomRedirects = r.librexTorCustomRedirects;
librexI2pRedirectsChecks = r.librexI2pRedirectsChecks;
librexI2pCustomRedirects = r.librexI2pCustomRedirects;
resolve(); resolve();
} }
) )
@ -307,6 +354,14 @@ function redirect(url, disableOverride) {
randomInstance = utils.getRandomInstance(instancesList) randomInstance = utils.getRandomInstance(instancesList)
path = "/search"; path = "/search";
} }
else if (searchFrontend == 'librex') {
let instancesList;
if (searchProtocol == 'normal') instancesList = [...librexNormalRedirectsChecks, ...librexNormalCustomRedirects];
if (searchProtocol == 'tor') instancesList = [...librexTorRedirectsChecks, ...librexTorCustomRedirects];
if (searchProtocol == 'i2p') instancesList = [...librexI2pRedirectsChecks, ...librexI2pCustomRedirects];
randomInstance = utils.getRandomInstance(instancesList)
path = "/search.php";
}
if ( if (
((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) || ((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) ||
@ -345,6 +400,10 @@ function switchInstance(url, disableOverride) {
...searchRedirects.whoogle.tor, ...searchRedirects.whoogle.tor,
...searchRedirects.whoogle.i2p, ...searchRedirects.whoogle.i2p,
...searchRedirects.librex.normal,
...searchRedirects.librex.tor,
...searchRedirects.librex.i2p,
...searxNormalCustomRedirects, ...searxNormalCustomRedirects,
...searxTorCustomRedirects, ...searxTorCustomRedirects,
...searxI2pCustomRedirects, ...searxI2pCustomRedirects,
@ -356,6 +415,10 @@ function switchInstance(url, disableOverride) {
...whoogleNormalCustomRedirects, ...whoogleNormalCustomRedirects,
...whoogleTorCustomRedirects, ...whoogleTorCustomRedirects,
...whoogleI2pCustomRedirects, ...whoogleI2pCustomRedirects,
...librexNormalCustomRedirects,
...librexTorCustomRedirects,
...librexI2pCustomRedirects,
].includes(protocolHost)) { resolve(); return; } ].includes(protocolHost)) { resolve(); return; }
let instancesList; let instancesList;
@ -363,16 +426,19 @@ function switchInstance(url, disableOverride) {
if (searchFrontend == 'searx') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; if (searchFrontend == 'searx') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
else if (searchFrontend == 'searxng') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; else if (searchFrontend == 'searxng') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
else if (searchFrontend == 'whoogle') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects]; else if (searchFrontend == 'whoogle') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
else if (searchFrontend == 'librex') instancesList = [...librexNormalRedirectsChecks, ...librexNormalCustomRedirects];
} }
else if (searchProtocol == 'tor') { else if (searchProtocol == 'tor') {
if (searchFrontend == 'searx') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; if (searchFrontend == 'searx') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
else if (searchFrontend == 'searxng') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; else if (searchFrontend == 'searxng') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
else if (searchFrontend == 'whoogle') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]; else if (searchFrontend == 'whoogle') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects];
else if (searchFrontend == 'librex') instancesList = [...librexTorRedirectsChecks, ...librexTorCustomRedirects];
} }
else if (searchProtocol == 'i2p') { else if (searchProtocol == 'i2p') {
if (searchFrontend == 'searx') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; if (searchFrontend == 'searx') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects];
else if (searchFrontend == 'searxng') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; else if (searchFrontend == 'searxng') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects];
else if (searchFrontend == 'whoogle') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects]; else if (searchFrontend == 'whoogle') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects];
else if (searchFrontend == 'librex') instancesList = [...librexI2pRedirectsChecks, ...librexI2pCustomRedirects];
} }
const i = instancesList.indexOf(protocolHost); const i = instancesList.indexOf(protocolHost);
@ -388,14 +454,20 @@ function initDefaults() {
return new Promise(async resolve => { return new Promise(async resolve => {
fetch('/instances/data.json').then(response => response.text()).then(async data => { fetch('/instances/data.json').then(response => response.text()).then(async data => {
let dataJson = JSON.parse(data); let dataJson = JSON.parse(data);
/*
redirects.searx = dataJson.searx; redirects.searx = dataJson.searx;
redirects.searxng = dataJson.searxng; redirects.searxng = dataJson.searxng;
redirects.whoogle = dataJson.whoogle; redirects.whoogle = dataJson.whoogle;
*/
for (let i = 0; i < frontends.length; i++) {
redirects[frontends[i]] = dataJson[frontends[i]]
}
browser.storage.local.get('cloudflareBlackList', async r => { browser.storage.local.get('cloudflareBlackList', async r => {
whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; whoogleNormalRedirectsChecks = [...redirects.whoogle.normal];
searxNormalRedirectsChecks = [...redirects.searx.normal]; searxNormalRedirectsChecks = [...redirects.searx.normal];
searxngNormalRedirectsChecks = [...redirects.searxng.normal]; searxngNormalRedirectsChecks = [...redirects.searxng.normal];
librexNormalRedirectsChecks = [...redirects.librex.normal];
for (const instance of r.cloudflareBlackList) { for (const instance of r.cloudflareBlackList) {
let i; let i;
@ -407,6 +479,9 @@ function initDefaults() {
i = searxngNormalRedirectsChecks.indexOf(instance); i = searxngNormalRedirectsChecks.indexOf(instance);
if (i > -1) searxngNormalRedirectsChecks.splice(i, 1); if (i > -1) searxngNormalRedirectsChecks.splice(i, 1);
i = librexNormalRedirectsChecks.indexOf(instance);
if (i > -1) librexNormalRedirectsChecks.splice(i, 1)
} }
browser.storage.local.set({ browser.storage.local.set({
disableSearch: false, disableSearch: false,
@ -424,6 +499,7 @@ function initDefaults() {
whoogleI2pRedirectsChecks: [...redirects.whoogle.i2p], whoogleI2pRedirectsChecks: [...redirects.whoogle.i2p],
whoogleI2pCustomRedirects: [], whoogleI2pCustomRedirects: [],
searxNormalRedirectsChecks: searxNormalRedirectsChecks, searxNormalRedirectsChecks: searxNormalRedirectsChecks,
searxNormalCustomRedirects: [], searxNormalCustomRedirects: [],
@ -433,6 +509,7 @@ function initDefaults() {
searxI2pRedirectsChecks: [...redirects.searx.i2p], searxI2pRedirectsChecks: [...redirects.searx.i2p],
searxI2pCustomRedirects: [], searxI2pCustomRedirects: [],
searxngNormalRedirectsChecks: searxngNormalRedirectsChecks, searxngNormalRedirectsChecks: searxngNormalRedirectsChecks,
searxngNormalCustomRedirects: [], searxngNormalCustomRedirects: [],
@ -441,6 +518,16 @@ function initDefaults() {
searxngI2pRedirectsChecks: [...redirects.searxng.i2p], searxngI2pRedirectsChecks: [...redirects.searxng.i2p],
searxngI2pCustomRedirects: [], searxngI2pCustomRedirects: [],
librexNormalRedirectsChecks: librexNormalRedirectsChecks,
librexNormalCustomRedirects: [],
librexTorRedirectsChecks: librexTorRedirectsChecks,
librexTorCustomRedirects: [],
librexI2pRedirectsChecks: librexI2pRedirectsChecks,
librexI2pCustomRedirects: []
}, () => resolve()) }, () => resolve())
}) })
}) })

View File

@ -1502,20 +1502,19 @@
<option value="searxng">SearXNG</option> <option value="searxng">SearXNG</option>
<option value="searx">SearX</option> <option value="searx">SearX</option>
<option value="whoogle">Whoogle</option> <option value="whoogle">Whoogle</option>
<option value="librex">LibreX</option>
</select> </select>
</div> </div>
<div id="searx-whoogle"> <div class="some-block option-block">
<div class="some-block option-block"> <h4 data-localise="__MSG_protocol__">Protocol</h4>
<h4 data-localise="__MSG_protocol__">Protocol</h4> <select id="search-protocol">
<select id="search-protocol"> <option value="normal" data-localise="__MSG_normal__">Normal</option>
<option value="normal" data-localise="__MSG_normal__">Normal</option> <option value="tor" data-localise="__MSG_tor__">Tor</option>
<option value="tor" data-localise="__MSG_tor__">Tor</option> <option value="i2p" data-localise="__MSG_i2p__">I2P</option>
<option value="i2p" data-localise="__MSG_i2p__">I2P</option> </select>
</select>
</div>
</div> </div>
<div class="some-block"> <div class="some-block">
<h4 data-localise="__MSG_searchNote__">Note: To use Search to its full potential, make LibRedirect as the Default Search Engine</h4> <h4 data-localise="__MSG_searchNote__">Note: To use Search, make LibRedirect the Default Search Engine</h4>
</div> </div>
<div id="searx"> <div id="searx">
<hr> <hr>
@ -1560,7 +1559,7 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://searx.onion" type="url"> <input class="custom-instance" placeholder="http://searx.onion" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
@ -1581,7 +1580,7 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://searx.i2p" type="url"> <input class="custom-instance" placeholder="http://searx.i2p" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
@ -1635,7 +1634,7 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://searxng.onion" type="url"> <input class="custom-instance" placeholder="http://searxng.onion" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
@ -1656,7 +1655,7 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://searxng.i2p" type="url"> <input class="custom-instance" placeholder="http://searxng.i2p" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
@ -1710,7 +1709,7 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://whoogle.onion" type="url"> <input class="custom-instance" placeholder="http://whoogle.onion" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
@ -1731,7 +1730,82 @@
</div> </div>
<form class="custom-instance-form"> <form class="custom-instance-form">
<div class="some-block option-block"> <div class="some-block option-block">
<input class="custom-instance" placeholder="https://whoogle.i2p" type="url"> <input class="custom-instance" placeholder="http://whoogle.i2p" type="url">
<button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
</svg>
</button>
</div>
</form>
<div class="checklist custom-checklist"></div>
</div>
</div>
<div id="librex">
<hr>
<div class="normal">
<div class="some-block option-block">
<h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
</div>
<div class="checklist"></div>
<hr>
<div class="some-block option-block">
<h4 data-localise="__MSG_customInstances__">Custom Instances</h4>
</div>
<form class="custom-instance-form">
<div class="some-block option-block">
<input class="custom-instance" placeholder="https://librex.com" type="url">
<button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
</svg>
</button>
</div>
</form>
<div class="checklist custom-checklist"></div>
<div class="buttons buttons-inline">
<label class="button button-inline" id="latency-librex-label" for="latency-librex">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"></path>
</svg>&nbsp;
<x data-localise="__MSG_testInstancesLatency__">Test Instances Latency</x>
</label>
<input class="button button-inline" id="latency-librex" style="display:none;">
</div>
</div>
<div class="tor">
<div class="some-block option-block">
<h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
</div>
<div class="checklist"></div>
<hr>
<div class="some-block option-block">
<h4 data-localise="__MSG_customInstances__">Custom Instances</h4>
</div>
<form class="custom-instance-form">
<div class="some-block option-block">
<input class="custom-instance" placeholder="http://librex.onion" type="url">
<button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
</svg>
</button>
</div>
</form>
<div class="checklist custom-checklist"></div>
</div>
<div class="i2p">
<div class="some-block option-block">
<h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
</div>
<div class="checklist"></div>
<hr>
<div class="some-block option-block">
<h4 data-localise="__MSG_customInstances__">Custom Instances</h4>
</div>
<form class="custom-instance-form">
<div class="some-block option-block">
<input class="custom-instance" placeholder="http://librex.i2p" type="url">
<button class="add add-instance" type="submit"> <button class="add add-instance" type="submit">
<svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor"> <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>

View File

@ -1,8 +1,39 @@
import utils from "../../../assets/javascripts/utils.js"; import utils from "../../../assets/javascripts/utils.js";
// GOAL: to never mention frontends/protocls outside these two arrays, so that adding a new frontend/protocol is as easy as adding it here.
// This may be expanded across the whole project, where almost everything becomes a template, and the frontend/protocol parts just become a JSON file.
// ONCE FINISHED: add librex and see if it works
const frontends = new Array("searx", "searxng", "whoogle", "librex") // Add librex once /javascripts/search.js is made agnostic
const protocols = new Array("normal", "tor", "i2p")
//let frontendProtocols = (frontends.length)
// I will leave comments of my privious attemps so that people can learn from my mistakes. :)
/*
for (let i = 0; i < frontends.length; i++) {
this.frontends[i] = frontends[i].getElementsByClassName(protocol)
}
*/
// There was a class here, but I deleted a bit of it
/*
this.searxDiv = searxDiv.getElementsByClassName(protocol)[0];
this.searxngDiv = searxngDiv.getElementsByClassName(protocol)[0];
this.librexDiv = librexDiv.getElementsByClassName(protocol)[0];
*/
/*
* Here I was trying to solve the issue by making a 2D array, but I later realised I was overcomplicating things
for (var i = 0; i < frontends.length; i++) {
frontendProtocols[i] = new Array(protocols.length)
}
*/
/*
const searxDiv = document.getElementById("searx"); const searxDiv = document.getElementById("searx");
const searxngDiv = document.getElementById("searxng"); const searxngDiv = document.getElementById("searxng");
const whoogleDiv = document.getElementById("whoogle"); const whoogleDiv = document.getElementById("whoogle");
*/
const enable = document.getElementById("search-enable"); const enable = document.getElementById("search-enable");
const frontend = document.getElementById("search-frontend"); const frontend = document.getElementById("search-frontend");
@ -12,28 +43,69 @@ const search = document.getElementById('search_page');
function changeFrontendsSettings() { function changeFrontendsSettings() {
let SearxWhoogleElement = document.getElementById("searx-whoogle"); for (let i = 0; i < frontends.length; i++) {
const frontendDiv = document.getElementById(frontends[i])
if (frontends[i] == frontend.value) {
frontendDiv.style.display = 'block'
} else {
frontendDiv.style.display = 'none'
}
}
/*
if (frontend.value == 'searx') { if (frontend.value == 'searx') {
searxDiv.style.display = 'block'; searxDiv.style.display = 'block';
searxngDiv.style.display = 'none'; searxngDiv.style.display = 'none';
whoogleDiv.style.display = 'none'; whoogleDiv.style.display = 'none';
SearxWhoogleElement.style.display = 'block'; librexDiv.style.display = 'none';
} }
else if (frontend.value == 'searxng') { else if (frontend.value == 'searxng') {
searxDiv.style.display = 'none'; searxDiv.style.display = 'none';
searxngDiv.style.display = 'block'; searxngDiv.style.display = 'block';
whoogleDiv.style.display = 'none'; whoogleDiv.style.display = 'none';
SearxWhoogleElement.style.display = 'block'; librexDiv.style.display = 'none';
} }
else if (frontend.value == 'whoogle') { else if (frontend.value == 'whoogle') {
searxDiv.style.display = 'none'; searxDiv.style.display = 'none';
searxngDiv.style.display = 'none'; searxngDiv.style.display = 'none';
whoogleDiv.style.display = 'block'; whoogleDiv.style.display = 'block';
SearxWhoogleElement.style.display = 'block'; librexDiv.style.display = 'none';
} }
else if (frontend.value == 'librex') {
searxDiv.style.display = 'none';
searxDiv.style.display = 'none';
searxngDiv.style.display = 'none';
librexDiv.style.display = 'block';
}
*/
} }
function changeProtocolSettings() { function changeProtocolSettings() {
for (let i = 0; i < frontends.length; i++) {
const frontendDiv = document.getElementById(frontends[i])
if (frontends[i] == frontend.value) { // Here we are checking if the frontend matches the current one. This skips the protocol checking for that frontend, speeding things up.
for (let x = 0; x < protocols.length; x++) {
const protocolDiv = frontendDiv.getElementsByClassName(protocols[x])[0]
if (protocols[x] == protocol.value) { //if the frontend value equals the selected one, it will show. Otherwise, it will be hidden
protocolDiv.style.display = 'block'
} else {
protocolDiv.style.display = 'none'
}
}
} else {
continue
}
}
/*
* "Legacy" code
const normalsearxDiv = searxDiv.getElementsByClassName("normal")[0]; const normalsearxDiv = searxDiv.getElementsByClassName("normal")[0];
const torsearxDiv = searxDiv.getElementsByClassName("tor")[0]; const torsearxDiv = searxDiv.getElementsByClassName("tor")[0];
const i2psearxDiv = searxDiv.getElementsByClassName("i2p")[0]; const i2psearxDiv = searxDiv.getElementsByClassName("i2p")[0];
@ -42,9 +114,17 @@ function changeProtocolSettings() {
const torsearxngDiv = searxngDiv.getElementsByClassName("tor")[0]; const torsearxngDiv = searxngDiv.getElementsByClassName("tor")[0];
const i2psearxngDiv = searxngDiv.getElementsByClassName("i2p")[0]; const i2psearxngDiv = searxngDiv.getElementsByClassName("i2p")[0];
const normalwhoogleDiv = whoogleDiv.getElementsByClassName("normal")[0];
const torwhoogleDiv = whoogleDiv.getElementsByClassName("tor")[0]; const torwhoogleDiv = whoogleDiv.getElementsByClassName("tor")[0];
const i2pwhoogleDiv = whoogleDiv.getElementsByClassName("i2p")[0]; const i2pwhoogleDiv = whoogleDiv.getElementsByClassName("i2p")[0];
const normalwhoogleDiv = whoogleDiv.getElementsByClassName("normal")[0];
function protocolDisplay(proto) {
proto.searxngDiv = 'block'
}
protocolDisplay(protocol.value)
if (protocol.value == 'normal') { if (protocol.value == 'normal') {
normalsearxDiv.style.display = 'block'; normalsearxDiv.style.display = 'block';
@ -85,6 +165,7 @@ function changeProtocolSettings() {
i2psearxngDiv.style.display = 'block'; i2psearxngDiv.style.display = 'block';
i2pwhoogleDiv.style.display = 'block'; i2pwhoogleDiv.style.display = 'block';
} }
*/
} }
browser.storage.local.get( browser.storage.local.get(
@ -103,6 +184,13 @@ browser.storage.local.get(
} }
); );
for (let i = 0; i < frontends.length; i++) {
for (let x = 0; x < protocols.length; x++){
utils.processDefaultCustomInstances('search', frontends[i], protocols[x], document)
}
utils.latency('search', frontends[i], document, location, true)
}
search.addEventListener("change", () => { search.addEventListener("change", () => {
browser.storage.local.set({ browser.storage.local.set({
disableSearch: !enable.checked, disableSearch: !enable.checked,
@ -113,6 +201,8 @@ search.addEventListener("change", () => {
changeProtocolSettings(protocol.value); changeProtocolSettings(protocol.value);
}) })
/*
* more "legacy" code
utils.processDefaultCustomInstances('search', 'searx', 'normal', document); utils.processDefaultCustomInstances('search', 'searx', 'normal', document);
utils.processDefaultCustomInstances('search', 'searx', 'tor', document); utils.processDefaultCustomInstances('search', 'searx', 'tor', document);
utils.processDefaultCustomInstances('search', 'searx', 'i2p', document); utils.processDefaultCustomInstances('search', 'searx', 'i2p', document);
@ -126,3 +216,4 @@ utils.processDefaultCustomInstances('search', 'whoogle', 'i2p', document);
utils.latency('search', 'searx', document, location, true) utils.latency('search', 'searx', document, location, true)
utils.latency('search', 'searxng', document, location, true) utils.latency('search', 'searxng', document, location, true)
utils.latency('search', 'whoogle', document, location, true) utils.latency('search', 'whoogle', document, location, true)
*/

View File

@ -13,17 +13,17 @@ section#search_page.option-block
option(value="searxng") SearXNG option(value="searxng") SearXNG
option(value="searx") SearX option(value="searx") SearX
option(value="whoogle") Whoogle option(value="whoogle") Whoogle
option(value="librex") LibreX
#searx-whoogle .some-block.option-block
.some-block.option-block h4(data-localise="__MSG_protocol__") Protocol
h4(data-localise="__MSG_protocol__") Protocol select#search-protocol
select#search-protocol option(value="normal" data-localise="__MSG_normal__") Normal
option(value="normal" data-localise="__MSG_normal__") Normal option(value="tor" data-localise="__MSG_tor__") Tor
option(value="tor" data-localise="__MSG_tor__") Tor option(value="i2p" data-localise="__MSG_i2p__") I2P
option(value="i2p" data-localise="__MSG_i2p__") I2P
.some-block .some-block
h4(data-localise="__MSG_searchNote__") Note: To use Search to its full potential, make LibRedirect as the Default Search Engine h4(data-localise="__MSG_searchNote__") Note: To use Search, make LibRedirect the Default Search Engine
#searx #searx
hr hr
@ -34,10 +34,10 @@ section#search_page.option-block
+latency('searx') +latency('searx')
.tor .tor
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://searx.onion') +instances('http://searx.onion')
.i2p .i2p
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://searx.i2p') +instances('http://searx.i2p')
#searxng #searxng
hr hr
@ -47,10 +47,10 @@ section#search_page.option-block
+latency('searxng') +latency('searxng')
.tor .tor
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://searxng.onion') +instances('http://searxng.onion')
.i2p .i2p
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://searxng.i2p') +instances('http://searxng.i2p')
#whoogle #whoogle
hr hr
@ -60,9 +60,22 @@ section#search_page.option-block
+latency('whoogle') +latency('whoogle')
.tor .tor
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://whoogle.onion') +instances('http://whoogle.onion')
.i2p .i2p
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://whoogle.i2p') +instances('http://whoogle.i2p')
#librex
hr
.normal
include ../../widgets/instances.pug
+instances('https://librex.com')
+latency('librex')
.tor
include ../../widgets/instances.pug
+instances('http://librex.onion')
.i2p
include ../../widgets/instances.pug
+instances('http://librex.i2p')
script(type="module" src="./widgets/search.js") script(type="module" src="./widgets/search.js")