summaryrefslogtreecommitdiff
path: root/web/share/js/tools.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-09-19 23:46:49 +0300
committerDevaev Maxim <[email protected]>2019-09-19 23:46:49 +0300
commitaaa60e63a4b66f275d52dc44c8e8198ee52b09e2 (patch)
tree3ce69ce628c084f107f6a15d90c31ba51a8535ca /web/share/js/tools.js
parentf6e02e7219fab418899a0a029bf38e13db95037c (diff)
refactoring
Diffstat (limited to 'web/share/js/tools.js')
-rw-r--r--web/share/js/tools.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/web/share/js/tools.js b/web/share/js/tools.js
index a0f0907e..f249de33 100644
--- a/web/share/js/tools.js
+++ b/web/share/js/tools.js
@@ -24,14 +24,14 @@
export var tools = new function() {
- let __debug = (new URL(window.location.href)).searchParams.get("debug");
-
this.setDefault = function(dict, key, value) {
if (!(key in dict)) {
dict[key] = value;
}
};
+ /************************************************************************/
+
this.makeRequest = function(method, url, callback, body=null, content_type=null) {
let http = new XMLHttpRequest();
http.open(method, url, true);
@@ -44,6 +44,8 @@ export var tools = new function() {
return http;
};
+ /************************************************************************/
+
this.makeId = function() {
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let id = "";
@@ -53,6 +55,8 @@ export var tools = new function() {
return id;
};
+ /************************************************************************/
+
this.getCookie = function(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") + "=([^;]*)" // eslint-disable-line no-useless-escape
@@ -106,13 +110,24 @@ export var tools = new function() {
};
};
+ /************************************************************************/
+
+ let __debug = (new URL(window.location.href)).searchParams.get("debug");
+
this.debug = function(...args) {
if (__debug) {
- console.log("LOG/DEBUG", ...args); // eslint-disable-line no-console
+ __log("DEBUG", ...args);
}
};
- this.info = (...args) => console.log("LOG/INFO", ...args); // eslint-disable-line no-console
- this.error = (...args) => console.error("LOG/ERROR", ...args); // eslint-disable-line no-console
+ this.info = (...args) => __log("INFO", ...args);
+ this.error = (...args) => __log("ERROR", ...args);
+
+ let __log = function(label, ...args) {
+ let now = (new Date()).toISOString().split("T")[1].replace("Z", "");
+ console.log(`[${now}] LOG/${label} --`, ...args);
+ };
+
+ /************************************************************************/
this.browser = new function() {
// https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser/9851769