مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکییاد
بدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| خط ۱۷: | خط ۱۷: | ||
/** | /** | ||
* Gallery to background-cover: set img src as background on .thumb div + hide img | * Gallery to background-cover: set img src as background on .thumb div + hide img | ||
* → ONLY | * → ONLY when the gallerybox is inside an element with class "javidnam" | ||
*/ | */ | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
function processGalleries() { | function processGalleries() { | ||
document.querySelectorAll('li.gallerybox').forEach(function (box) { | document.querySelectorAll('li.gallerybox').forEach(function (box) { | ||
// Check if this gallerybox is inside a .javidnam container | |||
const container = box.closest('.javidnam'); | |||
if (!container) { | |||
return; // skip if not inside .javidnam | |||
} | |||
const thumbDiv = box.querySelector('div.thumb'); | const thumbDiv = box.querySelector('div.thumb'); | ||
if (!thumbDiv) return; | if (!thumbDiv) return; | ||
| خط ۴۱: | خط ۴۲: | ||
const src = img.src && img.src.trim(); | const src = img.src && img.src.trim(); | ||
if (!src || src === '' || | if (!src || src === '' || | ||
src.includes('brokenimage') || | src.includes('brokenimage') || | ||
src.includes('noimage') || | src.includes('noimage') || | ||
src.includes('Special:Redirect/file/') || | src.includes('Special:Redirect/file/') || | ||
img.alt === '' || img.alt === null) { | img.alt === '' || img.alt === null) { | ||
return; | return; | ||
} | } | ||
| خط ۸۴: | خط ۸۵: | ||
} | } | ||
// Mutation observer for dynamic | // Mutation observer for dynamic content (DPL, AJAX loads, etc.) | ||
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 delayed runs for late-loading thumbs / lazy images | // Extra delayed runs for late-loading thumbs / lazy images | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 600); | ||
setTimeout(processGalleries, 1500); | setTimeout(processGalleries, 1500); | ||
setTimeout(processGalleries, 3500); | 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 when the gallerybox is inside an element with class "javidnam"
*/
(function () {
'use strict';
function processGalleries() {
document.querySelectorAll('li.gallerybox').forEach(function (box) {
// Check if this gallerybox is inside a .javidnam container
const container = box.closest('.javidnam');
if (!container) {
return; // skip if not inside .javidnam
}
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/') ||
img.alt === '' || img.alt === null) {
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 content (DPL, AJAX loads, 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);
})();
