Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created January 13, 2015 15:24
Show Gist options
  • Save halfdan/be037a9c37c50e3924a9 to your computer and use it in GitHub Desktop.
Save halfdan/be037a9c37c50e3924a9 to your computer and use it in GitHub Desktop.
Duolingo Google TTS
// ==UserScript==
// @name LingoGoogleTTS
// @version 0.1
// @description Technical demo, changed by TheLagom!
// @match https://www.duolingo.com/*
// ==/UserScript==
(function($) {
if (typeof duo != 'undefined' && typeof $.tts_super == 'undefined') {
var ttsBase = duo.tts_base_url,
ttsPath = duo.tts_path;
$.fn.tts_super = $.fn.tts;
$.fn.tts = function(d) {
var language = d.language;
duo.tts_base_url = "http://translate.google.com/translate_tts?ie=UTF-8&";
if (d.tts_type === "sentence" && typeof d.sentence !== 'undefined') {
var quoted_text = encodeURIComponent(d.sentence.replace("/", " "));
if(d.language == 'dn')
{
d.language = 'nl';
}
duo.tts_path = 'tl=' + d.language + '&q=' + quoted_text;
} else {
// Use default for tokens (single words)
duo.tts_base_url = ttsBase;
duo.tts_path = ttsPath;
}
return this.each(function() {
$(this).tts_super(d);
});
}
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment