مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکییاد
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| خط ۲۹: | خط ۲۹: | ||
function processGalleries() { | function processGalleries() { | ||
document.querySelectorAll('li.gallerybox').forEach(function (box) { | document.querySelectorAll('li.gallerybox').forEach(function (box) { | ||
const thumbDiv = box.querySelector('div.thumb'); | const thumbDiv = box.querySelector('div.thumb'); | ||
if (!thumbDiv) return; | |||
const img = thumbDiv.querySelector('img.mw-file-element'); | |||
if (!img) return; | |||
// Skip if image has no src, or src is empty/broken placeholder | |||
img. | const src = img.src && img.src.trim(); | ||
if (!src || src === '' || src.includes('brokenimage') || src.includes('noimage')) { | |||
return; | |||
} | |||
// Optional: skip very small placeholder images (common broken/no-image sizes) | |||
// You can adjust or remove these checks | |||
if (img.naturalWidth <= 1 || img.naturalHeight <= 1) { | |||
return; | |||
} | |||
// Skip if 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 image | |||
img.style.display = 'none'; | |||
// Mark as done | |||
thumbDiv.dataset.backgroundApplied = 'true'; | |||
}); | }); | ||
} | } | ||
// | // Initial run after DOM ready | ||
document.addEventListener('DOMContentLoaded', processGalleries); | if (document.readyState !== 'loading') { | ||
processGalleries(); | |||
} else { | |||
document.addEventListener('DOMContentLoaded', processGalleries); | |||
} | |||
// Watch for | // Watch for dynamically added galleries / images | ||
const observer = new MutationObserver(processGalleries); | const observer = new MutationObserver(processGalleries); | ||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { | ||
childList: true, | |||
subtree: true | |||
}); | |||
// Extra | // Extra safety runs (helps with lazy-loaded thumbs or very slow image loading) | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 800); | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 1800); | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 4000); | ||
})(); | })(); | ||
نسخهٔ ۹ فوریهٔ ۲۰۲۶، ساعت ۱۵:۲۰
/**
* 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;
const img = thumbDiv.querySelector('img.mw-file-element');
if (!img) return;
// Skip if image has no src, or src is empty/broken placeholder
const src = img.src && img.src.trim();
if (!src || src === '' || src.includes('brokenimage') || src.includes('noimage')) {
return;
}
// Optional: skip very small placeholder images (common broken/no-image sizes)
// You can adjust or remove these checks
if (img.naturalWidth <= 1 || img.naturalHeight <= 1) {
return;
}
// Skip if 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 image
img.style.display = 'none';
// Mark as done
thumbDiv.dataset.backgroundApplied = 'true';
});
}
// Initial run after DOM ready
if (document.readyState !== 'loading') {
processGalleries();
} else {
document.addEventListener('DOMContentLoaded', processGalleries);
}
// Watch for dynamically added galleries / images
const observer = new MutationObserver(processGalleries);
observer.observe(document.body, {
childList: true,
subtree: true
});
// Extra safety runs (helps with lazy-loaded thumbs or very slow image loading)
setTimeout(processGalleries, 800);
setTimeout(processGalleries, 1800);
setTimeout(processGalleries, 4000);
})();
