Diferencia entre revisiones de «MediaWiki:Common.js»
Sin resumen de edición Etiqueta: Revertido |
Sin resumen de edición Etiqueta: Reversión manual |
||
| Línea 1: | Línea 1: | ||
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */ | /* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */ | ||
$(function () { | |||
const skin = mw.config.get('skin'); | |||
const user = mw.config.get('wgUserName'); | |||
if (user !== null && skin === 'vector-2022') { | |||
if (! | 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 => { | |||
const cleanMsg = msg.trim().replace(/^✅\s*/, ''); | |||
$('#runjobs-msg').html(` | |||
<div style="display: flex; align-items: center; gap: 1em; font-size: 90%;"> | |||
✅ ${cleanMsg} | |||
<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); | |||
} | |||
} | |||
}); | |||
} | |||
Revisión del 15:55 21 jun 2025
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
$(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 => {
const cleanMsg = msg.trim().replace(/^✅\s*/, '');
$('#runjobs-msg').html(`
<div style="display: flex; align-items: center; gap: 1em; font-size: 90%;">
✅ ${cleanMsg}
<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);
}
}
});