Skip to content

Instantly share code, notes, and snippets.

@linhnobi
linhnobi / getEventListeners.js
Created July 31, 2024 02:13
View all event listeners used in the page, getEventListeners(object) returns the event listeners registered on the specified object
// Get all the binding click events number in page
// Return number
Array.from(document.querySelectorAll('*'))
.reduce(function(pre, dom){
var clks = getEventListeners(dom).click;
pre += clks ? clks.length || 0 : 0;
return pre
}, 0)
// If you want see what events have been bound in all your elements in your page and
const replaceOnDocument = (pattern, string, { target = document.body } = {}) => {
[target, ...target.querySelectorAll("*:not(script):not(noscript):not(style)")]
.forEach(({ childNodes: [...nodes] }) => nodes
.filter(({ nodeType }) => nodeType === document.TEXT_NODE).forEach((textNode) => (textNode.textContent = textNode.textContent.replace(patter, string)))
);
replaceOnDocument("search","replace");
// retrives all childNodes of body