MediaWiki:Gadget-HistoryNumDiff.js

Origem: Wikilivros, livros abertos por um mundo aberto.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === WARNING: GLOBAL GADGET FILE ===                      |
 * |                  Changes to this page affect many users.                    |
 * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
 * |_____________________________________________________________________________|
 *
 * Imported from the January 17, 2011 version at [[fr:MediaWiki:Gadget-HistoryNumDiff.js]]
 *
 * Shows the number of characters added or removed, rather than the size of the revision.
 * This format is like the one used by the Watchlist and Recent Changes. 
 * 
 * See [[w:en:MediaWiki:Gadget-HistoryNumDiff]].
 *
 * Author: The RedBurn
 *
 */
 
function getNumFromString (i,eltsByTag) {
    var resultString,
        string = eltsByTag.item(i).innerHTML,
        separator = /[^0-9]/g,
        regString = {
            'en' : /\((.*) bytes?\)/,
            'fr' : /\((.*) octets?\)/
        },
        empty = {
            'en' : '(empty)',
            'fr' : '(vide)',
            'pt' : '(vazia)',
            'pt-br' : '(vazio)'
        };
  if( string == ( empty[ mw.config.get( 'wgUserLanguage' ) ] || empty.en ) ) {
    string=0;
  } else {
    resultString= ( regString[ mw.config.get( 'wgUserLanguage' ) ] || regString.en ).exec(string);
    string = resultString[1].replace(separator,"");
    string = parseInt(string, 10);
  }
  return string;
}
 
function makeNumDiff() {
  var   string,
        resultPrevString = 0, // précédent dans l'ordre chronologique
        resultNextString = 0,
        className,
        lastI = 0,
        i = 0,
        eltsByTag = document.getElementsByTagName("span"),
        length = eltsByTag.length;
 
  while(i<length && eltsByTag.item(i).className != "history-size") {
    i++;
  }
  if(i<length) {
    resultNextString = getNumFromString(i,eltsByTag);
    lastI = i;
    i++;
 
    while (i<length) {
      if (eltsByTag.item(i).className == "history-size"){
 
        resultPrevString = getNumFromString(i,eltsByTag);
 
        string = resultNextString - resultPrevString;
 
        if (string>0) {
          className = "mw-plusminus-pos";
          string = "+" + string;
        }
        else {
          if (string<0) {
            className = "mw-plusminus-neg";
          } else {
            className = "mw-plusminus-null";
          }
        }
        if (string<-500 || string>500) {
          string = "<strong>" + "(" + string + ")" + "</strong>";
        } else {
          string = "(" + string + ")";
        }
        eltsByTag.item(lastI).innerHTML = string ;
        eltsByTag.item(lastI).className = className;
 
        resultNextString = resultPrevString;
        lastI = i;
      }
      i++;
    }
  }
}
if(mw.config.get( 'wgAction' ) && mw.config.get( 'wgAction' ) == "history") {
  $(makeNumDiff);
}

// [[Categoria:Gadgets|HistoryNumDiff.js]]
// [[Categoria:Scripts do Wikilivros|HistoryNumDiff.js]]