User:Nohat/IPA.js

var IPAkey = new Array; IPAkey["aɪ"] = "crY"; IPAkey["aʊ"] = "nOW"; IPAkey["ɑ"] = "spA"; IPAkey["ɑɹ"] = "cAR"; IPAkey["ɒ"] = "rOd"; IPAkey["æ"] = "bAd"; IPAkey["ɔ"] = "lAW"; IPAkey["ɔɹ"] = "nORth"; IPAkey["ɔɪ"] = "bOY"; IPAkey["dʒ"] = "riDGe"; IPAkey["ð"] = "THis"; IPAkey["ə"] = "About"; IPAkey["ɚ"] = "winnER"; IPAkey["ɛ"] = "bEd"; IPAkey["ɝ"] = "shIRt"; IPAkey["eɪ"] = "mAId"; IPAkey["ɡ"] = "piG"; IPAkey["i"] = "shE"; IPAkey["ɪ"] = "bIg"; IPAkey["j"] = "Yes"; IPAkey["ŋ"] = "riNG"; IPAkey["oʊ"] = "sOAp"; IPAkey["əʊ"] = "sOAp"; IPAkey["ɹ"] = "Red"; IPAkey["ʃ"] = "SHoe"; IPAkey["tʃ"] = "CHoose"; IPAkey["θ"] = "THing"; IPAkey["ʊ"] = "bOOk"; IPAkey["ʊɹ"] = "tOUR"; IPAkey["u"] = "fOOd"; IPAkey["ju"] = "cUE"; IPAkey["ʌ"] = "rUn"; IPAkey["ʒ"] = "beiGE";

function IPAkeys { var ipaSpans = getElementsByClassName(document, "span", "IPA"); for (var i = 0; i < ipaSpans.length ; i++) { var span = ipaSpans[i];

var str = IPA_getInnerText(span);

var helpText = ''; var foundMatches = new Array;

for (var j = 0; j < str.length; j++) { var one = str.charAt(j); var two = one + str.charAt(j+1); var IPA_match = ''; if (IPAkey[two]) { IPA_match = two; j++; } else if (IPAkey[one]) { IPA_match = one; }

if (IPA_match && !foundMatches[IPA_match] && IPAkey[IPA_match]) { foundMatches[IPA_match] = 1; helpText += '/' + IPA_match + '/ ' + IPAkey[IPA_match] + ';'; }       }        if (helpText != '') { span.title += ': ' + helpText; }   } }

function IPA_getInnerText(el) { if (typeof el == "string") return el; if (typeof el == "undefined") { return el }; if (el.innerText) return el.innerText; // Not needed but it is faster var str = "";

var cs = el.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { switch (cs[i].nodeType) { case 1: //ELEMENT_NODE str += IPA_getInnerText(cs[i]); break; case 3: //TEXT_NODE str += cs[i].nodeValue; break; }   }    return str; }

$(IPAkeys);