User:Robert Ullmann/monobook.js

/** * doRedirect will redirect if a did you mean box is found, and create a * "redirected from X" if a rdfrom is passed in the get parameters * The first half is an ugly workaround for Bugzilla:3339, :( * The second half is an ugly workaround for not having serverware support :( function doRedirect { var dym = document.getElementById('did-you-mean') var from= window.location.href.replace(/^(.+[&\?]rdfrom=([^&]+).*|.*)?$/,"$2"); // REDIRECTED FROM if(from){ var insertPosition= document.getElementById("siteSub"); var div=document.createElement("div"); if(insertPosition){ div.setAttribute("id","contentSub"); var tt=document.createElement('tt'); var lnk =document.createElement('a'); lnk.setAttribute("href",wgArticlePath.replace("$1",from)+ '?redirect=no'); lnk.appendChild(document.createTextNode(decodeURI(from))); tt.appendChild(lnk); div.appendChild(document.createTextNode("(Auto-redirected from "));      div.appendChild(tt);       div.appendChild(document.createTextNode(")")); insertPosition.parentNode.insertBefore(div,insertPosition.nextSibling); } // DID YOU MEAN }else{ if( dym           && !window.location.href.match(/[&\?]redirect=no/)           && (getCookie('WiktionaryDisableAutoRedirect') != 'true')         ) { var target = dym.firstChild.title; var pagetitle = document.getElementsByTagName('h1')[0].firstChild.nodeValue; if( pagetitle != target           && pagetitle.toLowerCase.replace(/[^a-z]/g, "") == target.toLowerCase.replace(/[^a-z]/g, "")           && pagetitle.search(/Editing /g) == -1           && !document.getElementById('contentSub').innerHTML.match("Redirected from") // does contentSub always exist         ) { document.location = wgArticlePath.replace("$1",encodeURIComponent(target.replace(/\ /g, "_"))) + '?rdfrom=' + encodeURIComponent(pagetitle.replace(/ /g,"_")) + '&redirect=no'; }    }   } }