مدیاویکی:Common.js
از ویکییاد
نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.
- فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلیدهای Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-R)
- گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-Shift-R)
- Edge: کلید Ctrl را نگهدارید و روی دکمهٔ Refresh کلیک کنید، یا کلیدهای Ctrl-F5 را با هم فشار دهید
/**
* Gallery to background-cover: extract img src → set as box background + hide img
*/
(function () {
function processGalleries() {
document.querySelectorAll('li.gallerybox').forEach(function (box) {
// Find the img inside thumb
const img = box.querySelector('.thumb img.mw-file-element');
if (img && img.src && !box.dataset.backgroundApplied) {
// Apply background
box.style.backgroundImage = 'url(' + img.src + ')';
box.style.backgroundSize = 'cover';
box.style.backgroundPosition = 'center center';
box.style.backgroundRepeat = 'no-repeat';
// Hide original image
img.style.display = 'none';
// Mark as processed to avoid re-running
box.dataset.backgroundApplied = 'true';
console.log('Applied background to gallery box:', img.src);
}
});
}
// Run once DOM is ready
document.addEventListener('DOMContentLoaded', processGalleries);
// Watch for dynamic content added by DPL (important!)
const observer = new MutationObserver(processGalleries);
observer.observe(document.body, { childList: true, subtree: true });
// Fallback: run again after 1–2 seconds in case DPL is very slow
setTimeout(processGalleries, 1500);
setTimeout(processGalleries, 3000);
})();
