اطلاعیه: از همه ایران دوستان عزیز دعوت می‌کنیم در ایجاد و به‌روزرسانی صفحات جاویدنامان همیاری نمایند. در حال حاضر میتوانید بدون عضویت در ثبت تاریخ کمک نمایید.

مدیاویکی:Common.js

از ویکی‌یاد
نسخهٔ تاریخ ۲۳ ژانویهٔ ۲۰۲۶، ساعت ۱۹:۴۱ توسط Adminwki (بحث | مشارکت‌ها)

نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.

  • فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلید‌های Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-R)
  • گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-Shift-R)
  • Edge: کلید Ctrl را نگه‌دارید و روی دکمهٔ Refresh کلیک کنید، یا کلید‌های Ctrl-F5 را با هم فشار دهید
/**
 * Gallery to background-cover: set img src as background on .thumb div + hide img
 */
(function () {
    function processGalleries() {
        document.querySelectorAll('li.gallerybox').forEach(function (box) {
            // Find the .thumb div and the img inside it
            const thumbDiv = box.querySelector('div.thumb');
            const img = thumbDiv ? thumbDiv.querySelector('img.mw-file-element') : null;
            
            if (thumbDiv && img && img.src && !thumbDiv.dataset.backgroundApplied) {
                // Apply background to the .thumb div
                thumbDiv.style.backgroundImage = 'url(' + img.src + ')';
                thumbDiv.style.backgroundSize = 'cover';
                thumbDiv.style.backgroundPosition = 'center center';
                thumbDiv.style.backgroundRepeat = 'no-repeat';
                
                // Hide the original <img> tag
                img.style.display = 'none';
                
                // Mark as processed
                thumbDiv.dataset.backgroundApplied = 'true';
                
                console.log('Applied background to thumb div:', img.src);
            }
        });
    }

    // Run once DOM is ready
    document.addEventListener('DOMContentLoaded', processGalleries);

    // Watch for dynamic additions (DPL may insert later)
    const observer = new MutationObserver(processGalleries);
    observer.observe(document.body, { childList: true, subtree: true });

    // Extra fallback runs
    setTimeout(processGalleries, 1000);
    setTimeout(processGalleries, 2500);
})();