function setCookie(name, value, options) {
options = options || {};
var expires = options.expires;
if (typeof expires == "number" && expires) {
var d = new Date();
d.setTime(d.getTime() + expires * 1000);
expires = options.expires = d;
}
if (expires && expires.toUTCString) {
options.expires = expires.toUTCString();
}
value = encodeURIComponent(value);
var updatedCookie = name + "=" + value;
for (var propName in options) {
updatedCookie += "; " + propName;
var propValue = options[propName];
if (propValue !== true) {
updatedCookie += "=" + propValue;
}
}
document.cookie = updatedCookie;
}
var date = new Date(),
openMinute = date.getMinutes();
var totalSeconds = 0;
setInterval(function(){
++totalSeconds
console.log(totalSeconds)
}, 1000);
window.addEventListener("beforeunload", function (event) {
date = new Date();
var closeMinute = date.getMinutes(),
closeDay = date.getDate();
localStorage.setItem('lastVisitDay', closeDay)
localStorage.setItem('lastVisitMin', closeMinute);
localStorage.setItem('longSec', totalSeconds);
});
var lastVisitMin, lastLongtitudeSec;
lastVisitMin = localStorage.getItem('lastVisitMin');
lastLongtitudeSec = localStorage.getItem('longSec');
minuteLongtitude = openMinute - lastVisitMin;
if(minuteLongtitude <= 1 && parseInt(lastLongtitudeSec) < 20){
setCookie('isClicker', 'true',{
expires: 3600
});
localStorage.clear()
}
https://habrahabr.ru/post/282880/