مدیاویکی:Common.js
از ویکییاد
نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.
- فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلیدهای Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-R)
- گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-Shift-R)
- Edge: کلید Ctrl را نگهدارید و روی دکمهٔ Refresh کلیک کنید، یا کلیدهای Ctrl-F5 را با هم فشار دهید
/**
* 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);
})();
