User:Atelaes/pronunciationCustomization.js

function decidePronunciationOutput {   var preference = getCookie('PronunciationPrefs'); if (preference == 'SAMPA') { changePronunciationOutput(SAMPA, 'http://en.wikipedia.org/wiki/SAMPA_chart_for_English', 'w:SAMPA_chart_for_English', 'SAMPA'); } } function changePronunciationOutput(whichArray, newLink, newFloat, newName) {  for(       var i=0;       PronunciationSection = document.getElementsByTagName("span")[i];       i++      ) { if (PronunciationSection.className == 'IPA' && PronunciationSection.parentNode.nodeName == 'LI') { var IpaPronunciation = PronunciationSection.innerHTML; var MinusOne = IpaPronunciation.length - 1; var NewPronunciation = IpaPronunciation.substring(0,1) + IPAconvert(IpaPronunciation.substring(1, MinusOne), whichArray) + IpaPronunciation.substring(MinusOne); PronunciationSection.innerHTML = NewPronunciation; if (whichArray == SAMPA) { PronunciationSection.setAttribute('style', "font-family: monospace"); }           var ToTheLeft = PronunciationSection.previousSibling.previousSibling; if (ToTheLeft.tagName == 'A') { ToTheLeft.setAttribute('href', newLink); ToTheLeft.setAttribute('title', newFloat); ToTheLeft.innerHTML = newName; }           }         } }

var SAMPA = { // http://fr.wiktionary.org/w/index.php?title=MediaWiki:Monobook.js&oldid=3006324 'a':"a", 'b':"b", 'ɓ':"b_<", 'c':"c", 'd':"d", 'ɖ':"d`", 'ɗ':"d_<", 'e':"e", 'f':"f", 'ɡ':"g", 'ɠ':"g_<", 'h':"h", 'ɦ':"h\\", 'i':"i", 'j':"j", 'ʝ':"j\\", 'k':"k", 'l':"l", 'ɭ':"l`", 'ɺ':"l\\", 'm':"m", 'n':"n", 'ɳ':"n`", 'o':"o", 'p':"p", 'ɸ':"p\\", 'q':"q", 'ʠ':"q_<", 'r':"r", 'ɽ':"r`", 'ɹ':"r\\", 'ɻ':"r\\`", 'ɼ':"r\\_r", 's':"s", 'ʂ':"s`", 'ɕ':"s\\", 't':"t", 'ʈ':"t`", 'u':"u", 'v':"v", 'ʋ':"P", 'w':"w", 'x':"x", 'ɧ':"x\\", 'y':"y", 'z':"z", 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", '̥':"_0", '˒':"_0", '̊':"_0", '̩':"=", '̍':"=", 'ʼ':"_>", 'ˀ':"_>", 'ˤ':"_?\\", 'ˆ':"_\\", '̯':"_^", '̚':"_}", '˞':"`", '̢':"`", '̃':"~", '̨':"~", '̘':"_A", '̺':"_a", '̏':"_B", 'ˏ':"_B_L", '̜':"_c", '˓':"_c", '̪':"_d", '̴':"_e", '↘':"", '̂':"_F", 'ˠ':"_G", '́':"_H", '˥':"_T", 'ʰ':"_h", '̴':"_e", '̰':"_k", '̀':"_L", 'ˎ':"_L_B", 'ˡ':"_l", '̄':"_M", '̻':"_m", '̼':"_N", 'ⁿ':"_n", '̹':"_O", '̞':"_o", '˕':"_o", '̙':"_q", '↗':"_R", '̌':"_R", '̝':"_r", '˔':"_r", '̋':"_T", 'ˉ':"_T", '̤':"_t", 'ʱ':"_t", '̬':"_v", 'ʷ':"_w", '̫':"_w", '̆':"_X", '̽':"_x", 'ʤ':"dZ", 'ʣ':"dz", 'ʥ':"dz\\", 'ʧ':"tS", 'ʨ':"ts\\", 'ʦ':"ts", '﻿͡':")", '˩﻿':"_B", '˦﻿':"_H", '˨﻿':"_L", '˧':"_M", '˩﻿':"_B", 'ʳ':"_r", 'ʶ':"_R", 'ʴ':"_r\\", 'ʵ':"_r\\`", 'ˢ':"_s", 'ˣ':"_x", 'ʸ':"_y"} /** * Simple minded Transliterator, more of a proof of concept than anything particularly useful atm * function IPAconvert(input, map){ var output ='';  for(var s=0;s= 6) {        //We need to check up to six spaces ahead,      var testLength = 6;                 //as some of the characters are six bytes.      }                                   //However, only do so if there are at least    else {                                //six bytes left.      var testLength = (input.length - s);      }    for(var e=testLength;e>0;e--){        var c = map[input.substr(s,e)];     //  Find out what the dictionary says it is      if(typeof(c) != 'undefined'){       //  See if the dictionary knew what it was talking about output+=c;                       //  If so add the match and move forward a notch }     }    }  return output;                          //we're done }

function setupPronCus { if (wgPageName == "User:Atelaes/Customization/Pronunciation") { var preference = getCookie('PronunciationPrefs'); var span = document.getElementById('formhook'); var form = document.createElement('form'); temp = document.createElement('input'); temp.setAttribute('type', 'radio'); temp.setAttribute('name', 'pronunciation'); temp.setAttribute('value', 'IPA'); temp.setAttribute('onClick', 'setCookie("PronunciationPrefs", "IPA")'); if (preference == 'IPA') { temp.setAttribute('checked', 'checked'); }  form.appendChild(temp); temp = document.createElement('a'); temp.setAttribute('href', 'http://en.wikipedia.org/wiki/IPA'); temp.innerHTML = 'IPA'; form.appendChild(temp); temp = document.createTextNode(': The standard format for linguistics and most robust of the options. This is the default system used on Wiktionary.'); form.appendChild(temp); temp = document.createElement('br'); form.appendChild(temp); temp = document.createElement('input'); temp.setAttribute('type', 'radio'); temp.setAttribute('name', 'pronunciation'); temp.setAttribute('value', 'SAMPA'); temp.setAttribute('onClick', 'setCookie("PronunciationPrefs", "SAMPA")'); if (preference == 'SAMPA') { temp.setAttribute('checked', 'checked'); }  form.appendChild(temp); temp = document.createElement('a'); temp.setAttribute('href', 'http://en.wikipedia.org/wiki/SAMPA'); temp.innerHTML = 'SAMPA'; form.appendChild(temp); temp = document.createTextNode(': A format based on IPA, but using only ASCII characters, making it easier for computers with limited fonts to display.'); form.appendChild(temp); temp = document.createElement('br'); form.appendChild(temp); temp = document.createElement('input'); temp.setAttribute('type', 'radio'); temp.setAttribute('name', 'pronunciation'); temp.setAttribute('value', 'enPR'); temp.setAttribute('onClick', 'alert("I told you not to click this!")'); if (preference == 'enPR') { temp.setAttribute('checked', 'checked'); }  form.appendChild(temp); temp = document.createElement('a'); temp.setAttribute('href', 'http://en.wiktionary.org/wiki/Wiktionary:English_pronunciation_key'); temp.innerHTML = 'enPR'; form.appendChild(temp); temp = document.createTextNode(": A home-brewed system, largely based on the American Heritage Dictionary's system. Uses characters intended to be intuitive for English speakers.  Warning: This system only encodes sounds made in English.  Sounds which do not occur in English will be matched to the closest English sound."); form.appendChild(temp); temp = document.createElement('br'); form.appendChild(temp); temp = document.createElement('input'); temp.setAttribute('type', 'radio'); temp.setAttribute('name', 'pronunciation'); temp.setAttribute('value', 'Shavian'); temp.setAttribute('onClick', 'alert("I told you not to click this!")'); if (preference == 'Shavian') { temp.setAttribute('checked', 'checked'); }  form.appendChild(temp); temp = document.createElement('a'); temp.setAttribute('href', 'http://en.wikipedia.org/wiki/Shavian_alphabet'); temp.innerHTML = 'Shavian'; form.appendChild(temp); temp = document.createTextNode(': Invented by George Bernard Shaw, this system aims to use characters whose shape meaningfully maps to sound relationships. Suffers from similar shortcomings to enPR.'); form.appendChild(temp) temp = document.createElement('br'); form.appendChild(temp); span.appendChild(form); } }

$( setupPronCus ); $( decidePronunciationOutput );