about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assets/javascripts/helpers/search.js147
-rw-r--r--src/pages/options/search/search.html8
-rw-r--r--src/pages/options/search/search.js63
3 files changed, 203 insertions, 15 deletions
diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js
index c26eeb29..e6d230fe 100644
--- a/src/assets/javascripts/helpers/search.js
+++ b/src/assets/javascripts/helpers/search.js
@@ -146,20 +146,107 @@ function initSearxCookies() {
 }
 
 function initSearxngCookies() {
-  let themeValue;
-  if (theme == 'light') themeValue = 'logicodev';
-  if (theme == 'dark') themeValue = 'logicodev-dark';
-  if (applyThemeToSites && themeValue) {
-    let checkedInstances;
-    if (protocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
-    else if (protocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
-    else if (protocol == 'i2p') checkedInstances = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects];
+  browser.storage.local.get(
+    [
+      "searchProtocol",
+      "searchFrontend",
+      "searxngCustomSettings",
 
-    for (const instanceUrl of checkedInstances) {
-      browser.cookies.set({ url: instanceUrl, name: "oscar-style", value: themeValue })
-      browser.cookies.set({ url: instanceUrl, name: "theme", value: 'oscar' })
+      "searxngNormalRedirectsChecks",
+      "searxngNormalCustomRedirects",
+      "searxngTorRedirectsChecks",
+      "searxngTorCustomRedirects",
+      "searxngI2pRedirectsChecks",
+      "searxngI2pCustomRedirects",
+
+      "searxng_category_general",
+      "searxng_category_images",
+      "searxng_category_videos",
+      "searxng_category_news",
+      "searxng_category_map",
+      "searxng_category_music",
+      "searxng_category_it",
+      "searxng_category_science",
+      "searxng_category_files",
+      "searxng_category_social_media",
+      "searxng_language",
+      "searxng_autocomplete",
+      "searxng_safesearch",
+      "searxng_hostname_replace",
+      "searxng_oa_doi_rewrite",
+      "searxng_doi_resolver",
+      "searxng_tokens",
+      "searxng_locale",
+      "searxng_theme",
+      "searxng_simple_style",
+      "searxng_results_on_new_tab",
+      "searxng_infinite_scroll",
+      "searxng_search_on_category_select",
+      "searxng_vim_hotkeys",
+      "searxng_method",
+      "searxng_image_proxy",
+      "searxng_query_in_title",
+      "searxng_tracker_url_remover",
+    ],
+    r => {
+      if (!r.searxngCustomSettings || r.searchFrontend != 'searxng') return;
+      console.log('init SearXNG Cookies');
+      let checkedInstances;
+      if (r.searchProtocol == 'normal') checkedInstances = [...r.searxngNormalRedirectsChecks, ...r.searxngNormalCustomRedirects];
+      else if (r.searchProtocol == 'tor') checkedInstances = [...r.searxngTorRedirectsChecks, ...r.searxngTorCustomRedirects];
+      else if (r.searchProtocol == 'i2p') checkedInstances = [...r.searxngI2pRedirectsChecks, ...r.searxngI2pCustomRedirects];
+
+      let categoryList = [];
+      if (r.searxng_category_general) categoryList.push('general')
+      if (r.searxng_category_images) categoryList.push('images')
+      if (r.searxng_category_videos) categoryList.push('videos')
+      if (r.searxng_category_news) categoryList.push('news')
+      if (r.searxng_category_map) categoryList.push('map')
+      if (r.searxng_category_music) categoryList.push('music')
+      if (r.searxng_category_it) categoryList.push('it')
+      if (r.searxng_category_science) categoryList.push('science')
+      if (r.searxng_category_files) categoryList.push('files')
+      if (r.searxng_category_social_media) categoryList.push('social media')
+      let categoryString = '"' + categoryList.join("\\054") + '"'  // ""general\054images\054videos""
+
+      let enabledPluginsList = [];
+      if (r.searxng_hostname_replace) enabledPluginsList.push('searx.plugins.hostname_replace')
+      if (r.searxng_oa_doi_rewrite) enabledPluginsList.push('searx.plugins.oa_doi_rewrite')
+      if (r.searxng_vim_hotkeys) enabledPluginsList.push('searx.plugins.vim_hotkeys')
+      
+      let enabledPluginsString = '"' + enabledPluginsList.join("\\054") + '"' // ""searx.plugins.hostname_replace\054searx.plugins.oa_doi_rewrite""   
+
+
+      let disabledPluginsList = [];
+      if (!r.searxng_search_on_category_select) disabledPluginsList.push('searx.plugins.search_on_category_select')
+      if (!r.searxng_tracker_url_remover) disabledPluginsList.push('searx.plugins.tracker_url_remover')
+      let disabledPluginsString = '"' + disabledPluginsList.join("\\054") + '"' // ""searx.plugins.hostname_replace\054searx.plugins.oa_doi_rewrite""   
+
+      for (const instanceUrl of checkedInstances) {
+        browser.cookies.set({ url: instanceUrl, name: "categories", value: categoryString });
+
+        browser.cookies.set({ url: instanceUrl, name: "language", value: r.searxng_language });
+        browser.cookies.set({ url: instanceUrl, name: "autocomplete", value: r.searxng_autocomplete });
+        browser.cookies.set({ url: instanceUrl, name: "safesearch", value: r.searxng_safesearch });
+
+        browser.cookies.set({ url: instanceUrl, name: "enabled_plugins", value: enabledPluginsString });
+        browser.cookies.set({ url: instanceUrl, name: "disabled_plugins", value: disabledPluginsString });
+
+        browser.cookies.set({ url: instanceUrl, name: "doi_resolver", value: r.searxng_doi_resolver });
+        browser.cookies.set({ url: instanceUrl, name: "tokens", value: r.searxng_tokens });
+        browser.cookies.set({ url: instanceUrl, name: "locale", value: r.searxng_locale });
+        browser.cookies.set({ url: instanceUrl, name: "theme", value: r.searxng_theme });
+        browser.cookies.set({ url: instanceUrl, name: "simple_style", value: r.searxng_simple_style });
+        browser.cookies.set({ url: instanceUrl, name: "results_on_new_tab", value: r.searxng_results_on_new_tab });
+        browser.cookies.set({ url: instanceUrl, name: "infinite_scroll", value: r.searxng_infinite_scroll });
+        browser.cookies.set({ url: instanceUrl, name: "method", value: r.searxng_method });
+        browser.cookies.set({ url: instanceUrl, name: "image_proxy", value: r.searxng_image_proxy });
+        browser.cookies.set({ url: instanceUrl, name: "query_in_title", value: r.searxng_query_in_title });
+      }
     }
-  }
+  )
+
+
 }
 
 function redirect(url) {
@@ -303,6 +390,7 @@ async function initDefaults() {
         disableSearch: false,
         searchFrontend: 'searxng',
         searchRedirects: redirects,
+        searxngCustomSettings: false,
 
         whoogleNormalRedirectsChecks: whoogleNormalRedirectsChecks,
         whoogleNormalCustomRedirects: [],
@@ -335,6 +423,41 @@ async function initDefaults() {
         applyThemeToSites: false,
 
         searchProtocol: 'normal',
+
+        searxng_category_general: true,
+        searxng_category_images: false,
+        searxng_category_videos: false,
+        searxng_category_news: false,
+        searxng_category_map: false,
+        searxng_category_music: false,
+        searxng_category_it: false,
+        searxng_category_science: false,
+        searxng_category_files: false,
+        searxng_category_social_media: false,
+
+        searxng_language: 'en',
+        searxng_autocomplete: 'google',
+        searxng_safesearch: '0',
+
+        searxng_hostname_replace: false,
+        searxng_oa_doi_rewrite: false,
+
+        searxng_doi_resolver: 'oadoi.org',
+        searxng_tokens: '',
+
+        searxng_locale: 'en',
+        searxng_theme: 'simple',
+        searxng_simple_style: 'auto',
+        searxng_results_on_new_tab: '0',
+        searxng_infinite_scroll: '0',
+
+        searxng_search_on_category_select: true,
+        searxng_vim_hotkeys: false,
+
+        searxng_method: 'POST',
+        searxng_image_proxy: '1',
+        searxng_query_in_title: '',
+        searxng_tracker_url_remover: false,
       })
     })
   })
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') {