Skip to content

Instantly share code, notes, and snippets.

@peterjmag
Created August 24, 2014 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjmag/489364ca58330c348c33 to your computer and use it in GitHub Desktop.
Save peterjmag/489364ca58330c348c33 to your computer and use it in GitHub Desktop.
/*
* Visit http://benzguo.com/bayan/ and paste this in your console.
*
* Originally from https://news.ycombinator.com/item?id=8217872, adapted
* to handle non-alpha characters like commas and semicolons.
*/
// SETTINGS
// var input = "rsa ecde srgu yhgr bv rsa ecde srgu yhgr bv hybtg ser erv";
// input += " hybtg iii r hybtg ser erv tvr rrr rvgres rrr rvg rrr rvgres ";
// input += "ggg rgh grs sxebbe cuuuhbgres grs sxebbe cbbbgvrsai";
var input = "uyvyu,pl,ynuuupl,kmk,,uyvuyvyu,pl,ynuuupl,kmk,,uyvppp;[[;plp;;;pl,kmk,ynuu,,,kmmml;pl,,kuu,lp;[,lp;l,";
var TIME_INTERVAL = 300;
// Add jquery
var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
var KeyboardJS = require('lib/keyboard');
function play () {
// Sound array setup
var soundArray = [];
var down = $.Event("keydown");
var up = $.Event("keyup");
input = ' ' + input; // hack
for (var i = 0; i < input.length; ++i) {
var code = KeyboardJS.key.code(input.charAt(i));
if (code) {
soundArray.push(code);
} else {
soundArray.push(32);
}
}
// Start sound
var index = 0;
function playSound () {
up.which = soundArray[index];
$("body").trigger(up);
++index;
down.which = soundArray[index];
$("body").trigger(down);
// // is there another?
if (index < soundArray.length) {
setTimeout(playSound, TIME_INTERVAL);
}
}
playSound();
}
(function loadjQuery () {
if (typeof jQuery === 'undefined') {
setTimeout(loadjQuery, 100);
} else {
play();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment