Skip to content

Instantly share code, notes, and snippets.

@Xananax
Last active October 1, 2018 23:05
Show Gist options
  • Save Xananax/0c017c99fd1fd1b3f2c7e4f6b5980817 to your computer and use it in GitHub Desktop.
Save Xananax/0c017c99fd1fd1b3f2c7e4f6b5980817 to your computer and use it in GitHub Desktop.
Check if someone comes online in whatsapp web
var audioContext = new AudioContext();
function play(frequency) {
var sampleRate = audioContext.sampleRate;
var duration = 1*sampleRate;
var numChannels = 1;
var buffer = audioContext.createBuffer(numChannels, duration, sampleRate);
var channelData = buffer.getChannelData(0);
for (var i = 0; i < sampleRate; i++) {
channelData[i]=Math.sin(2*Math.PI*frequency*i/(sampleRate));
}
var source = audioContext.createBufferSource();
source.buffer = buffer;
source.connect(audioContext.destination);
source.start(0);
}
var online = false;
var time = () => new Date().toLocaleDateString('en-UK',{hour:'numeric', minute:'numeric', second:'numeric'})
setInterval(()=>{
const isTyping = !!document.querySelector('[title="typing…"]');
const isOnline = !!document.querySelector('[title="online"]')
const considerOnline = isOnline || isTyping
if(considerOnline !== online){
online = considerOnline;
if(online){ console.log('is online!', time() ); play(210) }
else{ console.log('is not online!', time() ) }
}
},1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment