Skip to content

Instantly share code, notes, and snippets.

@julienetie
Forked from galpx/getEvents.js
Last active May 16, 2021 12:03
Show Gist options
  • Save julienetie/027ee9166931c8e213918cfd3a85f0ed to your computer and use it in GitHub Desktop.
Save julienetie/027ee9166931c8e213918cfd3a85f0ed to your computer and use it in GitHub Desktop.
Gets a list of all events in the browser
const isEvent0 = prop => 0 === prop.indexOf('on');
const getEventNames0 = (obj) => {
const result = [];
for (let prop in obj) {
if (!isEvent0(prop)) continue;
prop = prop.substr(2), result.push(prop);
}
return result;
}
const getEvents = () => {
const result = {};
const arr = Object.getOwnPropertyNames(window);
result['window'] = getEventNames0(window, hasOwnProperty);
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
const obj = window[element];
if (!obj || !obj['prototype']) continue;
const proto = obj['prototype'];
if(!proto) continue;
const resultArray = getEventNames0(proto);
if(!resultArray.length) continue;
result[element] = resultArray;
}
return result;
}
console.info(getEvents());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment