Skip to content

Instantly share code, notes, and snippets.

@DevWouter
Last active May 4, 2020 12:30
Show Gist options
  • Save DevWouter/fdc683dc1c102c94025b to your computer and use it in GitHub Desktop.
Save DevWouter/fdc683dc1c102c94025b to your computer and use it in GitHub Desktop.
Countdown timer for whatsapp (now with instructions)
/**
* This script was written in 2015 and no longer works since 2017.
* The issue is most likely the `document.querySelector` since the queries return no results.
*/
// How to use this script:
// 1. Go to web.whatsapp.com and connect your device.
// 2. Open the developer console in chrome (F11 on windows, command+alt+i on mac)
// 3. Go to the tab console
// 4. Copy the script below, paste it and press enter.
// 5. To stop the script run `clearInterval(interval_tracker)`
alert("Please read the intro, this script is broken");
function getTime() {
var difference = (new Date(2015,9,24, 16) - new Date()) / (1000* 60*60);
var hours = Math.floor(difference)
var minutes = Math.floor((difference - hours) * 60) +"";
if(minutes.length == 1){
minutes = "0" + minutes;
}
var timeToGo = hours +":" + minutes;
return timeToGo
}
function countdown_dimaro(){
function dispatch(target, eventType, char) {
var evt = document.createEvent("TextEvent");
evt.initTextEvent (eventType, true, true, window, char, 0, "en-US");
target.focus();
target.dispatchEvent(evt);
}
dispatch(document.querySelector(".input-container div"), "textInput", "Nog maar " + getTime() + " voordat de reunie begint!");
function triggerClick() {
var event = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
document.querySelector(".icon.btn-icon.icon-send").dispatchEvent(event)
}
triggerClick()
}
var interval_tracker = setInterval(countdown_dimaro, 1000 * 60 * 20);
countdown_dimaro()
@mukeshdak
Copy link

VM40:18 Uncaught TypeError: Cannot read property 'focus' of null
    at dispatch (<anonymous>:18:10)
    at countdown_dimaro (<anonymous>:23:1)
    at <anonymous>:37:1

I'm getting this error.....

I got exactly same error

@DevWouter
Copy link
Author

DevWouter commented May 4, 2020

For those who have issues getting it to work. This was written in 2015 and since then WhatsApp has changed while this script has remained the same. And since I'm no longer using WhatsApp I will no longer update it.

The problem you experience is that that document.querySelector on line 37 and 45 no longer point to the correct value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment