├── cfn.js ├── cfn.min.js ├── demo ├── index.html ├── scary-sound.mp3 └── style.css ├── license.md └── readme.md /cfn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Console Fright Night 3 | * - Play audio when the web console has been opened. 4 | * -- Works by constantly hitting the console log, and hijacking the id check. 5 | * 6 | * MIT licensed 7 | * Copyright (C) 2016 Tim Holman, http://tholman.com 8 | */ 9 | 10 | function CFN(options) { 11 | 12 | var checkSpeed = 500; 13 | var audioIsPlaying = false; 14 | var audioCheck = false; 15 | 16 | var audioElement; 17 | 18 | // Setup 19 | function init(options) { 20 | 21 | if( !options || !options.src ) { 22 | console.log('Oh no, no source!'); 23 | return; 24 | } 25 | 26 | audioElement = document.createElement('audio'); 27 | audioElement.src = options.src; 28 | 29 | // When the console logs and is open, it requests the id. 30 | // We can jack into this, to tell when the console has been opened. 31 | audioElement.__defineGetter__('id', function() { 32 | audioCheck = true; 33 | }); 34 | 35 | // Just keep checking to see if anything opens :o 36 | setInterval( checkTheConsole, checkSpeed ); 37 | } 38 | 39 | // Function hits the console, which lets our "getting" function run. 40 | function checkTheConsole() { 41 | audioCheck = false; 42 | console.log("Check the console: ", audioElement); 43 | if( audioCheck === true || (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized)) { 44 | play(); 45 | } else { 46 | dontPlay(); 47 | } 48 | } 49 | 50 | // Play the audio 51 | function play() { 52 | if (audioIsPlaying) { 53 | return; 54 | } 55 | 56 | audioElement.play(); 57 | audioIsPlaying = true; 58 | } 59 | 60 | // Stop the audio 61 | function dontPlay() { 62 | audioIsPlaying = false; 63 | audioElement.pause(); 64 | audioElement.currentTime = 0; 65 | } 66 | 67 | init(options); 68 | } -------------------------------------------------------------------------------- /cfn.min.js: -------------------------------------------------------------------------------- 1 | function CFN(e){function n(e){return e&&e.src?(r=document.createElement("audio"),r.src=e.src,r.__defineGetter__("id",function(){d=!0}),void setInterval(o,t)):void console.log("Oh no, no source!")}function o(){d=!1,console.log("Check the console: ",r),d===!0||window.Firebug&&window.Firebug.chrome&&window.Firebug.chrome.isInitialized?i():c()}function i(){u||(r.play(),u=!0)}function c(){u=!1,r.pause(),r.currentTime=0}var r,t=500,u=!1,d=!1;n(e)} -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Console Fright Night 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

CONSOLE FRIGHT NIGHT
**OPEN THE CONSOLE**

20 |
CMD + OPT + I on Mac.
Or CTRL + SHIFT + I on Windows
21 | 24 |
25 | 26 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /demo/scary-sound.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tholman/console-fright-night/abfec0eb1a015ae940b6250645adea2f3cbe952b/demo/scary-sound.mp3 -------------------------------------------------------------------------------- /demo/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: monospace; 3 | text-align: center; 4 | } 5 | 6 | span { 7 | font-family: helvetica; 8 | text-align: center; 9 | text-transform: uppercase; 10 | padding-left: 10px; 11 | padding-right: 10px; 12 | padding-top: 10px; 13 | padding-bottom: 10px; 14 | border: 2px solid #f5f5f5; 15 | border-radius: 6px; 16 | min-width: 22px; 17 | display: inline-block; 18 | letter-spacing: 1px; 19 | background: black; 20 | color: #f5f5f5; 21 | box-shadow: 0px 5px 0px 0px rgba(0, 0, 0, 1); 22 | } 23 | 24 | .wrap { 25 | position: absolute; 26 | font-size: 20px; 27 | left: 50%; 28 | top: 50%; 29 | width: 900px; 30 | transform: translate(-50%, -50%); 31 | margin-top: -30px; 32 | } 33 | 34 | .links { 35 | margin-top: 60px; 36 | font-size: 16px; 37 | } 38 | 39 | iframe { 40 | margin-bottom: -5px; 41 | } 42 | 43 | a, iframe { 44 | margin-left: 5px; 45 | margin-right: 5px; 46 | } 47 | 48 | .mini-wrap { 49 | display: inline-block; 50 | margin-left: 10px; 51 | margin-right: 10px; 52 | } 53 | 54 | @media (max-width: 900px) { 55 | 56 | .wrap { 57 | max-width: 900px; 58 | width: 100%; 59 | min-width: 600px; 60 | } 61 | 62 | .mini-wrap { 63 | display: block; 64 | margin-bottom: 30px; 65 | } 66 | 67 | .links a, .links iframe{ 68 | display: block; 69 | } 70 | 71 | iframe { 72 | margin: auto; 73 | } 74 | } 75 | 76 | @media (max-width: 450px) { 77 | h1 { 78 | font-size: 20px; 79 | margin-bottom: 30px; 80 | } 81 | 82 | .wrap { 83 | font-size: 10px; 84 | } 85 | } -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Tim Holman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Console Fright Night 2 | 3 | Give someone an audio fright... or welcome, when they open the web inspector/console on your website (using Safari/Chrome... sorry!) 4 | 5 | #### Instructions 6 | 7 | `Console Fright Night` is a stand alone library (no jQuery, or the likes) so usage is pretty straight forward. You'll need to include `CFN.js` to your page, and create a new instance of `CFN`. 8 | 9 | #### Usage 10 | 11 | `Console Fright Night (CFN)` lives entirely within the JS realm, which makes things fairly simple to use. 12 | 13 | ```html 14 | 23 | ``` 24 | 25 | #### But How? 26 | `CFN` defines a custom "getter" to an audio element, which is then constantly logged to the console. When the browser is actually open, this getter will be triggered, allowing us to detect that the console is open. This happens on lines 31 - 33 of `cfn.js`. 27 | 28 | Because of these console checks, it will look like your console is being spammed, but that's how it works. Not much else we can do there. 29 | 30 | #### License 31 | 32 | Console Fright Night is covered by the MIT License. 33 | 34 | Copyright (C) ~ [Tim Holman](http://tholman.com) ~ timothy.w.holman@gmail.com 35 | --------------------------------------------------------------------------------