Nota: Després de desar, heu de netejar la memòria cau del navegador per veure els canvis. En la majoria de navegadors amb Windows o Linux, premeu Ctrl+F5 o bé premeu Shift i cliqueu el botó "Actualitza" (Ctrl i "Actualitza" amb Internet Explorer). Vegeu més informació i instruccions per a cada navegador a Viquipèdia:Neteja de la memòria cau.

Array.prototype.copy = function() {
  return [].concat(this);
};
$.getReadyList = function()  {
  if(this.readyList != null)
    this.myreadylist =  this.readyList.copy();      
  return this.myreadylist;
};

ajaxwiki = {};

ajaxwiki.sessionstorage = function() {
  try {
    sessionStorage.setItem("abcdef", "a");
    sessionStorage.removeItem("abcdef");
    return true;
  } catch(e) {
    return false;
  }
}();
ajaxwiki.historyapi = !!(window.history && history.pushState);

ajaxwiki.maketitle = function (t) {
  return 'cached-'+t.replace(/[^\x00-\x80]/g,'-'); 
}
ajaxwiki.setLink = function (sel,tit) {
  sel.each(function () {
    $(this).attr("href",$(this).attr("href").replace(/(title=)[^\&]+/,"title="+tit));
  });
}
ajaxwiki.setLink2 = function (sel,tit) {
  sel.each(function () {
    $(this).attr("href",$(this).attr("href").replace(/\/[^$\/]+$/,"/"+tit));
  });
}
ajaxwiki.setContents = function (nc, tit) {
  $("#mw-content-text").html(nc);
  $("#firstHeading span").text(tit);
  document.title = tit+ ' - Viquipèdia';
  ajaxwiki.setLink($("#ca-edit a, #ca-history a, #ca-purge a, #t-print a, #t-permalink a"),tit);
  ajaxwiki.setLink2($("#t-whatlinkshere a, #t-recentchangeslinked a, #ca-purge a, #t-print a, #ca-move a"),tit);
  var readylist = $.getReadyList();
  $(readylist).each(function() {
    this();
  });
};
ajaxwiki.loadPage = function (tit,push,usecache) {
  if (typeof tit != "string") {
    var title = tit.attr("title");
    if (!title || tit.hasClass("external") ) { return false; }
  } else {
    var title = tit;
  }
  if (ajaxwiki.sessionstorage && usecache && sessionStorage.getItem(ajaxwiki.maketitle(title))) {
    ajaxwiki.setContents(sessionStorage.getItem(ajaxwiki.maketitle(title)),title);
  } else {
    $.get("//ca.wikipedia.org/w/index.php?title="+encodeURIComponent(title)+"&action=render",function(t) {
      ajaxwiki.setContents(t,title);
      if (ajaxwiki.sessionstorage) sessionStorage.setItem(ajaxwiki.maketitle(title),t);
    });
  }
  /*$.getJSON("http://ca.wikipedia.org/w/api.php?action=query&titles="+tit+"&prop=categories|langlinks&lllimit=500&cllimit=500&format=json",function (data) {
    
  });*/
  if (push) history.pushState({page:title},title,"/wiki/"+title);
  return true;
}
$(document).ready(function () {
 if (ajaxwiki.historyapi && localStorage.enabled) {
  // fem maca la URL
  if (mw.config.get('wgAction') == 'view' && location.href.indexOf('/w/index.php') != -1 && mw.config.get('wgIsArticle') && location.href.indexOf('oldid') == -1) {
    history.replaceState({page:wgPageName},wgPageName,"/wiki/"+wgPageName);
  }
  ajaxwiki.initial = mw.config.get('wgPageName');
  if (mw.config.get('wgIsArticle') && mw.config.get('wgAction') == 'view') {
    $("#bodyContent a").live("click",function (e) {
      var what = ajaxwiki.loadPage($(this),true,false);
      if (what) e.preventDefault();
    });
  }
  window.onpopstate = function (ev) {
    if (ev.state !== null) ajaxwiki.loadPage(ev.state.page,false,true);
    else ajaxwiki.loadPage(ajaxwiki.initial,false,true);
  };
 }
});