-
-
Save julienetie/027ee9166931c8e213918cfd3a85f0ed to your computer and use it in GitHub Desktop.
Gets a list of all events in the browser
This file contains 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
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