-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.html
94 lines (87 loc) · 3.51 KB
/
report.html
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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Report generation for the silent hit counter intended for Markdown files. https://github.com/jxmot/markdown-hitcounter"/>
<meta name="author" content="Jim Motyl - https://github.com/jxmot/markdown-hitcounter"/>
<title>My Repositories' Hit Counters</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- https://getbootstrap.com/docs/4.0/getting-started/contents/ -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="repout">
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
/*
Send a GET request and invoke a
callback function when completed.
*/
function httpGet(url, callback, tickle = false) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
var resp = this.responseText;
console.log(`${this.readyState} - ${this.status} - ${resp.length}`);
callback(resp);
} else {
console.log(`${this.readyState} - ${this.status}`);
}
};
// bypass caching, useful when retrieving resources
// that change frequently
if((tickle === true) && (url.includes('?') === false)) {
// ToDo: if url already has a "?" in it then use "&_=" instead
url = url + '?_=' + new Date().getTime();
}
xmlhttp.open('GET', url, true);
xmlhttp.send();
};
//////////////////////////////////////////////////////////////////////////
// sorting types
var sorts = ['?csort=','?isort=','?tsort='];
// sort directions
var sdirs = ['a','d'];
// URL to report generator
var url = './mdreport.php';
// optional limiting qty of counters returned
var limit = '&limit=10';
// './mdreport.php' + '?tsort=' + 'd'
var datasrc = url+sorts[2]+sdirs[1];//+limit;
// create a table with mdreport.php and place
// it within an specified element ID
function createTable(elemid, ds) {
httpGet(ds, (resp) => {
$(elemid).hide();
$(elemid).html(resp);
// wait for a column in this table to be clicked
$(elemid+' .orderhover').click((col) => {
var target = {
id: col.target.id,
ix: col.target.dataset.ix,
order: col.target.dataset.order
};
$(document).trigger('newtable', target);
});
setTimeout((id) => {
$(id).show();
}, 100, elemid);
},false);
};
// render the table of counters
createTable('#repout', datasrc);
// when a column heading is clicked
$(document).on('newtable', (e, target) => {
$('.orderhover').off('click');
// build the URL and query...
var datasrc = url+sorts[target.ix - 1] + (target.order === 'a' ? 'd' : 'a');// + limit;
// go get it!
createTable('#repout', datasrc);
});
});
</script>
</body>
</html>