Created
November 24, 2016 17:25
-
-
Save antonhedstrom/604a2977c12b8f4d2d1d16fc2521ef72 to your computer and use it in GitHub Desktop.
Prank: Play random sound
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
| // Install Chrome extension (in order to execute after page reloads as well): | |
| // https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija | |
| // After installation, add script and right the icon and choose 'Hide in Chrome Menu'. | |
| (function() { | |
| var defaultDelay = 3 * 60; // secs | |
| var numberOfRuns = 0; | |
| var soundUrls = [ | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/final-scream.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/howl-mono.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/i-can-see-you.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/low-mean-growl.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/loud-thunder-clap.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/why-have-you-disturbed-us.mp3', | |
| 'http://www.szworld.net/scary-sounds/downloader.php?file=audio/you-are-going-to-die.mp3' | |
| ]; | |
| activate(); | |
| // Expose run | |
| window.playSound = activate; | |
| function activate(delay) { | |
| // Preload sound | |
| var sound = loadSound(getRandomSoundUrl()); | |
| delay = delay || defaultDelay; | |
| numberOfRuns++; | |
| setTimeout(function() { | |
| sound.play(); | |
| activate(delay); | |
| }, numberOfRuns * delay * 1000); | |
| } | |
| function loadSound(url) { | |
| var audio = new Audio(url); | |
| return audio; | |
| } | |
| function getRandomSoundUrl() { | |
| return soundUrls[Math.floor(Math.random() * soundUrls.length)]; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment