(function(){
    var key = '_lp_' + location.search.replace('?v=','') + '_t';
    var start = Date.now();
    var prev = parseInt(sessionStorage.getItem(key) || '0');
    window.addEventListener('beforeunload', function(){
        var spent = Math.round((Date.now() - start) / 1000);
        sessionStorage.setItem(key, prev + spent);
    });
    setInterval(function(){
        var spent = Math.round((Date.now() - start) / 1000);
        var total = prev + spent;
        document.cookie = key + '=' + total + ';path=/;max-age=86400;SameSite=Lax;Secure';
    }, 5000);
})();
