Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created November 30, 2010 06:19
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tlrobinson/721253 to your computer and use it in GitHub Desktop.
Save tlrobinson/721253 to your computer and use it in GitHub Desktop.
A drum machine for the German Google Translate. See instructions in comments below.
(function() {
// Notes from http://news.ycombinator.com/item?id=1952531
var notes = {
"suspended cymbal":"zk",
"snare":"bschk",
"brush":"pv",
"bass":"bk",
"flam1":"tk",
"roll tap":"vk",
"flam2":"kt",
"flam tap":"kttp",
"hi hat tap":"krp",
"short roll":"pv",
"better hi hat":"th",
"instant rimshot":"thp, ds"
};
function clickListen() {
var e = document.createEvent('MouseEvents');
e.initMouseEvent("click", true, true, window, 1, 12, 345, 7, 220, false, false, true, false, 0, null );
document.getElementsByClassName("gt-icon-listen-off")[0].dispatchEvent(e);
}
function playNote(event) {
var source = document.getElementById("source");
if (source.value === event.target.note) {
clickListen();
return;
}
source.value = event.target.note;
var state = 0;
var result_box = document.getElementById("result_box");
var timer = window.setInterval(function() {
if (state === 0 && result_box.childNodes[1] && result_box.childNodes[1].data === "...") {
state = 1;
} else if (state === 1 && (!result_box.childNodes[1] || !result_box.childNodes[1].data)) {
clickListen();
window.clearInterval(timer);
}
});
}
for (var name in notes) {
if (notes.hasOwnProperty(name)) {
var button = document.createElement("input");
button.type = "button";
button.value = name;
button.note = notes[name];
button.onclick = playNote;
document.body.appendChild(button);
}
}
})();
@tlrobinson
Copy link
Author

Instructions:

  1. Load Google Translate (German to German): http://translate.google.com/#de|de|pv
  2. Load the bookmarklet in the above comment in the URL bar.
  3. Click the new buttons at the bottom of the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment