summaryrefslogtreecommitdiff
path: root/kvmd/web/js/tools.js
blob: 6714908506dca16c6bc59c52cd125c494af489aa (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
var tools = new function() {
	var __debug = (new URL(window.location.href)).searchParams.get("debug");

	this.makeRequest = function(method, url, callback, timeout=null) {
		var http = new XMLHttpRequest();
		http.open(method, url, true);
		http.onreadystatechange = callback;
		http.timeout = (timeout ? timeout : 5000);
		http.send();
		return http;
	};

	this.debug = function(...args) {
		if (__debug) {
			console.log("LOG/DEBUG", ...args);  // eslint-disable-line no-console
		}
	};

	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
};

var $ = (id) => document.getElementById(id);
var $$ = (cls) => document.getElementsByClassName(cls);