forked from YadavAkhileshh/Alien-Invasion-Defense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testp.js
31 lines (25 loc) · 1006 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
// 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();