Userscripts.org Diff Extender

By jerone Last update Jan 12, 2009 — Installed 61 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 3, 0

There are 3 previous versions of this script.

////////////////////////////////////////////////////////////////////////////
// ==UserScript===
// @name            Userscripts.org Diff Extender
// @author          Jerone UserScript Productions
// @namespace       http://userscripts.org/users/31497
// @homepage        http://userscripts.org/scripts/show/38909
// @description     Add some handy features to the diff.
// @description     Userscripts.org Diff Extender v1.1.1 Beta
// @copyright       2008 Jerone
// @version         v1.1.1 Beta
// @versiontext     Fixed site change.
// @browser         FF3
// @include         http://userscripts.org/scripts/diff/*
// ==/UserScript==
/*//////////////////////////////////////////////////////////////////////////
// ToC:
// - Copyrights
// - History
// - Todo
// - Note
// - Framework Check
// - Userscript
// - Statistics
////////////////////////////////////////////////////////////////////////////
THIS  SCRIPT  IS  PROVIDED BY THE AUTHOR `AS IS' AND ANY EXPRESS OR IMPLIED
WARRANTIES,  INCLUDING, BUT  NOT  LIMITED  TO, THE  IMPLIED  WARRANTIES  OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
EVENT  SHALL  THE  AUTHOR  BE  LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER  CAUSED  AND  ON  ANY THEORY OF LIABILITY,
WHETHER  IN  CONTRACT, STRICT  LIABILITY, OR  TORT  (INCLUDING NEGLIGENCE OR
OTHERWISE)  ARISING  IN  ANY  WAY  OUT  OF  THE  USE OF THIS SCRIPT, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////
// History:
// [+] = added; [-] = removed; [/] = fixed; [*] = updated;
// - 19-12-2008 16:00 [v1 Alpha]:
//   [+] initial release;
// - 10-01-2009 17:45 [v1.1 Beta]:
//   [/] minor bug fix in numbering width;
//   [*] updated framework;
// - 12-01-2009 16:30 [v1.1.1 Beta]:
//   [/] fixed site change;
////////////////////////////////////////////////////////////////////////////
// Todo:
//  - bug with base64 in http://userscripts.org/scripts/diff/16750/48471;
////////////////////////////////////////////////////////////////////////////
// Note:
// - This script does NOT work without it's framework:
//   - US Framework => http://userscripts.org/scripts/show/39678
//   - US Functions => http://userscripts.org/scripts/show/16142
//   - US Language => http://userscripts.org/scripts/show/16143
//   - US Options => http://userscripts.org/scripts/show/31458
//   - US Update => http://userscripts.org/scripts/show/16144
/*//////////////////////////////////////////////////////////////////////////



//*** FRAMEWORK CHECK ***//
if(!window.US||!window.US.Framework){if(window.US!==null&&confirm(String.fromCharCode(83,111,109,101,116,104,105,110,103,32,119,101,110,116,32,119,114,111,110,103,32,119,105,116,104,32,116,104,101,32,85,83,32,70,114,97,109,101,119,111,114,107,46,32,92,110,77,97,107,101,32,115,117,114,101,32,105,116,32,105,115,32,105,110,115,116,97,108,108,101,100,32,99,111,114,114,101,99,116,108,121,32,111,114,32,114,101,105,110,115,116,97,108,108,32,116,104,101,32,115,99,114,105,112,116,46,32,92,110,92,110,68,111,32,121,111,117,32,119,97,110,116,32,116,111,32,103,111,32,116,111,32,116,104,101,32,115,99,114,105,112,116,115,32,104,111,109,101,112,97,103,101,63).replace(/\\n/g,"\n")))GM_openInTab("http://userscripts.org/scripts/show/39678");window.US=null;return;}else if(!window.US.Framework())return;

new US.Language({langMod:"browser"});

new US.Update({check4Update:true,updateTime:1*60*60*1000,title:"Userscripts.org Diff Extender",thisVersion:'v1.1.1 Beta',versionUrl:38909,updateUrl:38909,language:"browser"});

eval(US.Functions.prototype({}));



//*** USERSCRIPT ***//
var UDE = {
	init: function(){
		if((pre=$xs("//div[@id='content']/pre"))){
			$sa(pre,"style","padding-left:15px;");
			
			$addCSS(<style><![CDATA[
				.diff{
					float:				left;
					margin-top:			12px;
					padding-top:		6px;
				}
				.diffNr{
					text-align:			center !important;
					font-size:			1.1em !important;
					font-family:		monospace !important;
				}
				.diffNr td{
					padding:			0px !important;
					border-color:		#DDDDDD;
					border-style:		none none none solid;
					border-width:		0 0 0 3px;
				}
				.diffMeta{
					background-color:	#CCCCCC;
				}
				.diffAdd{
					background-color:	#FF8888;
				}
				.diffDel{
					background-color:	#99FF99;
				}
				.diffSim{
					padding:			0px 5px 0px 4px;
					margin-right:		5px;
					float:				left;
				}
			]]></style>.toString(),false,top.document);
			
			var div=$ib(pre,$ce("DIV"));
			$sa(div,"class","diff");
			 var table=$ac(div,$ce("TABLE"));
			 $sa(table,"width","100%");
			 $sa(table,"border","0");
			 $sa(table,"cellspacing","0");
			 $sa(table,"cellpadding","0");
			 $sa(table,"class","diffNr");
			 
			$x(".//div[@class='meta']",pre).forEach(function(meta){
				$sa(meta,"style","margin-left:-15px;");
				
				var tr=$ac(table,$ce("TR"));
				 var tdDel=$ac(tr,$ce("TD"));
				 $ac(tdDel,$ct("-"));
				 $sa(tdDel,"class","diffMeta");
				 $sa(tdDel,"width","50%");
				 var tdAdd=$ac(tr,$ce("TD"));
				 $ac(tdAdd,$ct("+"));
				 $sa(tdAdd,"class","diffMeta");
				 $sa(tdAdd,"width","50%");
				
				var iOld=meta.textContent.match(/^@@\s\-(\d+),\d+\s\+(\d+),\d+\s@@/)[1];
				var iNew=meta.textContent.match(/^@@\s\-(\d+),\d+\s\+(\d+),\d+\s@@/)[2];
				while(meta.nextSibling && meta.nextSibling.className!="meta"){
					var temp=meta.nextSibling.textContent.split(/\n/);
					temp.splice(-1, 1);
					var tdDel,tdAdd;
					temp.forEach(function(item){
						var tr=$ac(table,$ce("TR"));
						 tdDel=$ac(tr,$ce("TD"));
						 tdAdd=$ac(tr,$ce("TD"));
						if(!item.match(/^\+/)){
							$sa(tdDel,"class","diffAdd");
							$ac(tdDel,$ct(iOld));
							iOld++;
						}
						if(!item.match(/^\-/)){
							$sa(tdAdd,"class","diffDel");
							$ac(tdAdd,$ct(iNew));
							iNew++;
					}	});
					if(meta.nodeType===3){
						tdDel.style.borderTop="1px solid #FF8888";
						tdAdd.style.borderTop="1px solid #99FF99";
					}
					if(meta.nextSibling.nextSibling && meta.nextSibling.nextSibling.nodeType===3){
						tdDel.style.borderBottom="1px solid #FF8888";
						tdAdd.style.borderBottom="1px solid #99FF99";
					}
					meta=meta.nextSibling;
			}	});
			
			$x(".//div[@class='del' or @class='add']",pre).forEach(function(del){
				var temp = del.textContent;
				$sa(del,"style",""+
					"margin-left:		-15px;"+
					"border:			"+(/^\-/.test(temp)?"#AA3333":"#33AA33")+" solid;"+
					"border-width:		"+(del.previousSibling.nodeType==3?"1px":"0px")+" 1px "+(del.nextSibling.nodeType==3?"1px":"0px")+" 1px;");
				$rc(del);
				$ac(del,$ct(temp.replace(/^[\+\-]/,"")));
				var span=$ce("SPAN");
				$sa(span,"class",(/^\-/.test(temp)?"diffAdd":"diffDel")+" diffSim");
				$ih(span,temp.match(/^[\+\-]/));
				$af(del,span);
});	}	}	}

UDE.init();  // execute;



//*** STATISTICS ***//
// Chars (exclude spaces): 5.961
// Chars (include spaces): 6.937
// Chars (Chinese): 0
// Words: 518
// Lines: 186