Skip to content

Instantly share code, notes, and snippets.

@rosenpin
Last active August 11, 2018 13:38
Show Gist options
  • Save rosenpin/79e28f111f525321796371d43139d611 to your computer and use it in GitHub Desktop.
Save rosenpin/79e28f111f525321796371d43139d611 to your computer and use it in GitHub Desktop.
Get an array representing the hours a person is active on Whatsapp. Saved to local Storage and viewable by using 'console.log(hoursArray)'
var LOCAL_STORAGE_KEY = "activelogintimestatistics"
var lastSeenTime
var localStorageData = localStorage[LOCAL_STORAGE_KEY]
var localStorageArray = localStorageData != undefined ? JSON.parse(localStorageData) : undefined
var hoursArray = (localStorageArray == undefined) ? [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] : localStorageArray
console.log(hoursArray)
update = function() {
var textSpan = document.getElementsByClassName("emojitext O90ur")[0]
if (textSpan == null) {
console.log("An error has occured, couldn't find the last seen label")
return
}
var text = textSpan.innerText
if (text == "online") {
var currentTime = new Date()
var currentHour = currentTime.getHours()
addMinute(parseInt(hour))
console.log("Adding to " + currentHour + " Because User is online")
return
}
text = text.substr(10, text.length)
var day = text.substr(0, text.indexOf(" at"))
if (day == "today") {
var newestLastSeen = text.substr(text.indexOf(" at") + 3, text.length)
console.log(newestLastSeen)
if (newestLastSeen != lastSeenTime) {
var hour = newestLastSeen.substr(0, newestLastSeen.indexOf(":"))
console.log("adding to" + hour)
lastSeenTime = newestLastSeen
addMinute(parseInt(hour))
console.log("Minutes logged in on that hour: " + hoursArray[parseInt(hour)])
} else {
console.log("Not adding because user didn't login since last login")
return
}
} else {
console.log("Not adding because user didn't login today yet")
return
}
}
function addMinute(index) {
hoursArray[index] = hoursArray[index] + 1
localStorage[LOCAL_STORAGE_KEY] = JSON.stringify(hoursArray);
}
setInterval(update, 60000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment