User:Splarka/cascadeskinlang.js

// // ***************************************************************** // Cascading useskin/uselang parameter preservation // ***************************************************************** /* This script simply iterates through all links and forms and appends any uselang/useskin parameters in the current URL.

For links, it only grabs local that aren't a null anchor, ignoring external and javascript.

For forms, it ignores external and javascript too.

Known issues: * Local page anchors may cause page to reload. * Some forms result in a 301 redirect (will break cascading).

if((queryString('uselang'))||(queryString('useskin'))) addOnloadHook(cascadeSkinLang)

function cascadeSkinLang { var links = document.getElementsByTagName('a'); var forms = document.getElementsByTagName('form'); var parmchr; var parm;

if(queryString('uselang')) { parm = 'uselang=' + queryString('uselang'); } if(queryString('useskin')) { if(queryString('uselang')) { parm += '&useskin=' + queryString('useskin'); } else { parm = 'useskin=' + queryString('useskin'); } }

for(var i=0;i<links.length;i++) { if((links[i].href.indexOf(wgServer)==0)&&(links[i].href!=wgServer+'/#')) { parmchr = (links[i].href.indexOf('?')==-1) ? '?' : '&';     if(links[i].href.indexOf('#')==-1) { links[i].href += parmchr + parm; } else { links[i].href = links[i].href.substring(0,links[i].href.indexOf('#')) + parmchr + parm + links[i].href.substring(links[i].href.indexOf('#')); }   }  }

for(var i=0;i<forms.length;i++) { if((forms[i].action.indexOf('http://')==-1)&&(forms[i].action.indexOf('avascript:')==-1)) { parmchr = (forms[i].action.indexOf('?')==-1) ? '?' : '&';     forms[i].action += parmchr + parm; } } }

function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }

//