Last active
October 1, 2018 23:05
-
-
Save Xananax/0c017c99fd1fd1b3f2c7e4f6b5980817 to your computer and use it in GitHub Desktop.
Check if someone comes online in whatsapp web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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