User:Atelaes/TargetedTranslations.js

function clarifyTransTable {  var targetLanguages = getCookie('TargetedTransPrefs'); targetLanguages = targetLanguages.split(';'); var targetLanguage; var spacer = ' - ' var separator = '; ' var targetTrans; var tables = document.getElementsByTagName('table'); var lis; var li; var dls; var dl; var dd; var clone var NavFrame; var NavHead; var temp; function isRight(node) { for (var l = 0; l < targetLanguages.length; l++) { targetLanguage = targetLanguages[l]; if (node.childNodes[0].nodeName == '#text') { if (node.innerHTML.indexOf(targetLanguage + ':') == 0) { return true; }           }         // Weed out two names which, as subheadings, should refer to scripts, not languages. else if (node.nodeName.toUpperCase == 'DD') { if (targetLanguage == 'Hebrew' || targetLanguage == 'Latin') { return false; }           }         else if (node.childNodes[0].nodeName.toUpperCase == 'A') { if (node.childNodes[0].innerHTML == targetLanguage) { return true; }           }         }      }   for (var i=0; i -1) { targetTrans = document.createElement('span'); lis = tables[i].getElementsByTagName('li'); for (var j=0; j<lis.length; j++) { li = lis[j]; dls = li.getElementsByTagName('dl'); //If we have subelements in the li.... if (dls.length == 1) { dds = dls[0].getElementsByTagName('dd'); if (isRight(li)) { temp = document.createElement('span'); for (var k=0; k<li.childNodes.length; k++) { if (li.childNodes[k].nodeName != 'DL') { clone = li.childNodes[k].cloneNode(true); temp.appendChild(clone); }                 }               if (targetTrans.innerHTML != '') { targetTrans.appendChild(document.createTextNode(separator)); }              targetTrans.appendChild(temp); }           for (var k=0; k < dds.length; k++) { if (isRight(dds[k])) { temp = document.createElement('span'); temp.innerHTML = dds[k].innerHTML; if (targetTrans.innerHTML != '') { targetTrans.appendChild(document.createTextNode(separator)); }                 targetTrans.appendChild(temp); }              }            }         else if (isRight(li)){ temp = document.createElement('span'); temp.innerHTML = li.innerHTML; if (targetTrans.innerHTML != '') { targetTrans.appendChild(document.createTextNode(separator)); }           targetTrans.appendChild(temp); }        }      NavHead = tables[i].parentNode.parentNode.getElementsByTagName('div')[0]; if (targetLanguages.length == 1 && targetLanguages[0] == '') { NavHead.appendChild(document.createTextNode(spacer)); NavHead.appendChild(newNode('a', 'Select your targeted language', {href: '/wiki/User:Atelaes/Customization/Translations'})); }        else if (targetTrans.innerHTML) { NavHead.appendChild(document.createTextNode(spacer)); NavHead.appendChild(targetTrans); }        }      }   } function setupTransCus {  if (wgPageName == 'User:Atelaes/Customization/Translations') { var preference = getCookie('TargetedTransPrefs'); var span = document.getElementById('formhook'); var form = newNode('form', {        name: 'transform'         }); var temp = document.createTextNode('Language: ') form.appendChild(temp); var temp = newNode('input', {        type: 'text',         name: 'blank'         }); form.appendChild(temp); var temp = newNode('input', {        type: 'submit',         value: 'Add',         onclick: 'addTargetTransCookie;'         }); form.appendChild(temp); span.appendChild(form); var list = newNode('ul', {        id : 'currentLanguages'         }); span.appendChild(list); targetTransRefreshList var brokenMessage = document.getElementById('broken_message'); brokenMessage.style.display = 'none'; }  }

function targetTransRefreshList {  var targetLanguages = getCookie('TargetedTransPrefs'); targetLanguages = targetLanguages.split(';'); var ul = document.getElementById('currentLanguages'); ul.innerHTML = ''; var li; var button; for (var x=0; x < targetLanguages.length; x++) { li = newNode('li', targetLanguages[x] + ' '); button = newNode('input', {        type: 'submit',         value: 'Remove',         onclick: 'removeTargetTransCookie(' + x + ')'         }) li.appendChild(button); ul.appendChild(li); }  }

function addTargetTransCookie {  var input = document.transform.blank.value; var targetLanguages = getCookie('TargetedTransPrefs'); if (targetLanguages != '') { targetLanguages += ';'; }  targetLanguages += input; setCookie("TargetedTransPrefs", targetLanguages); targetTransRefreshList; } function removeTargetTransCookie(number) {  var targetLanguages = getCookie('TargetedTransPrefs'); targetLanguages = targetLanguages.split(';'); targetLanguages.splice(number, 1) targetLanguages = targetLanguages.join(';'); setCookie("TargetedTransPrefs", targetLanguages); targetTransRefreshList; }

$( clarifyTransTable ); $( setupTransCus );