Jump to content

User:Rob*/monobook.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function externISBN() {
  for (var i = 0; i < document.links.length; i++) 
    {       
         var ln = document.links[i].href.match(/isbn=(.*)/);
         if (ln) {
           document.links[i].href='http://www.amazon.com/exec/obidos/ASIN/'+RegExp.$1;
         }
    }

}

var IPAkey = new Array();
IPAkey["aɪ"] = "shY";
IPAkey["aʊ"] = "chOW";
IPAkey["ɑ"] = "shAH";
IPAkey["ɒ"] = "shOd";
IPAkey["æ"] = "shAd";
IPAkey["ɔ"] = "shAW";
IPAkey["ɔɪ"] = "chOY";
IPAkey["dʒ"] = "Jig";
IPAkey["ð"] = "THy";
IPAkey["ə"] = "About";
IPAkey["ɚ"] = "winnER";
IPAkey["ɛ"] = "shEd";
IPAkey["ɝ"] = "shIRt";
IPAkey["eɪ"] = "shAde";
IPAkey["ɡ"] = "Goat";
IPAkey["i"] = "shE";
IPAkey["ɪ"] = "bIg";
IPAkey["j"] = "Yes";
IPAkey["ŋ"] = "briNG";
IPAkey["oʊ"] = "nO";
IPAkey["əʊ"] = "nO";
IPAkey["ɹ"] = "Red";
IPAkey["ʃ"] = "SHeep";
IPAkey["tʃ"] = "CHoose";
IPAkey["θ"] = "THink";
IPAkey["ʊ"] = "shOOk";
IPAkey["u"] = "shOO";
IPAkey["ʌ"] = "shUn";
IPAkey["ʒ"] = "beiGE";

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

        var str = 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 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 += getInnerText(cs[i]);
                break;
            case 3: //TEXT_NODE
                str += cs[i].nodeValue;
                break;
        }
    }
    return str;
}

addOnloadHook(IPAkeys);