Skip to content

Instantly share code, notes, and snippets.

@yasinatesim
Created January 16, 2019 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasinatesim/71466c45ac0911ce93d8bf1771c2317d to your computer and use it in GitHub Desktop.
Save yasinatesim/71466c45ac0911ce93d8bf1771c2317d to your computer and use it in GitHub Desktop.
Sitede Aktif Olmama Uyarısı(Afk)
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Afk Kontrol Testi</title>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
</head>
<body>
<h1>AFK KONTROL TESTİ</h1>
<script>
$(function () {
var maxTimeout = 10; // Azami AFK kalma süresi (10sn)
var afkTimeout = 0; // Sayacımız
var afk = false; // Statüs AFK mi?
// Mouse Klavye hareketinde sayacı ve statüsü sıfırla
$(window).on('mousemove click keydown', function () {
afkTimeout = 0;
afk = false;
});
// Her 1 saniyede sayacı artır ve azami sayaçla karşılaştır
setInterval(function () {
afkTimeout++;
// Eğer verilen süre aşıldı ve ilk statüs afk değil ise
if (afkTimeout >= maxTimeout && afk === false) {
afk = true;
// Onay fonksiyonumuzu çağır
getConfirmation();
}
}, 1000);
// Onay Fonksiyonu
function getConfirmation() {
var result = confirm("Uzun süre işlem yapmadınız bu sekmeyi kapatmak istermisiniz?");
if(result === true){
// Onay Alındığında burası gerçekleşir
alert('Kapatma işlemini kabul ettiniz');
}
else {
// İptal Edildiğinde burası gerçekleşir
alert('Kapatma işlemini iptal ettiniz');
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment