repaint-detector
Version:
a library for styling the DOM while it is being repainted
23 lines (19 loc) • 606 B
JavaScript
function detectRepaint() {
const observer = new MutationObserver((mutations) => {
const colors = ["green", "red", "blue", "yellow"];
mutations.forEach((mutation) => {
const target = mutation.target;
if (target) {
const randomColor = colors[Math.floor(Math.random() * colors.length)];
target.style.border = `2px solid ${randomColor}`;
}
});
});
observer.observe(document.body, {
attributes: true,
childList: true,
subtree: true,
});
}
// Automatically execute the function when the script is loaded
detectRepaint();