Skip to content

Instantly share code, notes, and snippets.

@apisurfer
Last active October 13, 2015 20:58
Show Gist options
  • Save apisurfer/6e6846cc6539017b3b13 to your computer and use it in GitHub Desktop.
Save apisurfer/6e6846cc6539017b3b13 to your computer and use it in GitHub Desktop.
Write text line by line when user opens console
function isConsoleOpened() {
var threshold = 160;
return (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) ||
window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
}
var index = 0;
var tOut;
var text = [
'Good day neighbour!',
'Searching for more info?',
'You can just contact me on sth@example.net'
];
function write() {
if (index < text.length) {
console.log(text[index++]);
tOut = setTimeout(write, 2000);
} else {
// We got all the text out; now cleanup everything
clearTimeout(tOut);
window.onresize = undefined;
}
}
// DISCLAIMER: this should normally be debounced!
window.onresize = function(){
if(isConsoleOpened()) {
setTimeout(write, 1500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment