aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2022-04-03 22:20:26 +0300
committerManeraKai <manerakai@protonmail.com>2022-04-03 22:20:26 +0300
commitd731d94a2d7761e6fea7f061d6dd13cfa4f380d5 (patch)
tree25f8bb3d5988717746f857fd728f7240e3f45cab /src
parentSeperated searX and SearXNG in the list #120 (diff)
downloadlibredirect-d731d94a2d7761e6fea7f061d6dd13cfa4f380d5.zip
Seperated SearX and SearXNG in code #120
Diffstat (limited to 'src')
-rw-r--r--src/assets/javascripts/helpers/common.js1
-rw-r--r--src/assets/javascripts/helpers/search.js135
-rw-r--r--src/pages/options/search/search.html55
-rw-r--r--src/pages/options/search/search.js56
4 files changed, 236 insertions, 11 deletions
diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js
index 2536afa4..678b9dd5 100644
--- a/src/assets/javascripts/helpers/common.js
+++ b/src/assets/javascripts/helpers/common.js
@@ -48,6 +48,7 @@ async function updateInstances() {
translateHelper.setLingvaRedirects(instances.lingva)
searchHelper.setSearxRedirects(instances.searx);
+ searchHelper.setSearxngRedirects(instances.searxng);
searchHelper.setWhoogleRedirects(instances.whoogle);
wikipediaHelper.setRedirects(instances.wikiless);
diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js
index ea14ca35..26939ade 100644
--- a/src/assets/javascripts/helpers/search.js
+++ b/src/assets/javascripts/helpers/search.js
@@ -13,6 +13,11 @@ let redirects = {
"tor": [],
"i2p": []
},
+ "searxng": {
+ "normal": [],
+ "tor": [],
+ "i2p": []
+ },
"whoogle": {
"normal": [],
"tor": []
@@ -29,6 +34,10 @@ const getCustomRedirects = () => {
"normal": [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects],
"tor": [...searxTorRedirectsChecks, ...searxTorCustomRedirects],
},
+ "searxng": {
+ "normal": [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects],
+ "tor": [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects],
+ },
"whoogle": {
"normal": [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects],
"normal": [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]
@@ -53,6 +62,23 @@ function setSearxRedirects(val) {
setSearxTorRedirectsChecks(searxTorRedirectsChecks);
}
+function setSearxngRedirects(val) {
+ redirects.searxng = val;
+ browser.storage.local.set({ searchRedirects: redirects })
+ console.log("searxngRedirects:", val)
+ for (const item of searxngNormalRedirectsChecks) if (!redirects.searxng.normal.includes(item)) {
+ var index = searxngNormalRedirectsChecks.indexOf(item);
+ if (index !== -1) searxngNormalRedirectsChecks.splice(index, 1);
+ }
+ setSearxngNormalRedirectsChecks(searxngNormalRedirectsChecks);
+
+ for (const item of searxngTorRedirectsChecks) if (!redirects.searxng.tor.includes(item)) {
+ var index = searxngTorRedirectsChecks.indexOf(item);
+ if (index !== -1) searxngTorRedirectsChecks.splice(index, 1);
+ }
+ setSearxngTorRedirectsChecks(searxngTorRedirectsChecks);
+}
+
function setWhoogleRedirects(val) {
redirects.whoogle = val;
browser.storage.local.set({ searchRedirects: redirects })
@@ -134,6 +160,38 @@ function setSearxTorCustomRedirects(val) {
console.log("searxTorCustomRedirects: ", val)
}
+let searxngNormalRedirectsChecks;
+const getSearxngNormalRedirectsChecks = () => searxngNormalRedirectsChecks;
+function setSearxngNormalRedirectsChecks(val) {
+ searxngNormalRedirectsChecks = val;
+ browser.storage.local.set({ searxngNormalRedirectsChecks })
+ console.log("searxngNormalRedirectsChecks: ", val)
+}
+
+let searxngTorRedirectsChecks;
+const getSearxngTorRedirectsChecks = () => searxngTorRedirectsChecks;
+function setSearxngTorRedirectsChecks(val) {
+ searxngTorRedirectsChecks = val;
+ browser.storage.local.set({ searxngTorRedirectsChecks })
+ console.log("searxngTorRedirectsChecks: ", val)
+}
+
+let searxngNormalCustomRedirects = [];
+const getSearxngNormalCustomRedirects = () => searxngNormalCustomRedirects;
+function setSearxngNormalCustomRedirects(val) {
+ searxngNormalCustomRedirects = val;
+ browser.storage.local.set({ searxngNormalCustomRedirects })
+ console.log("searxngNormalCustomRedirects: ", val)
+}
+
+let searxngTorCustomRedirects = [];
+const getSearxngTorCustomRedirects = () => searxngTorCustomRedirects;
+function setSearxngTorCustomRedirects(val) {
+ searxngTorCustomRedirects = val;
+ browser.storage.local.set({ searxngTorCustomRedirects })
+ console.log("searxngTorCustomRedirects: ", val)
+}
+
let disable;
const getDisable = () => disable;
function setDisable(val) {
@@ -193,6 +251,39 @@ function initSearxCookies() {
}
}
+function initSearxngCookies() {
+ let themeValue;
+ if (theme == 'light') themeValue = 'logicodev';
+ if (theme == 'dark') themeValue = 'logicodev-dark';
+ if (applyThemeToSites && themeValue) {
+ let allInstances = [...redirects.searxng.normal, ...redirects.searxng.tor, ...searxngNormalCustomRedirects, ...searxngTorCustomRedirects]
+ let checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects, ...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]
+ for (const instanceUrl of allInstances)
+ if (!checkedInstances.includes(instanceUrl)) {
+ browser.cookies.remove({
+ url: instanceUrl,
+ name: "oscar-style",
+ })
+ browser.cookies.remove({
+ url: instanceUrl,
+ name: "oscar",
+ })
+ }
+ for (const instanceUrl of checkedInstances) {
+ browser.cookies.set({
+ url: instanceUrl,
+ name: "oscar-style",
+ value: themeValue
+ })
+ browser.cookies.set({
+ url: instanceUrl,
+ name: "theme",
+ value: 'oscar'
+ })
+ }
+ }
+}
+
function initWhoogleCookies() {
let checkedInstances = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects, ...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]
@@ -249,6 +340,14 @@ function redirect(url) {
randomInstance = commonHelper.getRandomInstance(instancesList)
path = "/";
}
+ else if (frontend == 'searxng') {
+ let instancesList;
+ if (protocol == 'normal') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
+ else if (protocol == 'tor') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
+ if (instancesList.length === 0) return null;
+ randomInstance = commonHelper.getRandomInstance(instancesList)
+ path = "/";
+ }
else if (frontend == 'whoogle') {
let instancesList
if (protocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
@@ -279,6 +378,12 @@ function switchInstance(url) {
...searxNormalCustomRedirects,
...searxTorCustomRedirects,
+ ...redirects.searx.normal,
+ ...redirects.searxng.tor,
+
+ ...searxngNormalCustomRedirects,
+ ...searxngTorCustomRedirects,
+
...redirects.whoogle.normal,
...redirects.whoogle.tor,
@@ -293,6 +398,10 @@ function switchInstance(url) {
if (protocol == 'normal') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
else if (protocol == 'tor') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
}
+ else if (frontend == 'searxng') {
+ if (protocol == 'normal') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
+ else if (protocol == 'tor') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
+ }
else if (frontend == 'whoogle') {
if (protocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
else if (protocol == 'tor') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects];
@@ -330,6 +439,12 @@ async function init() {
"searxTorRedirectsChecks",
"searxTorCustomRedirects",
+ "searxngNormalRedirectsChecks",
+ "searxngNormalCustomRedirects",
+
+ "searxngTorRedirectsChecks",
+ "searxngTorCustomRedirects",
+
"theme",
"applyThemeToSites",
@@ -346,6 +461,7 @@ async function init() {
applyThemeToSites = r.applyThemeToSites ?? false;
redirects.searx = dataJson.searx;
+ redirects.searxng = dataJson.searxng;
redirects.whoogle = dataJson.whoogle;
if (r.searchRedirects) redirects = r.searchRedirects;
@@ -361,7 +477,14 @@ async function init() {
searxTorRedirectsChecks = r.searxTorRedirectsChecks ?? [...redirects.searx.tor];
searxTorCustomRedirects = r.searxTorCustomRedirects ?? [];
+ searxngNormalRedirectsChecks = r.searxngNormalRedirectsChecks ?? [...redirects.searxng.normal];
+ searxngNormalCustomRedirects = r.searxngNormalCustomRedirects ?? [];
+
+ searxngTorRedirectsChecks = r.searxngTorRedirectsChecks ?? [...redirects.searxng.tor];
+ searxngTorCustomRedirects = r.searxngTorCustomRedirects ?? [];
+
initSearxCookies()
+ initSearxngCookies()
// initWhoogleCookies()
resolve();
@@ -378,7 +501,9 @@ export default {
getRedirects,
getCustomRedirects,
+
setSearxRedirects,
+ setSearxngRedirects,
setWhoogleRedirects,
getFrontend,
@@ -404,6 +529,16 @@ export default {
getSearxTorCustomRedirects,
setSearxTorCustomRedirects,
+ getSearxngNormalRedirectsChecks,
+ setSearxngNormalRedirectsChecks,
+ getSearxngNormalCustomRedirects,
+ setSearxngNormalCustomRedirects,
+
+ getSearxngTorRedirectsChecks,
+ setSearxngTorRedirectsChecks,
+ getSearxngTorCustomRedirects,
+ setSearxngTorCustomRedirects,
+
getProtocol,
setProtocol,
diff --git a/src/pages/options/search/search.html b/src/pages/options/search/search.html
index 3ad8353c..a90ad8ed 100644
--- a/src/pages/options/search/search.html
+++ b/src/pages/options/search/search.html
@@ -138,6 +138,7 @@
<h4 id="frontend" data-localise="__MSG_frontend__">Frontend</h4>
<select id="search-frontend">
<option value="searx">SearX</option>
+ <option value="searxng">SearXNG</option>
<option value="whoogle">Whoogle</option>
<option value="startpage">Startpage</option>
</select>
@@ -211,6 +212,58 @@
</div>
</div>
+ <div id="searxng">
+ <hr>
+ <div id="searxng-normal">
+ <div class="some-block option-block">
+ <h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
+ </div>
+ <div class="checklist" id="searxng-normal-checklist">
+ </div>
+ <hr>
+ <div class="some-block option-block">
+ <h4 data-localise="__MSG_customInstances__">Custom Instances</h4>
+ </div>
+ <form id="custom-searxng-normal-instance-form">
+ <div class="some-block option-block">
+ <input id="searxng-normal-custom-instance" placeholder="https://searxng.com" type="url" />
+ <button type="submit" class="add" id="searxng-normal-add-instance">
+ <svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
+ fill="currentColor">
+ <path d="M0 0h24v24H0V0z" fill="none" />
+ <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
+ </svg>
+ </button>
+ </div>
+ </form>
+ <div class="checklist" id="searxng-normal-custom-checklist"></div>
+ </div>
+ <div id="searxng-tor">
+ <div class="some-block option-block">
+ <h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
+ </div>
+ <div class="checklist" id="searxng-tor-checklist">
+ </div>
+ <hr>
+ <div class="some-block option-block">
+ <h4 data-localise="__MSG_customInstances__">Custom Instances</h4>
+ </div>
+ <form id="custom-searxng-tor-instance-form">
+ <div class="some-block option-block">
+ <input id="searxng-tor-custom-instance" placeholder="https://searxng.com" type="url" />
+ <button type="submit" class="add" id="searxng-tor-add-instance">
+ <svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
+ fill="currentColor">
+ <path d="M0 0h24v24H0V0z" fill="none" />
+ <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
+ </svg>
+ </button>
+ </div>
+ </form>
+ <div class="checklist" id="searxng-tor-custom-checklist"></div>
+ </div>
+ </div>
+
<div id="whoogle">
<hr>
<div id="whoogle-normal">
@@ -264,8 +317,6 @@
</div>
</div>
-
-
</section>
diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js
index 68ae017f..cc4a44ea 100644
--- a/src/pages/options/search/search.js
+++ b/src/pages/options/search/search.js
@@ -2,13 +2,12 @@ import searchHelper from "../../../assets/javascripts/helpers/search.js";
import commonHelper from "../../../assets/javascripts/helpers/common.js";
let disableSearchElement = document.getElementById("disable-search");
-disableSearchElement.addEventListener("change",
- (event) => searchHelper.setDisable(!event.target.checked)
-);
+disableSearchElement.addEventListener("change", event => searchHelper.setDisable(!event.target.checked));
-let searxDivElement = document.getElementById("searx")
-let whoogleDivElement = document.getElementById("whoogle")
+let searxDivElement = document.getElementById("searx");
+let searxngDivElement = document.getElementById("searxng")
+let whoogleDivElement = document.getElementById("whoogle");
function changeFrontendsSettings(frontend) {
@@ -17,25 +16,35 @@ function changeFrontendsSettings(frontend) {
if (frontend == 'searx') {
frontendElement.innerHTML = 'Frontend';
searxDivElement.style.display = 'block';
+ searxngDivElement.style.display = 'none';
+ whoogleDivElement.style.display = 'none';
+ SearxWhoogleElement.style.display = 'block';
+ }
+ else if (frontend == 'searxng') {
+ frontendElement.innerHTML = 'Frontend';
+ searxDivElement.style.display = 'none';
+ searxngDivElement.style.display = 'block';
whoogleDivElement.style.display = 'none';
SearxWhoogleElement.style.display = 'block';
}
else if (frontend == 'whoogle') {
frontendElement.innerHTML = 'Frontend';
searxDivElement.style.display = 'none';
+ searxngDivElement.style.display = 'none';
whoogleDivElement.style.display = 'block';
SearxWhoogleElement.style.display = 'block';
}
else if (frontend == 'startpage') {
frontendElement.innerHTML = `Frontend: <span style="color:red;">This is a centralized service</span>`;
searxDivElement.style.display = 'none';
+ searxngDivElement.style.display = 'none';
whoogleDivElement.style.display = 'none';
SearxWhoogleElement.style.display = 'none';
}
}
let searchFrontendElement = document.getElementById("search-frontend");
searchFrontendElement.addEventListener("change",
- (event) => {
+ event => {
let frontend = event.target.options[searchFrontendElement.selectedIndex].value
searchHelper.setFrontend(frontend)
changeFrontendsSettings(frontend);
@@ -44,7 +53,7 @@ searchFrontendElement.addEventListener("change",
let protocolElement = document.getElementById("protocol")
protocolElement.addEventListener("change",
- (event) => {
+ event => {
let protocol = event.target.options[protocolElement.selectedIndex].value
searchHelper.setProtocol(protocol);
changeProtocolSettings(protocol);
@@ -55,19 +64,26 @@ function changeProtocolSettings(protocol) {
let normalsearxDiv = document.getElementById("searx-normal");
let torsearxDiv = document.getElementById("searx-tor");
+ let normalsearxngDiv = document.getElementById("searxng-normal");
+ let torsearxngDiv = document.getElementById("searxng-tor");
+
let normalwhoogleDiv = document.getElementById("whoogle-normal");
let torwhoogleDiv = document.getElementById("whoogle-tor");
if (protocol == 'normal') {
normalsearxDiv.style.display = 'block';
+ normalsearxngDiv.style.display = 'block';
normalwhoogleDiv.style.display = 'block';
- torwhoogleDiv.style.display = 'none';
torsearxDiv.style.display = 'none';
+ torsearxngDiv.style.display = 'none';
+ torwhoogleDiv.style.display = 'none';
}
else if (protocol == 'tor') {
normalsearxDiv.style.display = 'none';
+ normalsearxngDiv.style.display = 'none';
normalwhoogleDiv.style.display = 'none';
- torwhoogleDiv.style.display = 'block';
torsearxDiv.style.display = 'block';
+ torsearxngDiv.style.display = 'block';
+ torwhoogleDiv.style.display = 'block';
}
}
@@ -104,6 +120,28 @@ searchHelper.init().then(() => {
);
commonHelper.processDefaultCustomInstances(
+ 'searxng',
+ 'normal',
+ searchHelper,
+ document,
+ searchHelper.getSearxngNormalRedirectsChecks,
+ searchHelper.setSearxngNormalRedirectsChecks,
+ searchHelper.getSearxngNormalCustomRedirects,
+ searchHelper.setSearxngNormalCustomRedirects
+ );
+
+ commonHelper.processDefaultCustomInstances(
+ 'searxng',
+ 'tor',
+ searchHelper,
+ document,
+ searchHelper.getSearxngTorRedirectsChecks,
+ searchHelper.setSearxngTorRedirectsChecks,
+ searchHelper.getSearxngTorCustomRedirects,
+ searchHelper.setSearxngTorCustomRedirects
+ );
+
+ commonHelper.processDefaultCustomInstances(
'whoogle',
'normal',
searchHelper,