Created
March 22, 2018 14:49
-
-
Save townivan/032059819647c0a7a7a0a50c558fce4f to your computer and use it in GitHub Desktop.
Chuck's excellent script to deal with tracker images without alt tag - the ones that mess up a11y scans!
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
document.addEventListener('DOMContentLoaded', function () { | |
const targetNode = document.body; | |
const callback = function (mutationsList) { | |
for (let mutation of mutationsList) { | |
if (mutation.type == 'childList') { | |
mutation.addedNodes.forEach((node) => { | |
if (node && node.src && node.src.match(/.*pages02.net.*/).length > | |
0) { | |
observer.disconnect(); | |
node.setAttribute("aria-hidden", true); | |
node.setAttribute("alt", ""); | |
} | |
}); | |
} | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(targetNode, { | |
childList: true | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment