summaryrefslogtreecommitdiff
path: root/searx/static/themes/simple/src/js/main/00_toolkit.js
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2022-01-23 11:37:57 +0100
committerAlexandre Flament <alex@al-f.net>2022-02-20 22:58:51 +0100
commit56e34947a6368e6154064c52fa23d21ecda7ab4c (patch)
treebad1463a0c3056896cfacb205039586b85a2c04d /searx/static/themes/simple/src/js/main/00_toolkit.js
parent36aee70c247fe347c69abb17ec3bdc31781204c6 (diff)
[mod] infinite_scroll as preference
* oscar theme: code from searx/plugins/infinite_scroll.py * simple theme: new implementation Co-authored-by: Markus Heiser <markus.heiser@darmarIT.de>
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.js81
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);