{"size": 1280, "ext": "js", "max_stars_repo_path": "targeted/Find largest subtree.js", "max_stars_repo_name": "thc202/community-scripts", "max_stars_repo_stars_event_min_datetime": "2015-01-02T15:10:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T07:05:21.000Z", "max_issues_repo_path": "targeted/Find largest subtree.js", "max_issues_repo_name": "thc202/community-scripts", "max_issues_repo_issues_event_min_datetime": "2015-05-11T00:53:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T06:02:16.000Z", "max_forks_repo_path": "targeted/Find largest subtree.js", "max_forks_repo_name": "thc202/community-scripts", "max_forks_repo_forks_event_min_datetime": "2015-01-02T14:12:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T07:20:16.000Z"}
{"max_stars_count": 629, "max_issues_count": 168, "max_forks_count": 241, "avg_line_length": 28.4444444444, "max_line_length": 114, "alphanum_fraction": 0.68828125}
// Find the largest sub tree under the node the script was invoked with.
// Also reports the total number of sub nodes.
// Targeted scripts can only be invoked by you, the user, eg via a right-click option on the Sites or History tabs

tot = 0
maxparent = ""
maxsub = 0

function recurseDown(node) {
	//print('recurseDown node: ' + node.getHierarchicNodeName() + " " + node.getChildCount())
	tot++
	if (node.getChildCount() > maxsub) {
		maxsub = node.getChildCount();
		maxparent = node.getHierarchicNodeName()
	}
	var j;
	for (j=0;j<node.getChildCount();j++) {
		recurseDown(node.getChildAt(j))
	}
}


function invokeWith(msg) {
	// Debugging can be done using print like this
	//print('invokeWith called for url=' + msg.getRequestHeader().getURI().toString())

	var sitestree = org.parosproxy.paros.model.Model.getSingleton().getSession().getSiteTree()
	var node = sitestree.findNode(msg, true)

	if (node != null) {
		//print('found node: ' + node.getHierarchicNodeName())
		recurseDown(node)
		tot -- // to remove the top node

		print('Largest subtree under ' + node.getHierarchicNodeName() + ' is')
		print('\t' + maxparent)
		print('With ' + maxsub + ' immediate sub nodes')
		print('Total number of sub nodes = ' + tot)

	} else {
		print('Failed to find node:( ')
	}

}
