Created
July 23, 2018 13:34
-
-
Save janwirth/5111bb532e131adc814092c94cbeea9e to your computer and use it in GitHub Desktop.
Monitor a person's whatsapp online status. Use with whatsapp web.
This file contains hidden or 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
const STATUS_SPAN_SELECTOR = '.O90ur' | |
function record(data) | |
{ | |
var a = []; | |
// Parse the serialized data back into an aray of objects | |
a = JSON.parse(localStorage.getItem('session') || '[]'); | |
// Push the new data (whether it be an object or anything else) onto the array | |
a.push(data); | |
// Alert the array value | |
console.log(a); // Should be something like [Object array] | |
// Re-serialize the array back into a string and store it in localStorage | |
localStorage.setItem('session', JSON.stringify(a)); | |
} | |
// select the target node | |
var target = document.querySelector(STATUS_SPAN_SELECTOR); | |
console.log('recording from element', target) | |
// create an observer instance | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
record({time: new Date(), status: mutation.target.title}) | |
}); | |
}); | |
// configuration of the observer: | |
var config = { attributes: true, childList: true, characterData: true } | |
// pass in the target node, as well as the observer options | |
observer.observe(target, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment