Userscripts.org Source Numbering

By jerone Last update Jan 15, 2009 — Installed 97 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0

There are 4 previous versions of this script.

////////////////////////////////////////////////////////////////////////////
// ==UserScript===
// @name            Userscripts.org Source Numbering
// @author          Jerone UserScript Productions
// @namespace       http://userscripts.org/users/31497
// @homepage        http://userscripts.org/scripts/show/38912
// @description     Add line numbering to source code.
// @description     Userscripts.org Source Numbering v1.2 Beta
// @copyright       2008 Jerone
// @version         v1.2 Beta
// @versiontext     Fixed style bugs and added maximum lines option.
// @browser         FF3
// @include         http://userscripts.org/scripts/review/*
// ==/UserScript==
/*//////////////////////////////////////////////////////////////////////////
// ToC:
// - Copyrights
// - History
// - Todo
// - Note
// - Framework Check
// - User Settings
// - 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 17:30 [v1 Alpha]:
//   [+] initial release;
// - 10-01-2009 19:15 [v1.1 Beta]:
//   [/] fixed bug in to many lines causing FF to crash;
//   [/] minor bug fix in numbering width;
//   [*] updated framework;
// - 11-01-2009 00:15 [v1.1.1 Beta]:
//   [/] fixed bug in code;
// - 15-01-2009 17:00 [v1.2 Beta]:
//   [+] added maximum lines option;
//   [/] fixed style;
//   [*] cleaned up code;
////////////////////////////////////////////////////////////////////////////
// Todo:
//  - 
////////////////////////////////////////////////////////////////////////////
// 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 Source Numbering",thisVersion:'v1.2 Beta',versionUrl:38912,updateUrl:38912,language:"browser"});

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



//*** USER SETTINGS ***//
const maxLines	= 2000;		// [Integer] maximum number of lines (prevent FF from crashing);



//*** USERSCRIPT ***//
var USN = {
	init: function(){
		if((pre=$gi("source"))){
			$addCSS(<style><![CDATA[
				.numb{
					float:			left;
					width:			37px;
					padding:		6px 0 4px 0;
					border-color:	#CCCCCC #DDDDDD;
					border-style:	solid;
					border-width:	1px 3px;
				}
				.numbNr{
					text-align:		center !important;
					font-size:		1.1em !important;
					font-family:	monospace !important;
				}
				.numbNr td{
					padding:		0px !important;
					border:			0px none !important;
				}
				pre#source{
					margin-left:	40px !important;
				}
			]]></style>.toString(),false,top.document);
			
			var preHeight=parseFloat($getStyle(pre,"height"));
			var lineHeight=parseFloat($getStyle(pre,"line-height"))||17.6833;  // px; 
			
			var div=$ib(pre,$ce("DIV"));
			$sa(div,"class","numb");
			$sa(div,"style","height:"+preHeight+"px");
			 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","numbNr");
			
			var lines=maxLines||2000;
			if(preHeight<((lines+9)*lineHeight)){
				lines=pre.innerHTML.split(/\n/).length+1;
			}
			for(var i=1; i<lines; i++){
				var tr=$ac(table,$ce("TR"));
				 var td=$ac(tr,$ce("TD"));
				 $ac(td,$ct(i));
}	}	}	}

USN.init();  // execute;



//*** STATISTICS ***//
// Chars (exclude spaces): 4.699
// Chars (include spaces): 5.396
// Chars (Chinese): 0
// Words: 488
// Lines: 141