diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-05-08 17:59:13 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-05-08 17:59:13 +0300 |
commit | 0c6085ce8d7c46c8fa15724154aa904f7e645bfa (patch) | |
tree | 9777e483c3ffd3220d5bb7d3b32d7455fbc87742 /src/pages | |
parent | Merge branch 'master' of https://github.com/libredirect/libredirect (diff) | |
download | libredirect-0c6085ce8d7c46c8fa15724154aa904f7e645bfa.zip |
Added SearXNG Custom Settings #193
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/options/search/search.html | 8 | ||||
-rw-r--r-- | src/pages/options/search/search.js | 63 |
2 files changed, 68 insertions, 3 deletions
diff --git a/src/pages/options/search/search.html b/src/pages/options/search/search.html index 641823f1..45fed601 100644 --- a/src/pages/options/search/search.html +++ b/src/pages/options/search/search.html @@ -154,6 +154,10 @@ </div> </div> <div id="searxng"> + <div class="some-block option-block"> + <h4 data-localise="__MSG_enableCustomSettings__">Enable Custom Settings (will use cookies)</h4> + <input id="enable-searxng-custom-settings" type="checkbox"> + </div> <hr> <div class="custom-settings"> <div class="some-block option-block"> @@ -489,14 +493,14 @@ <h4 data-localise="">Image proxy</h4> <select class="image_proxy"> <option value="1">Enabled</option> - <option value="">Disabled</option> + <option value="0">Disabled</option> </select> </div> <div class="some-block option-block"> <h4 data-localise="">Query in the page's title</h4> <select class="query_in_title"> <option value="1">Enabled</option> - <option value="" selected="selected">Disabled</option> + <option value="">Disabled</option> </select> </div> <div class="some-block option-block"> diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js index 37b0ed46..0cbb79f7 100644 --- a/src/pages/options/search/search.js +++ b/src/pages/options/search/search.js @@ -2,18 +2,49 @@ import searchHelper from "../../../assets/javascripts/helpers/search.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; let searxDiv = document.getElementById("searx"); -let searxngDiv = document.getElementById("searxng") + +let searxngDiv = document.getElementById("searxng"); +let searxngCustomSettings = document.getElementById("enable-searxng-custom-settings"); + +let searxngCustomSettingsDiv = searxngDiv.getElementsByClassName('custom-settings')[0] + let whoogleDiv = document.getElementById("whoogle"); let disableSearchElement = document.getElementById("disable-search"); let searchFrontendElement = document.getElementById("search-frontend"); let protocolElement = document.getElementById("protocol") +let customSettingsDivElement = document.getElementsByClassName("custom-settings"); + +let checkboxes_xpath = document.evaluate( + "//div[@id='searxng']//input[@type='checkbox']", + document, null, XPathResult.ANY_TYPE, null, +); +const inputChecked = []; +let checkbox = checkboxes_xpath.iterateNext(); +while (checkbox) { + inputChecked.push(checkbox); + checkbox = checkboxes_xpath.iterateNext(); +} + +let textInputs_xpath = document.evaluate( + "//div[@id='searxng']//input[@type='text']", + document, null, XPathResult.ANY_TYPE, null, +); +const inputValues = []; +let textInput = textInputs_xpath.iterateNext(); +while (textInput) { + inputValues.push(textInput); + textInput = textInputs_xpath.iterateNext(); +} +inputValues.push(...searxngCustomSettingsDiv.getElementsByTagName('select')); + browser.storage.local.get( [ "disableSearch", "searchFrontend", "searchProtocol", + "searxngCustomSettings" ], r => { disableSearchElement.checked = !r.disableSearch; @@ -23,19 +54,49 @@ browser.storage.local.get( protocolElement.value = r.searchProtocol; changeProtocolSettings(r.searchProtocol); + + + searxngCustomSettings.checked = r.searxngCustomSettings + changeCustomSettings() } ); +for (const element of inputChecked) { + let k = `searxng_${element.className}` + browser.storage.local.get(k, r => element.checked = r[k]) +} +for (const element of inputValues) { + let k = `searxng_${element.className}` + browser.storage.local.get(k, r => element.value = r[k]) +} + +searxngCustomSettingsDiv.addEventListener("change", async () => { + for (const element of inputChecked) + browser.storage.local.set({ [`searxng_${element.className}`]: element.checked }) + + for (const element of inputValues) + browser.storage.local.set({ [`searxng_${element.className}`]: element.value }); +}) + document.addEventListener("change", async () => { await browser.storage.local.set({ disableSearch: !disableSearchElement.checked, searchFrontend: searchFrontendElement.value, searchProtocol: protocolElement.value, + searxngCustomSettings: searxngCustomSettings.checked, }); changeFrontendsSettings(searchFrontendElement.value); changeProtocolSettings(protocolElement.value); + changeCustomSettings(); }) +function changeCustomSettings() { + if (searxngCustomSettings.checked) + for (const item of customSettingsDivElement) item.style.display = 'block'; + else + for (const item of customSettingsDivElement) item.style.display = 'none'; +} + function changeFrontendsSettings(frontend) { let SearxWhoogleElement = document.getElementById("searx-whoogle"); if (frontend == 'searx') { |