Skip to content

Instantly share code, notes, and snippets.

@chelovekula
Created October 13, 2020 23:44
Show Gist options
  • Save chelovekula/73d82152cabe1724a5962e5d572ea227 to your computer and use it in GitHub Desktop.
Save chelovekula/73d82152cabe1724a5962e5d572ea227 to your computer and use it in GitHub Desktop.
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];
for (let j = 0; j < types.length; j++) {
if (typeof currentElement[types[j]] === 'function') {
elements.push({
"node": currentElement,
"listeners": [ {
"type": types[j],
"func": currentElement[types[j]].toString(),
}]
});
}
}
}
return elements.filter(element => element.listeners.length)
})();
console.log(listeners);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment