/** * Tool functions with no dependency on settings.js */ /** Creates a hexagon SVG path from x/y center and radius */ function hexagon(x,y,r) { var x1 = x; var y1 = y-r; var x2 = x+(Math.cos(Math.PI/6)*r); var y2 = y-(Math.sin(Math.PI/6)*r); var x3 = x+(Math.cos(Math.PI/6)*r); var y3 = y+(Math.sin(Math.PI/6)*r); var x4 = x; var y4 = y+r; var x5 = x-(Math.cos(Math.PI/6)*r); var y5 = y+(Math.sin(Math.PI/6)*r); var x6 = x-(Math.cos(Math.PI/6)*r); var y6 = y-(Math.sin(Math.PI/6)*r); var path = 'M'+x1+" "+y1+" L"+x2+" "+y2+" L"+x3+" "+y3+" L"+x4+" "+y4+" L"+x5+" "+y5+" L"+x6+" "+y6+"z"; return path; } /** A simple hash method, http://stackoverflow.com/a/7616484 */ String.prototype.hashCode = function() { var hash = 0, i, chr, len; if (this.length === 0) return hash; for (i = 0, len = this.length; i < len; i++) { chr = this.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; }; /** Partition array elements according to callback function boolean value */ Array.prototype.partition = function (f){ var matched = [], unmatched = [], i = 0, j = this.length; for (; i < j; i++){ (f.call(this, this[i], i) ? matched : unmatched).push(this[i]); } return [unmatched, matched]; }; /** Parses maltego resonse XML Field elements into a js object using a mapping */ function namedFieldsToObj(fieldEls, mapping) { var obj = {}; var field = null; for(var j = 0; j < fieldEls.length; j++) { field = fieldEls[j]; var mappedFieldName = mapping[field.getAttribute('Name')]; if(!mappedFieldName) continue; obj[mappedFieldName] = field.textContent; } return obj; }