User:Sid/HistDiff



This is a little script I quickly wrote when I started to lose track of all the censorship on cp:Talk:PNAS Response to Letter. I could see the absolute size of each revision in the history, but that isn't overly intuitive. The Recent Changes with their color-coded messages are much nicer, so I made a script that calculates the diff sizes and displays them just like the RC do.

While I developed it for CP, it works on any wiki (1) that uses the +/- view in the RC and (2) that shows total sizes in the history view.

How to install it (Greasemonkey)
If you're using Greasemonkey (Firefox extension, grab it from the Mozilla Extensions site), there are two ways you can install it:
 * 1) Creating a text file and installing from there:
 * 2) Start a text editor that can save plain text files. On Windows, this would typically be Notepad. Just don't use MS Word or stuff like that.
 * 3) Copy-paste the code from the box below into a blank document. (If you want to include other wikis, just add more "include" lines, following the pattern there.)
 * 4) Save that document under the name HistDiff.user.js
 * 5) Drag and drop that file into the Firefox window (or use "File -> Open File" to navigate to it)
 * 6) A box will pop up, going all "Install this script?". Just confirm that.
 * 7) Creating a new script directly from Firefox
 * 8) In Firefox, right-click on the monkey head (lower right corner) and click on "New user script".
 * 9) Enter the following:
 * 10) *Name: Hist Diff
 * 11) *Namespace: http://rationalwiki.com
 * 12) *Description: Tweak History display to replace byte size with diff size (just like in the Recent Changes)
 * 13) *Includes: http://www.conservapedia.com/*action=history* [enter] http://conservapedia.com/*action=history* [enter] http://rationalwiki.com/*action=history* [similar for any other wiki]
 * 14) *Excludes: [leave blank]
 * 15) Hit "Okay". An editor (Notepad, etc.) will open with a quasi-blank script containing the info you entered above, basically.
 * 16) Replace the entire content of the document with the code from the box below and save the document.

The script
// ==UserScript== // @name          HistoryDiff // @namespace     http://rationalwiki.com // @description   Tweak History display to replace byte size with diff size (just like in the Recent Changes) // @include       http://www.conservapedia.com/*action=history* // @include       http://conservapedia.com/*action=history* // @include       http://rationalwiki.com/*action=history* // ==/UserScript==

(function{ var tagselect, subselect, currently, diff; var sizes= new Array; tagselect = document.getElementById("bodyContent"); subselect = document.evaluate("./form/ul/li/span[@class='history-size']", tagselect, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i < subselect.snapshotLength; i++) {	currently=subselect.snapshotItem(i).innerHTML;	if (currently=="(empty)")	{		currently=0;	}	else	{		currently=currently.slice(1,-7);		currently=currently.replace(/,/,"");		currently=parseInt(currently);	}	sizes[i]=currently; }

for (var j = 0; j < subselect.snapshotLength-1; j++) {	diff=sizes[j]-sizes[j+1]; currently=subselect.snapshotItem(j).innerHTML; if (diff>0) {		if (diff>999) {			diff= ' (+' + diff + ') '; }		else {			diff= ' (+' + diff + ') '; }	}	if (diff <0) {		if (diff<-999) {			diff= ' (' + diff + ') '; }		else {			diff= ' (' + diff + ') '; }	}	if (diff==0) {		diff=' (0) '; }

//If you want to show the total file size and the diff size, simply uncomment the next line and comment out the one behind it. //currently=currently + diff; currently=diff;

subselect.snapshotItem(j).innerHTML = currently; } });

How to install it (Userscript)
Simply edit your userscript file. It's always located at User:[your name]/[your skin name].js - which isn't terribly intuitive, so here are two examples: Do note that the first letter of the skin name is NOT capitalized.
 * RW default skin is "monobook", so my user script location would be User:Sid/monobook.js
 * CP default skin is "conserv" (and my CP user name is "Sid 3050"), so my user script location there would be User:Sid_3050/conserv.js

Once you found your location, copy-paste the below box into it, save and do a few full refreshes of History pages to see the effect.

OBVIOUS WARNING
If you're socking on CP, don't use this script. It originated here on RW, so anybody using it on CP will automatically admit knowledge of The Site That Must Not Be Mentioned. Additionally, CP's completely senseless "Must ask for permission before installing user scripts" rule will pretty much have sysops breathing down your neck anyway.

Advice: Wait until a sysop or parodist installs this as a user script first and gets away with it. Then you can claim that you're just using their script. This should be safe, but we all know that on CP, you can get banned for pretty much anything, so do this at your own risk, obviously.

Hint: The Greasemonkey script above also works when you're not logged in and can't be detected on CP.

The script
function rw{ var tagselect, subselect, currently, diff; var sizes= new Array; tagselect = document.getElementById("bodyContent"); subselect = document.evaluate("./form/ul/li/span[@class='history-size']", tagselect, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i < subselect.snapshotLength; i++) {	currently=subselect.snapshotItem(i).innerHTML; if (currently=="(empty)") {		currently=0; }	else {		currently=currently.slice(1,-7); currently=currently.replace(/,/,""); currently=parseInt(currently); }	sizes[i]=currently; }

for (var j = 0; j < subselect.snapshotLength-1; j++) {	diff=sizes[j]-sizes[j+1]; currently=subselect.snapshotItem(j).innerHTML; if (diff>0) {		if (diff>999) {			diff= ' (+' + diff + ') '; }		else {			diff= ' (+' + diff + ') '; }	}	if (diff <0) {		if (diff<-999) {			diff= ' (' + diff + ') '; }		else {			diff= ' (' + diff + ') '; }	}	if (diff==0) {		diff=' (0) '; }

//If you want to show the total file size and the diff size, simply uncomment the next line and comment out the one behind it. //currently=currently + diff; currently=diff;

subselect.snapshotItem(j).innerHTML = currently; } }

addOnloadHook(rw);

Known bugs
So far, I only know of one bug: If an article has more edits than fit onto one page (usually, this means "more than 50 edits"), the lowest diff will still have the absolute number (even though it's not really the first edit).

Something that isn't a bug is the fact that this script will not work for diffs that predate the time the byte size was introduced. Check this History page to see what I mean - the edits before JM's Sep 14 edit don't have any size listed, so there won't be a diff size for those edits, either.