-
Notifications
You must be signed in to change notification settings - Fork 191
/
visi.js
25 lines (22 loc) · 873 Bytes
/
visi.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
// Function to get the count from localStorage or initialize it
function getVisitorCount() {
return localStorage.getItem('visitorCount') || 0;
}
// Function to increment and save the count
function incrementVisitorCount() {
if (!localStorage.getItem('visitedHomePage')) {
let count = parseInt(getVisitorCount()) + 1;
localStorage.setItem('visitorCount', count);
localStorage.setItem('visitedHomePage', 'true');
return count;
}
return getVisitorCount();
}
// Function to display the count
function displayVisitorCount() {
const counterElement = document.querySelector('.website-counter');
const count = incrementVisitorCount();
counterElement.textContent = count;
}
// Call the display function when the page loads
document.addEventListener('DOMContentLoaded', displayVisitorCount);