Diferencia entre revisiones de «MediaWiki:Common.js»
Sin resumen de edición |
Sin resumen de edición |
||
| Línea 1: | Línea 1: | ||
// Añadir clase al <body> si el usuario NO ha iniciado sesión | |||
$(document).ready(function () { | |||
if (mw.config.get('wgUserName') === null) { | |||
document.body.classList.add('anon-user'); | |||
} | |||
}); | |||
$(function () { | $(function () { | ||
| Línea 52: | Línea 58: | ||
fetch('/trigger-jobs.php') | fetch('/trigger-jobs.php') | ||
.then(res => res.text()) | .then(res => res.text()) | ||
.then(msg => { | |||
$('#runjobs-msg').html(` | |||
<div style="font-size: 90%; display: flex; align-items: center; gap: 1em;"> | |||
${msg.trim()} | |||
<button id="runjobs-close">Aceptar</button> | |||
</div> | |||
`); | |||
$('#runjobs-close').on('click', () => { | |||
$('#runjobs-msg').remove(); | |||
}); | |||
}) | |||
.catch(err => { | |||
$('#runjobs-msg').html(` | $('#runjobs-msg').html(` | ||
<div style="display: flex; align-items: center; gap: 1em; font-size: 90%;"> | <div style="display: flex; align-items: center; gap: 1em; font-size: 90%;"> | ||
Revisión del 00:26 25 jun 2025
// Añadir clase al <body> si el usuario NO ha iniciado sesión
$(document).ready(function () {
if (mw.config.get('wgUserName') === null) {
document.body.classList.add('anon-user');
}
});
$(function () {
const skin = mw.config.get('skin');
const user = mw.config.get('wgUserName');
if (user !== null && skin === 'vector-2022') {
console.log("🔧 Configurando interfaz personalizada");
function ocultarElementosUsuario() {
$('#pt-watchlist-2').hide();
$('#pt-mytalk').hide();
$('#ca-talk').hide();
}
ocultarElementosUsuario();
const observer = new MutationObserver(ocultarElementosUsuario);
observer.observe(document.body, { childList: true, subtree: true });
// 🔹 Añadir botón "Ejecutar tareas"
mw.util.addPortletLink(
'p-tb',
'#',
'Ejecutar tareas',
'pt-runjobs',
'Ejecutar tareas pendientes desde el navegador'
);
$('#pt-runjobs').on('click', function (e) {
e.preventDefault();
if ($('#runjobs-msg').length) return;
const heading = document.querySelector('#firstHeading');
if (!heading) return;
const $msg = $(`
<div id="runjobs-msg" style="margin: 1em 0; font-size: 90%; display: flex; align-items: center; gap: 1em;">
¿Ejecutar las tareas pendientes ahora?
<button id="runjobs-confirm">✅ Sí</button>
<button id="runjobs-cancel">❌ No</button>
</div>
`);
$(heading).after($msg);
$('#runjobs-cancel').on('click', () => {
$('#runjobs-msg').remove();
});
$('#runjobs-confirm').on('click', () => {
$('#runjobs-msg').html('⏳ Ejecutando tareas...');
fetch('/trigger-jobs.php')
.then(res => res.text())
.then(msg => {
$('#runjobs-msg').html(`
<div style="font-size: 90%; display: flex; align-items: center; gap: 1em;">
${msg.trim()}
<button id="runjobs-close">Aceptar</button>
</div>
`);
$('#runjobs-close').on('click', () => {
$('#runjobs-msg').remove();
});
})
.catch(err => {
$('#runjobs-msg').html(`
<div style="display: flex; align-items: center; gap: 1em; font-size: 90%;">
❌ Error de red: ${err}
<button id="runjobs-close">Aceptar</button>
</div>
`);
$('#runjobs-close').on('click', () => {
$('#runjobs-msg').remove();
});
});
});
});
// 🔹 Mover el botón debajo de "Reemplazar texto"
const runJobsItem = $('#pt-runjobs').closest('li');
const target = $('a:contains("Reemplazar texto")').closest('li');
if (runJobsItem.length && target.length) {
runJobsItem.insertAfter(target);
}
}
});