MediaWiki:Gadget-HistoryNumDiff.js

/* _____________________________________________________________________________ * |                                                                             | * |                    === 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 MediaWiki:Gadget-HistoryNumDiff. * * Author: The RedBurn * */ function getNumFromString (i,eltsByTag) { var regString = /\((.*) bytes?\)/; var resultString; var string = eltsByTag.item(i).innerHTML; var separator = /[^0-9]/g; var empty = "(empty)"; if(mw.config.get( 'wgUserLanguage' ) == "fr") {   regString = /\((.*) octets?\)/; empty = "(vide)"; } if(string==empty) { string=0; } else { resultString= regString.exec(string); string = resultString[1].replace(separator,""); string = parseInt(string, 10); } return string; } function makeNumDiff { var string; var resultPrevString = 0; // précédent dans l'ordre chronologique var resultNextString = 0; var className; var lastI = 0; var i = 0; var eltsByTag = document.getElementsByTagName("span"); var length = eltsByTag.length; while(i0) { 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 = " " + "(" + string + ")" + " "; } 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); }