-
-
Save phusick/ed95fd424008f080e970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var root = angular.element(document.getElementsByTagName('html')); | |
var watchers = []; | |
var attributes = []; | |
var attributes_with_values = []; | |
var elements = {}; | |
var elements_per_attr = []; | |
var scopes = []; | |
function include(arr, obj) { | |
return (arr.indexOf(obj) != -1); | |
} | |
function is_not_duplicate(arr, obj) { | |
if (typeof arr == "undefined") { | |
return true; | |
} else { | |
if (include(arr, obj)) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
} | |
var f = function(element) { | |
if (element.data().hasOwnProperty('$scope')) { | |
if (typeof scopes[element.data().$scope.$id] == "undefined") { | |
scopes[element.data().$scope.$id] = true; | |
angular.forEach(element.data().$scope.$$watchers, function(watcher) { | |
watchers.push(watcher); | |
for (index = 0; index < element[0]['attributes'].length; ++index) { | |
if (is_not_duplicate(elements_per_attr[element[0]['attributes'][index].nodeName], element.data().$scope.$id)) { | |
if (typeof elements[element[0]['attributes'][index].nodeName] == "undefined") { | |
elements[element[0]['attributes'][index].nodeName] = []; | |
} | |
elements[element[0]['attributes'][index].nodeName].push({ | |
element: "(Scope " + element.data().$scope.$id + "): " + element[0].outerHTML, | |
element_obj: element[0], | |
element_data: element.data(), | |
relevant_watcher: watcher, | |
current_value: watcher.last | |
} | |
); | |
if (typeof elements_per_attr[element[0]['attributes'][index].nodeName] == "undefined") { | |
elements_per_attr[element[0]['attributes'][index].nodeName] = []; | |
} | |
elements_per_attr[element[0]['attributes'][index].nodeName].push(element.data().$scope.$id); | |
} | |
} | |
}); | |
} | |
} | |
angular.forEach(element.children(), function(childElement) { | |
f(angular.element(childElement)); | |
}); | |
}; | |
f(root); | |
console.log("Watchers:", watchers.length); | |
console.log("Watched Elements grouped by attribute:", elements); | |
var tableData = {}; | |
angular.forEach(elements, function(element, key) { | |
tableData[key] = { count: element.length }; | |
}); | |
console.table(tableData); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment