Skip to content

Instantly share code, notes, and snippets.

@asford
Last active December 29, 2015 08:39
Show Gist options
  • Save asford/7644437 to your computer and use it in GitHub Desktop.
Save asford/7644437 to your computer and use it in GitHub Desktop.
Code review, because brothers love sisters.
word_sub = {
"cybernetic" : "cyber",
"lived" : "living",
"relations" : "relation",
"changing" : "change",
"changes" : "change",
"womens" : "women",
"women's" : "women",
"movements" : "movement",
"discovered" : "discover",
"rests" : "rest",
"counts" : "count",
"object" : "thing",
"constructed" : "construction"
};
function spoken (text,index) {
console.log(index);
text=text.replace(/[-\',.]/g,"");
var word = $.trim(text.toString());
var audioElement = document.createElement('audio');
if(word in word_sub)
{
word = word_sub[word];
}
if(word != '') {
audioElement.setAttribute('src','https://ssl.gstatic.com/dictionary/static/sounds/de/0/' + word + '.mp3');
audioElement.setAttribute('autoplay','autoplay');
}
// Best to make indentation level match scope of control flow.
//TODO Globals in use?
doomed=true;
count=0;
// while (doomed) {
// audioElement.addEventListener("ended",function () {doomed=false;});
// count++;
// if (count > 50) {doomed=false;}
// console.log(count);
// }
}
$(document).ready(function() {
$('p').click(function(e) {
var range = document.getSelection();
var word = $.trim(range.toString());
var audioElement = document.createElement('audio');
if(word in word_sub)
{
word = word_sub[word];
}
if(word != '') {
audioElement.setAttribute('src','https://ssl.gstatic.com/dictionary/static/sounds/de/0/' + word + '.mp3');
audioElement.setAttribute('autoplay','autoplay');
}
range.collapse();
e.stopPropagation();
});
});
$(document).ready(function(){
$('span').click(function(){
$(this).addClass("redact");
});
$('span').dblclick(function(){
$(this).removeClass("redact");
});
$("img").click(function(){
$("span").not(".redact").each(function(index) {
var newword = $(this).text();
delay = 500*index;
console.log(delay);
setTimeout(function () {spoken(newword,index)} ,delay);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment