User:AT/langbox.js

From Guild Wars Wiki
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
 var node = document.getElementById(portlet);
 if ( !node ) return null;
 node = node.getElementsByTagName( "ul" )[0];
 if ( !node ) return null;
 var link = document.createElement( "a" );
 link.appendChild( document.createTextNode( text ) );
 link.href = href;
 var item = document.createElement( "li" );
 item.appendChild( link );
 if ( id ) item.id = id;
 if ( accesskey ) {
    link.setAttribute( "accesskey", accesskey );
    tooltip += " ["+accesskey+"]";
 }
 if ( tooltip ) {
    link.setAttribute( "title", tooltip );
 }
 if ( accesskey && tooltip ) {
    updateTooltipAccessKeys( new Array( link ) );
 }
 if ( nextnode && nextnode.parentNode == node )
    node.insertBefore( item, nextnode );
 else
    node.appendChild( item );  // IE compatibility (?)
 return item;
 }

function addLangSite( name, lang) { 
 var url = 'http://translate.google.com/translate?u=wiki.guildwars.com%2Fwiki%2F' + wgCanonicalNamespace;
 if(wgCanonicalNamespace != '') {
   url +='%3A'
 }
 url += wgTitle + '&hl=en&ie=UTF8&sl=en&tl=' +  lang;
 addPortletLink('p-lang', url, name, 'lang-link', name, ''); 
}

function langportlet() {
 document.getElementById('p-tb').innerHTML += '</div>'+'<p>'+
 '<div id=p-lang>'+
 '<h5>other languages</h5>'+
 '<div class=pBody><ul>'+
 '</ul></div></div>';
}


function langbox() {
  langportlet();
  addLangSite('Français', 'fr');
  addLangSite('Deutsch', 'de');
  addLangSite('Español', 'es');
  addLangSite('Italiano', 'it');
  addLangSite('Nederlands', 'nl');
  addLangSite('中文(简体)', 'zh');
  addLangSite('中文(繁體)', 'zh-TW');
  if ( typeof( userLanguages ) != 'undefined' )
     userLanguages();
}

addOnloadHook(langbox);