Skip to content

Instantly share code, notes, and snippets.

@cstumph
Last active February 6, 2020 20:53
Show Gist options
  • Save cstumph/c1ec28c9049ff54c1ddc617716ed52be to your computer and use it in GitHub Desktop.
Save cstumph/c1ec28c9049ff54c1ddc617716ed52be to your computer and use it in GitHub Desktop.
Count all event listeners
Array.from(document.querySelectorAll('*'))
.reduce(function(pre, dom){
var evtObj = getEventListeners(dom)
Object.keys(evtObj).forEach(function (evt) {
if (typeof pre[evt] === 'undefined') {
pre[evt] = 0
}
pre[evt] += evtObj[evt].length
})
return pre
}, {})
@cstumph
Copy link
Author

cstumph commented Jun 26, 2019

And a fun way to filter down the DOM nodes for other analysis, discarding things like emotions style tags, boilerplate, etc.
Array.from(document.querySelectorAll('*')).filter((i) => ['SCRIPT', 'STYLE', 'META', 'HEAD', 'TITLE', 'BODY', 'HTML'].indexOf(i.tagName) < 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment