Last active
September 9, 2016 17:37
-
-
Save cubedtear/b4925ba6b9a9b342fa961d673a8f2e1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function(){ | |
var window_focus = true; | |
var wasOnLine = false; | |
function addCheckBox() { | |
if ($('.pane-chat-header').find("#checkLog").length === 0) { | |
var logCheckbox = document.createElement('input'); | |
logCheckbox.type = "checkbox"; | |
logCheckbox.name = "LogOnLine"; | |
logCheckbox.value = "LogOnLine"; | |
logCheckbox.id = "checkLog"; | |
var lblLog = document.createElement('label'); | |
lblLog.for = "checkLog"; | |
lblLog.id = "lblLog"; | |
var notifyCheckbox = document.createElement('input'); | |
notifyCheckbox.type = "checkbox"; | |
notifyCheckbox.name = "Notify"; | |
notifyCheckbox.value = "Notify"; | |
notifyCheckbox.id = "checkNotif"; | |
var lblNotif = document.createElement('label'); | |
lblNotif.for = "checkNotif"; | |
lblNotif.id = "lblNotif"; | |
$('div.pane-chat-controls').before(logCheckbox); | |
$('#checkLog').after(lblLog); | |
$('#lblLog').after(notifyCheckbox); | |
$('#checkNotif').after(lblNotif); | |
$("#checkLog").css('margin-right', '5px'); | |
$("#lblLog").text("Log"); | |
$("#lblLog").css('margin-right', '20px'); | |
$("#lblLog").css('color', '#ffffff'); | |
$("#checkNotif").css('margin-right', '5px'); | |
$("#lblNotif").text("Notify"); | |
$("#lblNotif").css('margin-right', '20px'); | |
$("#lblNotif").css('color', '#ffffff'); | |
} | |
} | |
$(window).focus(function() { | |
window_focus = true; | |
}).blur(function() { | |
window_focus = false; | |
}); | |
function checkOnLine() { | |
if ($('.pane-chat-header').find('.chat-status').length > 0) { // Is online | |
if (!wasOnLine && !window_focus) { // Was not online | |
wasOnLine = true; | |
if($("#checkLog").is(':checked')) { // Log to console | |
var currentdate = new Date(); | |
var datetime = "Online at: " + currentdate.getDate() + "/" | |
+ (currentdate.getMonth()+1) + "/" | |
+ currentdate.getFullYear() + " @ " | |
+ currentdate.getHours() + ":" | |
+ currentdate.getMinutes() + ":" | |
+ currentdate.getSeconds(); | |
console.log(datetime); | |
} | |
if ($("#checkNotif").is(':checked')) { // Show notification | |
showNotification(); | |
//window.alert("Online!"); | |
} | |
} | |
} else { | |
wasOnLine = false; | |
} | |
} | |
setInterval(checkOnLine, 1000); | |
setInterval(addCheckBox, 500); | |
document.addEventListener('DOMContentLoaded', function () { | |
if (Notification.permission !== "granted") | |
Notification.requestPermission(); | |
}); | |
function showNotification() { | |
if (!Notification) { | |
alert('Desktop notifications not available in your browser. Try Chromium.'); | |
return; | |
} | |
if (Notification.permission !== "granted") | |
Notification.requestPermission(); | |
else { | |
var notification = new Notification('On line!', { | |
icon: 'https://www.cdn.whatsapp.net/img/v2/logo-whatsapp.png?v=20', | |
body: "On line!", | |
}); | |
} | |
} | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment