diff options
| author | Alexandre Flament <alex@al-f.net> | 2022-02-21 12:49:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-21 12:49:04 +0100 |
| commit | 8230603f4834003c79938b472d1f6328b1af2ae8 (patch) | |
| tree | 39ec6d65a8e04ba56fb1ba6f91cd8df068a85129 /searx/static/themes/simple/src/js/main/00_toolkit.js | |
| parent | 6c38bb599447db8cbe3436e4c3596ca0f4574080 (diff) | |
| parent | 1832ec742a378f0fd2162e3c07b7c279544c86f8 (diff) | |
Merge pull request #916 from dalf/pref_infinite_scroll2
Convert the infinite_scroll plugin as a preference (second version)
Diffstat (limited to 'searx/static/themes/simple/src/js/main/00_toolkit.js')
| -rw-r--r-- | searx/static/themes/simple/src/js/main/00_toolkit.js | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/searx/static/themes/simple/src/js/main/00_toolkit.js b/searx/static/themes/simple/src/js/main/00_toolkit.js index c5b7fe578..f53842d72 100644 --- a/searx/static/themes/simple/src/js/main/00_toolkit.js +++ b/searx/static/themes/simple/src/js/main/00_toolkit.js @@ -59,43 +59,45 @@ window.searxng = (function (w, d) { } }; - searxng.http = function (method, url) { - var req = new XMLHttpRequest(), - resolve = function () {}, - reject = function () {}, - promise = { - then: function (callback) { resolve = callback; return promise; }, - catch: function (callback) { reject = callback; return promise; } - }; - - try { - req.open(method, url, true); + searxng.http = function (method, url, data = null) { + return new Promise(function (resolve, reject) { + try { + var req = new XMLHttpRequest(); + req.open(method, url, true); + req.timeout = 20000; + + // On load + req.onload = function () { + if (req.status == 200) { + resolve(req.response, req.responseType); + } else { + reject(Error(req.statusText)); + } + }; + + // Handle network errors + req.onerror = function () { + reject(Error("Network Error")); + }; + + req.onabort = function () { + reject(Error("Transaction is aborted")); + }; + + req.ontimeout = function () { + reject(Error("Timeout")); + } - // On load - req.onload = function () { - if (req.status == 200) { - resolve(req.response, req.responseType); + // Make the request + if (data) { + req.send(data) } else { - reject(Error(req.statusText)); + req.send(); } - }; - - // Handle network errors - req.onerror = function () { - reject(Error("Network Error")); - }; - - req.onabort = function () { - reject(Error("Transaction is aborted")); - }; - - // Make the request - req.send(); - } catch (ex) { - reject(ex); - } - - return promise; + } catch (ex) { + reject(ex); + } + }); }; searxng.loadStyle = function (src) { @@ -148,5 +150,16 @@ window.searxng = (function (w, d) { this.parentNode.classList.add('invisible'); }); + function getEndpoint () { + for (var className of d.getElementsByTagName('body')[0].classList.values()) { + if (className.endsWith('_endpoint')) { + return className.split('_')[0]; + } + } + return ''; + } + + searxng.endpoint = getEndpoint(); + return searxng; })(window, document); |