MediaWiki:Gadget-cache.js

Notă: După salvare, trebuie să treceți peste cache-ul browser-ului pentru a vedea modificările.

  • Mozilla, Google Chrome, Safari, Konqueror: țineți apăsat Shift în timp ce apăsați butonul Reload (sau apăsați Ctrl-Shift-R).
  • Internet Explorer: apăsați Ctrl-F5.
  • Opera: apăsați F5.
function addcache() {
    
    if (typeof no_external_cache !== "undefined" && no_external_cache) {
        return;
    }
 
   
    var links = $('.external');


    for (var i = 0, l = links.length; i < l; i++) {
        var current_link = links[i];
        var path = current_link.href || '#';
        if (path.indexOf("http://wikiwix.com/cache/") > -1 || 
            path.indexOf("http://web.archive.org/web/") > -1 || 
            path.indexOf("archive.is") > -1 || 
            path.indexOf("wikipedia.org") > -1 || 
            path.indexOf("wikimedia") > -1 || 
            path.indexOf("wikisource.org") > -1 || 
            path.indexOf("wiktionary.org") > -1 || 
            path.indexOf("wikiversity.org") > -1 || 
            path.indexOf("wikinews.org") > -1 || 
            path.indexOf("wikiquote.org") > -1 || 
            path.indexOf("wikibooks.org") > -1 || 
            path.indexOf("wikispecies.org") > -1 ||
            path.indexOf("toolserver.org") > -1 ||
            path.indexOf("wmflabs.org") > -1){ 
            continue;
        }
        var element_parent = current_link.parentNode;
        if ($(element_parent).hasClass("noarchive")) {
            continue;
        }
        //normally, plain links should be internal, so we should skip them 
        if ($(element_parent).hasClass("plainlinks")) {
            continue;
        }
        var page_title = getTextContent(current_link);
        var last = document.createElement("small");
        last.className = "cachelinks";
        last.appendChild(document.createTextNode("\u00a0("));
 
        var link = document.createElement("a");
        link.setAttribute("href", "http://archive.is/" + path);
        link.setAttribute("title", "Arhiva paginii " + page_title + " la Archive.is");

        var picture = document.createElement("img");
        picture.setAttribute("src", "//upload.wikimedia.org/wikipedia/commons/thumb/8/8f/Nuvola_mimetypes_java_jar.png/15px-Nuvola_mimetypes_java_jar.png");
        picture.setAttribute("alt", "Versiunea arhivată");
        link.appendChild(picture);
 
        last.appendChild(link);
        last.appendChild(document.createTextNode(")"));
 
        element_parent.insertBefore(last, current_link.nextSibling);
    }
}

// If we're on an article page or on an article talk page, run addcache
if (($.inArray(mw.config.get('wgNamespaceNumber'), [0 , 1]) !== -1) && mw.config.get('wgAction') == "view") {
    $( addcache );
}

//special test page
if (mw.config.get('wgPageName') == "Wikipedia:Arhivă_legături_externe/Teste") {
    $( addcache );
}

// Retrieves the actual text content of a node and its descendant nodes
// Copyright Harmen Christophe, http://openweb.eu.org/articles/validation_avancee, CC
function getTextContent(oNode) {
  if(!oNode) return null;
  if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;}
  switch (oNode.nodeType) {
    case 3: // TEXT_NODE
    case 4: // CDATA_SECTION_NODE
      return oNode.nodeValue;
    case 7: // PROCESSING_INSTRUCTION_NODE
    case 8: // COMMENT_NODE
      if (getTextContent.caller!=getTextContent) {
        return oNode.nodeValue;
      }
      break;
    case 9: // DOCUMENT_NODE
    case 10: // DOCUMENT_TYPE_NODE
    case 12: // NOTATION_NODE
      return null;
  }
  var _textContent = "";
  oNode = oNode.firstChild;
  while (oNode) {
    _textContent += getTextContent(oNode);
    oNode = oNode.nextSibling;
  }
  return _textContent;
}