Skip to content

Instantly share code, notes, and snippets.

@yongzhihuang
Created December 29, 2014 15:52
Show Gist options
  • Save yongzhihuang/4b2f54f827dda55f6fa6 to your computer and use it in GitHub Desktop.
Save yongzhihuang/4b2f54f827dda55f6fa6 to your computer and use it in GitHub Desktop.
Make slack play sound on new message
javascript:function playSound(b,a){b.mp3?b.mp3.paused?b.mp3.play():b.mp3.pause():(b.mp3=new Audio(a),b.mp3.play())}
setInterval(function(){if(localStorage.lastMessage)b=$(".message").last().find(".message_sender").text().trim(),a=$(".message").last().find(".message_content").text().trim(),a!==localStorage.lastMessage&&(c=/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/,a.match(c)&&a.match(c)[0]&&(a=a.replace(a.match(c)[0],b+" shared a link")),playSound(this,"https://mansueto.campfirenow.com/sounds/incoming.mp3"),localStorage.lastMessage=a);else{var b=$(".message").last().find(".message_sender").text().trim(),
a=$(".message").last().find(".message_content").text().trim(),c=/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;a.match(c)&&a.match(c)[0]&&(a=a.replace(a.match(c)[0],b+" shared a link"));playSound(this,"https://mansueto.campfirenow.com/sounds/incoming.mp3");localStorage.lastMessage=a}},2500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment