Benutzer:Derschueler/monobook.js

Aus Wiktionary, dem freien Wörterbuch
 function doRedirect() {
  var dym = document.getElementById('Vorlage_Siehe_auch')
  var wiktDYMfrom= window.location.href.replace(/^(.+[&\?]rdfrom=([^&]+).*|.*)?$/,"$2");
 
 // REDIRECTED FROM
  if( window.location.href.indexOf('rdfrom=')!=-1 ) {
    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",wiktDYMfrom)+ '?redirect=no');
      lnk.className="new"; //As they are redlinks
      lnk.appendChild(document.createTextNode(decodeURIComponent(wiktDYMfrom)));
      tt.appendChild(lnk);
      div.appendChild(document.createTextNode("(Automatische Weiterleitung von "));
      div.appendChild(tt);
      div.appendChild(document.createTextNode(")"));
      insertPosition.parentNode.insertBefore(div,insertPosition.nextSibling);
      } else {
        alert('No insertposition');
      }
 
 // DID YOU MEAN
    }else{
      if( dym 
          && !window.location.href.match(/[&\?]redirect=no/)
          /* && (getCookie('WiktionaryDisableAutoRedirect') != 'true') */
        ) {
      var target = dym.getElementsByTagName('a')[1].title;
      var pagetitle = wgPageName;

      if( pagetitle != target 
          && ((pagetitle.toLowerCase().replace(/[^a-z]/g, "") == target.toLowerCase().replace(/[^a-z]/g, "")) && document.getElementById('noarticletext'))
          /* && pagetitle.search(/Editing /g) == -1
          && !(document.getElementById('contentSub') && document.getElementById('contentSub').innerHTML.indexOf("Redirected from")>=0) // does contentSub always exist */
        ) {
        document.location = wgArticlePath.replace("$1",encodeURIComponent(target.replace(/\ /g, "_")))
                          + '?rdfrom=' + encodeURIComponent(pagetitle.replace(/ /g,"_"));
      }
    }
  }
 }
 
 addOnloadHook(doRedirect);