Created
July 23, 2015 19:35
-
-
Save qgustavor/8315a3152a72d5040bc6 to your computer and use it in GitHub Desktop.
Quick Reddit Message Alert
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 lastMessageId = ''; | |
(function loop(){ | |
$.getJSON('https://www.reddit.com/message/inbox.json',function(result){ | |
var lastId = result.data.children[0].data.id; | |
if (lastMessageId !== lastId ) { | |
if (lastMessageId) { | |
alert('New message received'); | |
} else { | |
console.log('Listening for new messages'); | |
console.log('Last message id:', lastId); | |
} | |
lastMessageId = lastId; | |
} | |
setTimeout(loop, 5 * 60e3); | |
})}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment