forked from ankit071105/Ticket-Booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testp.js
33 lines (25 loc) · 1009 Bytes
/
testp.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
26
27
28
29
30
31
32
33
// Get current timestamp
const getCurrentTimestamp = () => {
return new Date().getTime();
};
// Store last active timestamp in LocalStorage
const storeLastActive = () => {
const lastActive = getCurrentTimestamp();
localStorage.setItem('lastActive', lastActive);
};
// Get last active timestamp from LocalStorage
const getLastActive = () => {
return localStorage.getItem('lastActive');
};
// Update last active timestamp on page load and interaction
document.addEventListener('DOMContentLoaded', storeLastActive);
document.addEventListener('click', storeLastActive);
document.addEventListener('scroll', storeLastActive);
document.addEventListener('keydown', storeLastActive);
// Example usage:
const displayLastActive = () => {
const lastActive = getLastActive();
const formattedTime = new Date(parseInt(lastActive)).toLocaleString();
document.getElementById('last-active').innerHTML = Last active: ${formattedTime};
};
displayLastActive();