Update web/templates/entry_view.html
This commit is contained in:
parent
d30a910e00
commit
91e8aa8b0f
@ -223,4 +223,30 @@
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
const entryId = {{ entry.id }};
|
||||||
|
let timer = null;
|
||||||
|
|
||||||
|
function visible(){ return document.visibilityState === 'visible'; }
|
||||||
|
function start(){
|
||||||
|
if (timer || !visible()) return;
|
||||||
|
timer = setTimeout(()=>{
|
||||||
|
const fd = new FormData();
|
||||||
|
fetch("{% url 'api_log_view' 0 %}".replace("0", entryId), {
|
||||||
|
method:'POST', body: fd,
|
||||||
|
headers: {'X-CSRFToken': (document.cookie.match(/(^|;)\s*csrftoken\s*=\s*([^;]+)/)||[]).pop() || '' }
|
||||||
|
}).catch(()=>{});
|
||||||
|
}, 10000); // 10 seconds
|
||||||
|
}
|
||||||
|
function stop(){ if (timer){ clearTimeout(timer); timer = null; } }
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', ()=> visible() ? start() : stop());
|
||||||
|
window.addEventListener('pagehide', stop);
|
||||||
|
start();
|
||||||
|
{% endif %}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue
Block a user