Created
December 10, 2018 07:28
-
-
Save gartmeier/b150c6cb845e46ee035ff2388006fb77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function addHook(hook, eventName) { | |
let event = window[eventName]; | |
window[eventName] = function() { | |
setTimeout(() => { | |
try { | |
hook.apply(null, arguments); | |
} catch (e) { | |
console.error(e); | |
} | |
}, 0); | |
event.apply(null, arguments); | |
}; | |
} | |
function addHookBefore(hook, eventName) { | |
let event = window[eventName]; | |
window[eventName] = function() { | |
try { | |
hook.apply(null, arguments); | |
} catch (e) { | |
console.error(e); | |
} | |
event.apply(null, arguments); | |
}; | |
} | |
function addHookAfter(hook, eventName) { | |
let event = window[eventName]; | |
window[eventName] = function() { | |
event.apply(null, arguments); | |
try { | |
hook.apply(null, arguments); | |
} catch (e) { | |
console.error(e); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment