Skip to content

Instantly share code, notes, and snippets.

@ulybu
Last active December 7, 2015 13:21
Show Gist options
  • Save ulybu/0d410625af30cc57479e to your computer and use it in GitHub Desktop.
Save ulybu/0d410625af30cc57479e to your computer and use it in GitHub Desktop.
Duolinguo speech shortcut

What is it

This bookmarklet will add a key shortcut to lauch the speech on duolinguo.com This way you can keep your hand on the keyboard without having to lick on the speaker button to hear the pronunciation By default it set ctrl as the keyboard but you're free to set the key you want (see install procedure)

Bookmarklet ?

Bookmarklets are tiny programs stored inside bookmarks. Similar to add-ons, extensions, and user scripts, they add new tools to your web browser. Bookmarklets are shared on web pages as web links. You don't actually "install" a bookmarklet. You simply add it to your bookmarks. It just sits there patiently until you want to use it.

Install (default)

  1. Copy the content of shortcutToSpeech.js (click RAW then hit ctrl+a then ctrl+c)
  2. Go to http://ted.mielczarek.org/code/mozilla/bookmarklet.html
  3. Read instructions
  4. Put a name e.g. duolinguo speech, paste, crunch
  5. Drag the generated bookmarklet to your bookmark bar

Install (setting your own shortcut)

  1. Go to http://keycode.info/ and get the key code of the new shortcut you wish to set
  2. Copying the content of shortcutToSpeech.js in your text editor
  3. Click the RAW button (top of the file)
  4. crtl+A then crtl+C
  5. Look for the line with if(event.keyCode ===...
  6. Replace the numeric value with the keycode from step 1
  7. Jump to the step 2 of Install (default)

Note: If your bookmark bar is hidden, google how to display it..

Usage

  • Go to duolinguo.com
  • Click on the bookmarklet
  • Whenever the speech is available, hit ctrl (or the shortcut you set) to hear the speech

Note: You will have to click on the bookmarket everytime you refresh the page

window.addEventListener('keydown',function(event) {
if(event.keyCode === 17 ) { // ctrl
var audioButton = document.querySelector("[id|='speaker-audio']");
fireEvent(audioButton,'click');
console.log("Played the speech.","keyCode:",event.keyCode);
}
});
function fireEvent (el,etype){
var evObj = new CustomEvent(etype, {bubbles:true, cancelable:false});
el.dispatchEvent(evObj);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment