summaryrefslogtreecommitdiff
path: root/searx/static/themes/simple/src/js/main/preferences.js
blob: e9dc7c85ca7c5b1a3a883db6e3e9a61ebbfe31f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* SPDX-License-Identifier: AGPL-3.0-or-later */
(function (w, d, searxng) {
  'use strict';

  if (searxng.endpoint !== 'preferences') {
    return;
  }

  searxng.ready(function () {
    let engine_descriptions = null;
    function load_engine_descriptions () {
      if (engine_descriptions == null) {
        searxng.http("GET", "engine_descriptions.json").then(function (content) {
          engine_descriptions = JSON.parse(content);
          for (const [engine_name, description] of Object.entries(engine_descriptions)) {
            let elements = d.querySelectorAll('[data-engine-name="' + engine_name + '"] .engine-description');
            for (const element of elements) {
              let source = ' (<i>' + searxng.settings.translations.Source + ':&nbsp;' + description[1] + '</i>)';
              element.innerHTML = description[0] + source;
            }
          }
        });
      }
    }

    for (const el of d.querySelectorAll('[data-engine-name]')) {
      searxng.on(el, 'mouseenter', load_engine_descriptions);
    }

    const copyHashButton = d.querySelector("#copy-hash");
    searxng.on(copyHashButton, 'click', (e) => {
      e.preventDefault();
      navigator.clipboard.writeText(copyHashButton.dataset.hash);
      copyHashButton.innerText = copyHashButton.dataset.copiedText;
    });
  });
})(window, document, window.searxng);