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()
@AravindhGopi
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.....

@magdale76
Copy link

I'm getting this error.....

me too

@Calicorio
Copy link

I got this error:

VM43:31 Uncaught TypeError: Cannot read property 'dispatchEvent' of null
    at triggerClick (<anonymous>:31:53)
    at countdown_dimaro (<anonymous>:33:1)
    at <anonymous>:37:1

@ninoeid
Copy link

ninoeid commented Oct 31, 2017

Anybody succeeded at running this script with no error?

Copy link

ghost commented Nov 14, 2018

Can anybody help? how does it work?
i also just get this error

Uncaught TypeError: Cannot read property 'focus' of null
at dispatch (:18:11)
at countdown_dimaro (:23:1)
at :37:1

@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