Jump to content

User:Ainali/blur.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ainali (talk | contribs) at 08:12, 15 July 2025 (Created page with '// Blur all images on page load function blurAllImages() { document.querySelectorAll('img').forEach(img => { img.classList.add('blurred-image'); }); } // Add CSS style for blurred images mw.util.addCSS(` .blurred-image { filter: blur(20px); transition: filter 0.3s ease; } .blurred-image.unblurred { filter: none; } `); // Blur initially blurAllImages(); // Use event delegation to handle clicks docume...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Blur all images on page load
function blurAllImages() {
    document.querySelectorAll('img').forEach(img => {
        img.classList.add('blurred-image');
    });
}

// Add CSS style for blurred images
mw.util.addCSS(`
    .blurred-image {
        filter: blur(20px);
        transition: filter 0.3s ease;
    }
    .blurred-image.unblurred {
        filter: none;
    }
`);

// Blur initially
blurAllImages();

// Use event delegation to handle clicks
document.addEventListener('click', function(event) {
    const img = event.target.closest('img.blurred-image');
    if (img) {
        img.classList.toggle('unblurred');
    }
});

// Handle dynamically loaded content
const observer = new MutationObserver(blurAllImages);
observer.observe(document.body, { childList: true, subtree: true });