Skip to content

Instantly share code, notes, and snippets.

@geekyorion
Created October 11, 2022 07:48
Show Gist options
  • Save geekyorion/4abe374326406caf89e869d5e930c105 to your computer and use it in GitHub Desktop.
Save geekyorion/4abe374326406caf89e869d5e930c105 to your computer and use it in GitHub Desktop.
WhatsApp get status [need to use console and whatsapp web for this]
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