You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
591 B
27 lines
591 B
|
5 years ago
|
let IdleGame = {
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
|
||
|
|
}
|
||
|
|
},
|
||
|
|
mounted() {
|
||
|
|
setInterval(heartBeat, 60000);
|
||
|
|
alert(getPastMinutes());
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
const heartBeat = () => {
|
||
|
|
localStorage.setItem('heartBeat', moment().toISOString());
|
||
|
|
};
|
||
|
|
|
||
|
|
const getPastMinutes = () => {
|
||
|
|
let lastHeartBeat = localStorage.getItem('heartBeat') ?? moment();
|
||
|
|
let minutesPast = Math.round(moment.duration(moment().diff(lastHeartBeat)).as('minutes'));
|
||
|
|
|
||
|
|
return minutesPast > 0 ? minutesPast : 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
const IdleGameInstance = Vue.createApp(IdleGame).mount('#game');
|