User:Ainali/blur.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:Ainali/blur.
// 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 });