Skip to content

Instantly share code, notes, and snippets.

@townivan
Created March 22, 2018 14:49
Show Gist options
  • Save townivan/032059819647c0a7a7a0a50c558fce4f to your computer and use it in GitHub Desktop.
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!
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