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

مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی‌یاد
Adminwki (بحث | مشارکت‌ها)
جزبدون خلاصۀ ویرایش
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
خط ۳۱: خط ۳۱:
             const thumbDiv = box.querySelector('div.thumb');
             const thumbDiv = box.querySelector('div.thumb');
             if (!thumbDiv) return;
             if (!thumbDiv) return;
            // Quick skip: if this thumb is a known broken/placeholder structure
            if (thumbDiv.querySelector('.mw-broken-media, .mw-file-element:not(img), span[typeof="mw:Error"]')) {
                return; // broken file link → leave untouched
            }


             const img = thumbDiv.querySelector('img.mw-file-element');
             const img = thumbDiv.querySelector('img.mw-file-element');
             if (!img) return;
             if (!img) return;


            // Skip if image has no src, or src is empty/broken placeholder
             const src = img.src && img.src.trim();
             const src = img.src && img.src.trim();
             if (!src || src === '' || src.includes('brokenimage') || src.includes('noimage')) {
             if (!src || src === '' ||  
                src.includes('brokenimage') ||  
                src.includes('noimage') ||
                src.includes('Special:Redirect/file/') ||  // sometimes broken thumbs use redirect
                img.alt === '' || img.alt === null) {     // empty alt often = placeholder
                 return;
                 return;
             }
             }


             // Optional: skip very small placeholder images (common broken/no-image sizes)
             // Skip tiny/unloaded images (common for broken ones)
            // You can adjust or remove these checks
             if (img.naturalWidth <= 4 || img.naturalHeight <= 4 || img.complete === false) {
             if (img.naturalWidth <= 1 || img.naturalHeight <= 1) {
                 return;
                 return;
             }
             }


             // Skip if already processed
             // Already processed?
             if (thumbDiv.dataset.backgroundApplied) {
             if (thumbDiv.dataset.backgroundApplied) {
                 return;
                 return;
خط ۵۸: خط ۶۵:
             thumbDiv.style.backgroundRepeat = 'no-repeat';
             thumbDiv.style.backgroundRepeat = 'no-repeat';


             // Hide original image
             // Hide original img
             img.style.display = 'none';
             img.style.display = 'none';


             // Mark as done
             // Mark as processed
             thumbDiv.dataset.backgroundApplied = 'true';
             thumbDiv.dataset.backgroundApplied = 'true';
         });
         });
     }
     }


     // Initial run after DOM ready
     // Run when DOM is ready
    function init() {
        processGalleries();
    }
 
     if (document.readyState !== 'loading') {
     if (document.readyState !== 'loading') {
         processGalleries();
         init();
     } else {
     } else {
         document.addEventListener('DOMContentLoaded', processGalleries);
         document.addEventListener('DOMContentLoaded', init);
     }
     }


     // Watch for dynamically added galleries / images
     // Mutation observer for dynamic additions (DPL, ajax, category tree, etc.)
     const observer = new MutationObserver(processGalleries);
     const observer = new MutationObserver(processGalleries);
     observer.observe(document.body, {
     observer.observe(document.body, { childList: true, subtree: true });
        childList: true,
        subtree: true
    });


     // Extra safety runs (helps with lazy-loaded thumbs or very slow image loading)
     // Extra delayed runs for late-loading thumbs / lazy images
     setTimeout(processGalleries,  800);
     setTimeout(processGalleries,  600);
     setTimeout(processGalleries, 1800);
     setTimeout(processGalleries, 1500);
     setTimeout(processGalleries, 4000);
     setTimeout(processGalleries, 3500);
})();
})();

نسخهٔ ۹ فوریهٔ ۲۰۲۶، ساعت ۱۵:۲۳

/**
 * Umami Analytics tracking (privacy-focused, self-hosted)
 */
(function() {
    // Create the script element
    var script = document.createElement('script');
    
    // Set attributes exactly as provided by Umami
    script.defer = true;
    script.src = 'https://cloud.umami.is/script.js';
    script.setAttribute('data-website-id', 'f5f75b33-a7ed-4d71-ac5a-7750a48efaa0');
    
    // Append to head (or body – head is preferred for earlier loading)
    document.head.appendChild(script);
})();

/**
 * Gallery to background-cover: set img src as background on .thumb div + hide img
 * → ONLY on Category: pages (not articles or other namespaces)
 */
(function () {
    'use strict';

    // Early exit if not on a category page
    if (mw.config.get('wgCanonicalNamespace') !== 'Category') {
        return;
    }

    function processGalleries() {
        document.querySelectorAll('li.gallerybox').forEach(function (box) {
            const thumbDiv = box.querySelector('div.thumb');
            if (!thumbDiv) return;

            // Quick skip: if this thumb is a known broken/placeholder structure
            if (thumbDiv.querySelector('.mw-broken-media, .mw-file-element:not(img), span[typeof="mw:Error"]')) {
                return; // broken file link → leave untouched
            }

            const img = thumbDiv.querySelector('img.mw-file-element');
            if (!img) return;

            const src = img.src && img.src.trim();
            if (!src || src === '' || 
                src.includes('brokenimage') || 
                src.includes('noimage') || 
                src.includes('Special:Redirect/file/') ||  // sometimes broken thumbs use redirect
                img.alt === '' || img.alt === null) {     // empty alt often = placeholder
                return;
            }

            // Skip tiny/unloaded images (common for broken ones)
            if (img.naturalWidth <= 4 || img.naturalHeight <= 4 || img.complete === false) {
                return;
            }

            // Already processed?
            if (thumbDiv.dataset.backgroundApplied) {
                return;
            }

            // Apply background
            thumbDiv.style.backgroundImage = 'url(' + src + ')';
            thumbDiv.style.backgroundSize = 'cover';
            thumbDiv.style.backgroundPosition = 'center center';
            thumbDiv.style.backgroundRepeat = 'no-repeat';

            // Hide original img
            img.style.display = 'none';

            // Mark as processed
            thumbDiv.dataset.backgroundApplied = 'true';
        });
    }

    // Run when DOM is ready
    function init() {
        processGalleries();
    }

    if (document.readyState !== 'loading') {
        init();
    } else {
        document.addEventListener('DOMContentLoaded', init);
    }

    // Mutation observer for dynamic additions (DPL, ajax, category tree, etc.)
    const observer = new MutationObserver(processGalleries);
    observer.observe(document.body, { childList: true, subtree: true });

    // Extra delayed runs for late-loading thumbs / lazy images
    setTimeout(processGalleries,  600);
    setTimeout(processGalleries, 1500);
    setTimeout(processGalleries, 3500);
})();