chore: fixes
This commit is contained in:
parent
e3b292a755
commit
0920087701
1 changed files with 37 additions and 15 deletions
|
|
@ -1,26 +1,48 @@
|
||||||
const VISITOR_COUNTER = document.getElementById("visitorCounter");
|
var VISITOR_COUNTER = document.getElementById("visitorCounter");
|
||||||
|
|
||||||
let xhttp = new XMLHttpRequest();
|
function formatNumber(n) {
|
||||||
xhttp.onreadystatechange = function () {
|
n = n.toString();
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
var result = "";
|
||||||
// Get the data
|
var count = 0;
|
||||||
let site_data = JSON.parse(this.responseText);
|
|
||||||
// Add commas
|
for (var i = n.length - 1; i >= 0; i--) {
|
||||||
let num_arr = site_data.info.views.toString().split("");
|
result = n.charAt(i) + result;
|
||||||
let num_str = "";
|
count++;
|
||||||
for (i = 0; i < num_arr.length; i++) {
|
|
||||||
num_str += num_arr[i];
|
if (count % 3 === 0 && i !== 0) {
|
||||||
if ((num_arr.length - 1 - i) % 3 == 0 && num_arr.length - 1 - i != 0) {
|
result = "," + result;
|
||||||
num_str += ",";
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhttp.onreadystatechange = function () {
|
||||||
|
if (xhttp.readyState === 4) {
|
||||||
|
|
||||||
|
if (xhttp.status === 200) {
|
||||||
|
try {
|
||||||
|
var site_data = eval("(" + xhttp.responseText + ")");
|
||||||
|
var views = site_data.info.views;
|
||||||
|
|
||||||
|
VISITOR_COUNTER.innerHTML = formatNumber(views);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
VISITOR_COUNTER.innerHTML = "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
VISITOR_COUNTER.innerHTML = "N/A";
|
||||||
}
|
}
|
||||||
// Add result to html
|
|
||||||
VISITOR_COUNTER.innerHTML = num_str;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xhttp.open(
|
xhttp.open(
|
||||||
"GET",
|
"GET",
|
||||||
"http://www.veltron.net/counter.php?sitename=venith",
|
"http://www.veltron.net/counter.php?sitename=venith",
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
xhttp.send();
|
|
||||||
|
xhttp.send(null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue