SEARCH
TOOLBOX
LANGUAGES
modified on 19 June 2010 at 01:27 ••• 2,259 views

O2 Script - Quick HtmlCode Viewer

From

Jump to: navigation, search

This script provides a very simple and quick way to view a webpage's Html in two formats: Raw Html and TreeView

Compile

  • Copy the code below into a

Image:5_19_2010_3_33_25_AM_tmp445A.jpg

Execute

  • click execute
  • by default www.google.com is loaded:

Image:5_19_2010_3_42_44_AM_tmp4462.jpg

  • TreeNode Legend: on the right, each note is prefixed with:
    • a: (shows an Attribute value of the selected node)
    • v: (shows in InnerHtml value of the selected node)
    • n: (shows a ChildNode)
  • viewing www.owasp.org (by entering www.owasp.org on the top TextBox and pressing Enter)

Image:5_19_2010_3_35_35_AM_tmp445D.jpg

  • note that selecting a node (on the right) will highlight its location on the code (on the left)

Image:5_19_2010_3_39_21_AM_tmp4460.jpg

Source Code

var defaultPage = "http://www.google.com";
 
// create GUI
var panel = O2Gui.open<Panel>("Quick HtmlCode Viewer",600,300);  
var groupBoxes = panel.add_1x1("Html Code", "TreeView", true, panel.width() /2 );
var htmlCodeViewer = groupBoxes[0].add_SourceCodeViewer();
var treeView =  groupBoxes[1].add_TreeView();
var pageToOpen = treeView.parent<SplitContainer>().insert_Above<Panel>(20).add_TextBox().fill();
 
// setup Events 
treeView.beforeExpand<HtmlAgilityPack.HtmlNode>(
		(treeNode, htmlNode)=>{																
								 if (htmlNode.Attributes != null)
								 	 foreach(var attribute in htmlNode.Attributes)
									 	 treeNode.add_Node("a: {0}={1}".format(attribute.Name, attribute.Value)); 
								 treeNode.add_Node("v: {0}".format(htmlNode.InnerHtml));  	
								 if (htmlNode.ChildNodes != null)
								 	 foreach(var childNode in htmlNode.ChildNodes)
									 	 if (childNode.html().valid()) 
										 	 treeNode.add_Node("n: {0}".format(childNode.Name), childNode, true);  
							  });
treeView.afterSelect<HtmlAgilityPack.HtmlNode>(
				  (htmlNode)=>{
				 		//show.info(htmlNode);
				 				if (htmlNode.Line != null && htmlNode.NextSibling != null) 
				 					{					 						
				 						var startLine = htmlNode.Line;
				 						var startColumn = htmlNode.LinePosition;
				 						var endLine = htmlNode.NextSibling.Line;
				 						var endColumn = htmlNode.NextSibling.LinePosition;
				 						htmlCodeViewer.editor().clearMarkers();
				 						htmlCodeViewer.editor().selectTextWithColor(startLine, startColumn, endLine, endColumn);				 						
				 						htmlCodeViewer.editor().caret_Line(startLine);
				 						htmlCodeViewer.editor().refresh();
				 					}								 	
				 			  });
pageToOpen.onEnter(
		(text)=>{
					pageToOpen.backColor(Color.LightBlue);					
					O2Thread.mtaThread(()=>
					{
						treeView.clear();						
						var htmlCode = text.uri().getHtml();						
						htmlCodeViewer.set_Text(htmlCode);
						var htmlDocument = htmlCode.htmlDocument();  												
						treeView.add_Node(htmlDocument.DocumentNode.Name, htmlDocument.DocumentNode,true);   
						treeView.expand();
						pageToOpen.backColor(Color.White); 					
					});
 
				});;
 
// load default data
pageToOpen.sendKeys(defaultPage.line());
MediaWiki Appliance - Powered by TurnKey Linux