-
Notifications
You must be signed in to change notification settings - Fork 15
/
definitions.js
97 lines (97 loc) · 2.66 KB
/
definitions.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var get_args = {};
if( 1 < window.location.search.length ) {
var pairs = window.location.search.substring(1).split('&');
for( var i in pairs ) {
var ler = pairs[i];
var e = ler.indexOf('=');
var key = decodeURIComponent(ler.substring(0,e));
var val = decodeURIComponent(ler.substring(e+1));
get_args[key] = val;
}
}
String.prototype.padStart = function(size,pad) {
var r = this;
while (r.length < (size || 2)) {r = pad + r;}
return r;
}
function seconds2str(s) {
var d = Math.floor(s/(24*60*60));
s = s%(24*60*60);
var h = Math.floor(s/(60*60));
s = s%(60*60);
var m = Math.floor(s/60);
s = s%60;
return (d>0? d + 'd ' : '') + h + ':' + String(m).padStart(2,0) + ':' + String(s).padStart(2,0);
}
function loadURL(url,handle) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
handle(this);
}
};
xhttp.open("GET", url);
xhttp.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0");
// fallbacks for IE and older browsers:
xhttp.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");
xhttp.setRequestHeader("Pragma", "no-cache");
xhttp.send();
}
function FilteredTable(table) {
var ret = {};
ret.table = table;
ret.filters = [];
ret.refresh = function () {
var filterValues = [];
for( var j = 0; j < ret.filters.length; j++ ) {
var id = ret.filters[j];
filterValues[j] = id == null ? "" : document.getElementById(id).value;
}
var trs = ret.table.getElementsByTagName("tr");
for( var i = 0; i < trs.length; i++ ) {
if( trs[i].classList.contains("head") ) {// row of class "head" won't be filtered
continue;
}
var tds = trs[i].getElementsByTagName("td");
for( var j = 0; ; j++ ) {
if( filterValues.length <= j ) {
trs[i].style.display = "";
break;
}
var td = tds[j];
if( td != null && (td.textContent || td.innerText).indexOf(filterValues[j]) < 0 ) {
trs[i].style.display = "none";
break;
}
}
}
}
ret.register = function(column,id) {
ret.filters[column] = id;
}
return ret;
}
function StyleToggler(button, select, options, index = 0) {
var ret = {};
ret.button = button;
ret.select = select;
ret.options = options;
ret.index = index;
ret.apply = function(elm) {
var option = ret.options[ret.index];
ret.button.innerHTML = option.text;
var targets = elm.querySelectorAll(select);
for( var i = 0; i < targets.length; i++ ) {
for( var key in option.assign ) {
targets[i].style[key] = option.assign[key];
}
}
}
ret.toggle = function() {
ret.index = (ret.index + 1) % ret.options.length;
ret.apply(document);
}
ret.apply(document);
ret.button.onclick = ret.toggle;
return ret;
}