Update visitor.js

This commit is contained in:
Rezza Priatna 2022-08-13 13:34:02 +07:00 committed by GitHub
parent 3c9536d63d
commit 9233a95ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,7 @@
var counterContainer = document.querySelector(".footer-title");
var resetButton = document.querySelector("#reset");
var visitCount = localStorage.getItem("page_view");
// Check if page_view entry is present
if (visitCount) {
visitCount = Number(visitCount) + 1;
localStorage.setItem("page_view", visitCount);
} else {
visitCount = 1;
localStorage.setItem("page_view", 1);
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.countapi.xyz/hit/rezzaapr.my.id/visits");
xhr.responseType = "json";
xhr.onload = function() {
document.querySelector('.footer-title').innerHTML = 'Total Visitor : ' + this.response.value;
}
counterContainer.innerHTML = 'Visitor This Website : '+visitCount;
xhr.send();