Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Owner

tlrobinson commented Nov 30, 2010

Bookmarklet:

javascript:(function(){document.body.appendChild(document.createElement("script")).src="https://gist.github.com/raw/721253/f70c2bdeaed54d9907a448504ca7488287ab6d12/google-translate-drums.js"})()

Only tested on Safari and Chrome.

@tlrobinson

This comment has been minimized.

Owner

tlrobinson commented Nov 30, 2010

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