MediaWiki:Common.js
De FSF
Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.
- Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
- Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
/* MediaWiki:Common.js */
/* 20260224 - Anexo para agregar encabezado arriba del SUMARIO del toc. Plantilla:FSF Panel Diario */
/* 20260226 - FSF Panel Diario ultra ligero sin API */
/* --------------------------------------------------------------- */
/* -- Para poder ver la cantidad de vistas de la pagina segun el footer de WikiFSF - 2260325 */
mw.hook('wikipage.content').add(function () {
let footer = document.getElementById('footer-info');
let panel = document.getElementById('fsf-views');
if (!footer || !panel) return;
let texto = footer.innerText;
let match = texto.match(/(\d+)\s+visitas/);
if (match) {
panel.textContent = " " + match[1] + " ";
} else {
panel.textContent = "—";
}
});
/* --
document.addEventListener("DOMContentLoaded", function () {
function buscarVistas() {
let footer = document.querySelector("#footer-info");
let panel = document.getElementById("fsf-views");
if (!footer || !panel) return false;
let texto = footer.innerText;
let match = texto.match(/(\d+)\s+visitas/);
if (match) {
panel.innerHTML = "👁️ " + match[1] + " visitas";
return true;
}
return false;
}
// Intentar varias veces (clave en MediaWiki)
let intentos = 0;
let intervalo = setInterval(function () {
if (buscarVistas() || intentos > 10) {
clearInterval(intervalo);
}
intentos++;
}, 300);
});
--/
/* --
document.addEventListener("DOMContentLoaded", function () {
// Buscar el texto de vistas en el footer
let footerViews = document.querySelector("#footer-info-views");
// Buscar el contenedor en el FSF Panel
let panelViews = document.getElementById("fsf-views");
if (footerViews && panelViews) {
panelViews.innerHTML = footerViews.innerText;
}
});
--}}
/* -- Ciertas ligas externas no cierran la ventana local o actual; si se usa la Plantilla:Ext la URL se abre en un pestaña nueva. --*/
mw.loader.using('mediawiki.util').then(function () {
$(function () {
$('a.external').each(function () {
if (!this.href.includes(location.hostname)) {
$(this)
.attr('target', '_blank')
.attr('rel', 'noopener noreferrer');
}
});
});
});
/* --
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll("a.external").forEach(function(link) {
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noopener noreferrer");
});
}); --*/
/* --------------------------------------------------------------- */
/*
mw.loader.using('mediawiki.util').then(function () {
$(function () {
// Solo si existe TOC
if (!$('#toc').length) return;
var pageId = mw.config.get('wgArticleId');
var namespace = mw.config.get('wgNamespaceNumber');
var isSpecial = mw.config.get('wgCanonicalSpecialPageName');
// Evitar páginas especiales o sin ID real
if (!pageId || pageId <= 0 || isSpecial) return;
var panelHTML =
'<div class="fsf-panel-container" ' +
'style="margin-bottom:8px; padding:6px 10px; background:#f8f9fa; border:1px solid #ddd; font-size:90%;">' +
'<strong>FSF Diario</strong> · ID: ' + pageId +
'</div>';
$('#toc').prepend(panelHTML);
});
});
*/
/* 20260427 - Boton de donativos. */
mw.loader.using(['mediawiki.util']).then(function () {
function addDonateButton() {
// ESTE selector sí existe en tu header (ya lo vi en tu captura)
var header = document.querySelector('#mw-header');
if (!header) {
console.log("No se encontró #mw-header");
return;
}
// evitar duplicados
if (document.getElementById('fsf-donate-btn')) return;
var btn = document.createElement('a');
btn.id = 'fsf-donate-btn';
btn.href = 'https://familiasuperfeliz.com/index.php/Donativos';
btn.textContent = '💙 Donar';
btn.title = 'Apoya este proyecto';
header.appendChild(btn);
console.log("Botón agregado en header");
}
window.addEventListener('load', function () {
setTimeout(addDonateButton, 300);
});
});
/* 20260427 - BOTON PULL DOWN MENU. */
mw.loader.using(['mediawiki.util']).then(function () {
mw.hook('wikipage.content').add(function () {
if (document.getElementById('fsf-menu')) return;
var header = document.querySelector('#mw-header');
if (!header) return;
// Contenedor
var container = document.createElement('div');
container.id = 'fsf-menu';
// Botón principal
var button = document.createElement('button');
button.id = 'fsf-menu-btn';
button.textContent = '⚙ Opciones';
// Dropdown
var dropdown = document.createElement('div');
dropdown.id = 'fsf-dropdown';
dropdown.innerHTML = `
<a href="/index.php/Donativos">💙 Donar</a>
<a href="/index.php/Inicio">🏠 Inicio</a>
<a href="/index.php/Especial:Preferencias">⚙ Preferencias</a>
`;
container.appendChild(button);
container.appendChild(dropdown);
header.appendChild(container);
// Toggle
button.addEventListener('click', function (e) {
e.stopPropagation();
dropdown.classList.toggle('show');
});
// Cerrar al hacer clic fuera
document.addEventListener('click', function () {
dropdown.classList.remove('show');
});
});
});