Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nfreear/5d108e5da956bf26ba6264e1b54e5123 to your computer and use it in GitHub Desktop.
Save nfreear/5d108e5da956bf26ba6264e1b54e5123 to your computer and use it in GitHub Desktop.
ARIA Live Region Monitor Bookmarklet Javascript
/*!
ARIA Live Region Monitor Bookmarklet.
NDF, 29-April-2022.
https://stackoverflow.com/questions/3219758/detect-changes-in-the-dom,
https://developer.mozilla.org/en-US/docs/web/api/mutationobserver,
https://whatsock.github.io/visual-aria/github-bookmarklet/visual-aria.htm,
*/
javascript:
(() => {
const ELEMS = document.querySelectorAll('[aria-live]');
const CALLBACK = function(mutationsList, observer) {
/* Use traditional 'for loops' for IE 11. */
for(const mut of mutationsList) {
if (mut.type==='childList' && mut.addNodes.length) {
console.log('Add node:', mut.addNodes[0].innerText, mut);
} else {
console.log('Mutation:', mut);
}
}
};
const observer = new MutationObserver(CALLBACK);
const config = { attributes: true, childList: true, subtree: true };
[...ELEMS].forEach(EL => observer.observe(EL, config));
})();
/* End. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment