Skip to content

Instantly share code, notes, and snippets.

@gloony
Last active March 10, 2024 19:33
Show Gist options
  • Save gloony/1d11573ceeb364a723e96e4ea7a35773 to your computer and use it in GitHub Desktop.
Save gloony/1d11573ceeb364a723e96e4ea7a35773 to your computer and use it in GitHub Desktop.
WhatsApp Auto reply
let occurrences = [];
var lastMessage = null;
var inSend = false;
async function loopChat() {
if(inSend) return;
let elementsWithAriaLabel = document.querySelectorAll('[aria-label]');
console.log('Check new message');
elementsWithAriaLabel.forEach(async element => {
var ariaLabel = element.getAttribute('aria-label');
if (ariaLabel.includes("message") && ariaLabel.includes("non lu")) {
let el = element.parentNode.parentNode.parentNode.parentNode.querySelector('span[aria-label=""]'),
message = el.innerText,
elsec = null;
console.log('Found : ' + message);
if(el.parentElement.parentElement.querySelectorAll('span span')[2]!==undefined){
elsec = el.parentElement.parentElement.querySelectorAll('span span')[2];
message = elsec.innerText;
console.log('Found : ' + message);
}
if (message.match(/(m(ain|in|en|an|un)t(en|n)(en|an)t|mnt)([*\s]|)[?]/gmi)) {
console.log('Send time from now');
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
inSend = true;
await new Promise(resolve => setTimeout(resolve, 1000));
let ed = document.querySelectorAll("[contenteditable='true']")[1];
ed.innerHTML = getTimeFromNow();
const event = new InputEvent('input', {
bubbles: true,
cancelable: true,
composed: true,
inputType: 'insertText',
data: getTimeFromNow()
});
ed.dispatchEvent(event);
await new Promise(resolve => setTimeout(resolve, 1000));
document.querySelectorAll('[aria-label="Envoyer"]')[0].click();
inSend = false;
}
}
});
}
setInterval(loopChat, 2000);
loopChat();
let countDown = new Date('Apr 27, 2024 10:00:00');
function getTimeFromNow(){
const second = 1000, minute = second * 60, hour = minute * 60, day = hour * 24;
let text = '', now = new Date().getTime(), distance = countDown - now;
var days = Math.floor(distance / (day)),
hours = Math.floor((distance % (day)) / (hour)),
minutes = Math.floor((distance % (hour)) / (minute)),
seconds = Math.floor((distance % (minute)) / second);
hours = ('0' + hours).slice(-2),
minutes = ('0' + minutes).slice(-2),
seconds = ('0' + seconds).slice(-2);
if(days!=='00'){
text += days + 'jour';
if(days > 1) text += 's';
}
if(hours!=='00'){
text += ' ' + hours + 'heure';
if(hours > 1) text += 's';
}
if(minutes!=='00'){
text += ' ' + minutes + 'minute';
if(minutes > 1) text += 's';
}
if(seconds!=='00'){
text += ' ' + seconds + 'seconde';
if(seconds > 1) text += 's';
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment