MediaWiki:DoRedirect.js

De Wikcionario, el diccionario libre

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
 
 //----------------------------------------------------------------------------------------
 //----------------------------------------------------------------------------------------
 // Sjálf-tilvísað frá ...
 //frá [[en:MediaWiki:Common.js]] autor: [[:en:User:Connel MacKenzie]], con ayuda de: [[:de:User:Melancholie]]
 
function doRedirect() {
  var dym = document.getElementById('quieres-buscar')
  var wiktDYMfrom= window.location.href.replace(/^(.+[&\?]rdfrom=([^&]+).*|.*)?$/,"$2");
  var wiktRndLang= window.location.href.replace(/^(.+[&\?]rndLang=([^&]+).*|.*)?$/,"$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",mw.config.get('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("(Auto-redirigido desde "));
      div.appendChild(tt);
      div.appendChild(document.createTextNode(")"));
      insertPosition.parentNode.insertBefore(div,insertPosition.nextSibling);
      } else {
        alert('No insertposition');
      }
 
 // DID YOU MEAN - Quizás quieres buscar...
    }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, "")
          && mw.config.get('wgAction') != "edit"
          && !(document.getElementById('contentSub') && document.getElementById('contentSub').innerHTML.indexOf("Redirected from")>=0) // does contentSub always exist
        ) {
        document.location = mw.config.get('wgArticlePath').replace("$1",encodeURIComponent(target.replace(/\ /g, "_")))
                          + '?rdfrom=' + encodeURIComponent(pagetitle.replace(/ /g,"_"));
      }
    }
  }
}
 
$(doRedirect);