diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js index 2536afa..678b9dd 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 ea14ca3..26939ad 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 3ad8353..a90ad8e 100644 --- a/src/pages/options/search/search.html +++ b/src/pages/options/search/search.html @@ -138,6 +138,7 @@

Frontend

@@ -211,6 +212,58 @@ +
+
+
+
+

Default Instances

+
+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+

@@ -264,8 +317,6 @@
- - diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js index 68ae017..cc4a44e 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: This is a centralized service`; 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'; } } @@ -103,6 +119,28 @@ searchHelper.init().then(() => { searchHelper.setSearxTorCustomRedirects ); + 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',