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();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
// Get the data
|
||||
let site_data = JSON.parse(this.responseText);
|
||||
// Add commas
|
||||
let num_arr = site_data.info.views.toString().split("");
|
||||
let num_str = "";
|
||||
for (i = 0; i < num_arr.length; i++) {
|
||||
num_str += num_arr[i];
|
||||
if ((num_arr.length - 1 - i) % 3 == 0 && num_arr.length - 1 - i != 0) {
|
||||
num_str += ",";
|
||||
}
|
||||
function formatNumber(n) {
|
||||
n = n.toString();
|
||||
var result = "";
|
||||
var count = 0;
|
||||
|
||||
for (var i = n.length - 1; i >= 0; i--) {
|
||||
result = n.charAt(i) + result;
|
||||
count++;
|
||||
|
||||
if (count % 3 === 0 && i !== 0) {
|
||||
result = "," + result;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"GET",
|
||||
"http://www.veltron.net/counter.php?sitename=venith",
|
||||
true
|
||||
);
|
||||
xhttp.send();
|
||||
|
||||
xhttp.send(null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue