Created
May 3, 2022 16:38
-
-
Save nfreear/5d108e5da956bf26ba6264e1b54e5123 to your computer and use it in GitHub Desktop.
ARIA Live Region Monitor Bookmarklet Javascript
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
/*! | |
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