Created
October 11, 2022 07:48
-
-
Save geekyorion/4abe374326406caf89e869d5e930c105 to your computer and use it in GitHub Desktop.
WhatsApp get status [need to use console and whatsapp web for this]
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 logs = { | |
| online: [], | |
| offline: [], | |
| typing: [] | |
| }; | |
| let currentStatus = ''; | |
| let timer = new Date(); | |
| const getDateFormat = date => { | |
| const day = date.getDate(); | |
| const month = date.getMonth() + 1; | |
| const year = date.getFullYear(); | |
| const hours = date.getHours(); | |
| const mins = date.getMinutes(); | |
| const secs = date.getSeconds(); | |
| const milisecs = date.getMilliseconds(); | |
| return `${day}-${month}-${year}::${hours}:${mins}:${secs}:${milisecs}`; | |
| } | |
| const log = (status = 'offline') => { | |
| if (!currentStatus) { | |
| currentStatus = status; | |
| } | |
| if (status !== currentStatus) { | |
| const stopTime = new Date(); | |
| logs[currentStatus].push(`${getDateFormat(timer)} to ${getDateFormat(stopTime)}`); | |
| currentStatus = status; | |
| timer = stopTime; | |
| } | |
| } | |
| const logStatus = () => { | |
| const heading = document.querySelector("[data-testid='conversation-header']"); | |
| const text = heading.textContent; | |
| switch(true) { | |
| case /online/.test(text): log('online'); break; | |
| case /typing/.test(text): log('typing'); break; | |
| default: log('offline'); | |
| } | |
| } | |
| let globalInterval = null; | |
| const startLogging = () => { | |
| globalInterval = setInterval(logStatus, 100); | |
| } | |
| const stopLogging = () => { | |
| clearInterval(globalInterval); | |
| } | |
| startLogging(); // to start the log | |
| // stopLogging(); // to stop the log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment