Diferencia entre revisiones de «MediaWiki:Common.js»
Sin resumen de edición Etiqueta: Revertido |
Sin resumen de edición Etiqueta: Revertido |
||
| Línea 1: | Línea 1: | ||
// Añadir clase al <body> si el usuario NO ha iniciado sesión | |||
$(document).ready(function () { | $(document).ready(function () { | ||
if (mw.config.get('wgUserName') === null) { | if (mw.config.get('wgUserName') === null) { | ||
document.body.classList.add('anon-user'); | document.body.classList.add('anon-user'); | ||
} | } | ||
}); | |||
$(function () { | |||
const skin = mw.config.get('skin'); | const skin = mw.config.get('skin'); | ||
const user = mw.config.get('wgUserName'); | const user = mw.config.get('wgUserName'); | ||
const action = mw.config.get('wgAction'); | const action = mw.config.get('wgAction'); | ||
// Solo ejecutar personalizaciones en modo "view" | // Solo ejecutar personalizaciones en modo "view" | ||
if (action === 'view') { | if (action === 'view') { | ||
// 🛠️ Ocultar elementos si el usuario NO ha iniciado sesión y la skin es Vector-2022 | |||
if (user === null && skin === 'vector-2022') { | if (user === null && skin === 'vector-2022') { | ||
console.log("🛠️ Ocultando elementos para usuarios anónimos en Vector-2022"); | console.log("🛠️ Ocultando elementos para usuarios anónimos en Vector-2022"); | ||
| Línea 24: | Línea 28: | ||
} | } | ||
// 👤 Configuración personalizada para usuarios logueados con skin Vector-2022 | |||
if (user !== null && skin === 'vector-2022') { | if (user !== null && skin === 'vector-2022') { | ||
console.log("🔧 Configurando interfaz personalizada | console.log("🔧 Configurando interfaz personalizada"); | ||
function ocultarElementosUsuario() { | function ocultarElementosUsuario() { | ||
$('#pt-watchlist-2').hide(); | $('#pt-watchlist-2').hide(); | ||
$('#pt-mytalk').hide(); | |||
$('#ca- | $('#ca-talk').hide(); | ||
} | } | ||
ocultarElementosUsuario(); | ocultarElementosUsuario(); | ||
const observer = new MutationObserver(ocultarElementosUsuario); | const observer = new MutationObserver(ocultarElementosUsuario); | ||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { childList: true, subtree: true }); | ||
// Añadir botón "Ejecutar tareas" | // 🔹 Añadir botón "Ejecutar tareas" | ||
mw.util.addPortletLink( | mw.util.addPortletLink( | ||
'p-tb', | 'p-tb', | ||
| Línea 57: | Línea 59: | ||
if (!heading) return; | if (!heading) return; | ||
const $msg = $( | const $msg = $( | ||
<div id="runjobs-msg" style="margin: 1em 0; font-size: 90%; display: flex; align-items: center; gap: 1em;"> | <div id="runjobs-msg" style="margin: 1em 0; font-size: 90%; display: flex; align-items: center; gap: 1em;"> | ||
¿Ejecutar las tareas pendientes ahora? | ¿Ejecutar las tareas pendientes ahora? | ||
| Línea 63: | Línea 65: | ||
<button id="runjobs-cancel">❌ No</button> | <button id="runjobs-cancel">❌ No</button> | ||
</div> | </div> | ||
); | |||
$(heading).after($msg); | $(heading).after($msg); | ||
| Línea 76: | Línea 78: | ||
.then(res => res.text()) | .then(res => res.text()) | ||
.then(msg => { | .then(msg => { | ||
$('#runjobs-msg').html( | $('#runjobs-msg').html( | ||
<div style="font-size: 90%; display: flex; align-items: center; gap: 1em;"> | <div style="font-size: 90%; display: flex; align-items: center; gap: 1em;"> | ||
${msg.trim()} | ${msg.trim()} | ||
<button id="runjobs-close">Aceptar</button> | <button id="runjobs-close">Aceptar</button> | ||
</div> | </div> | ||
); | |||
$('#runjobs-close').on('click', () => { | $('#runjobs-close').on('click', () => { | ||
| Línea 88: | Línea 90: | ||
}) | }) | ||
.catch(err => { | .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%;"> | ||
❌ Error de red: ${err} | ❌ Error de red: ${err} | ||
<button id="runjobs-close">Aceptar</button> | <button id="runjobs-close">Aceptar</button> | ||
</div> | </div> | ||
); | |||
$('#runjobs-close').on('click', () => { | $('#runjobs-close').on('click', () => { | ||
| Línea 102: | Línea 104: | ||
}); | }); | ||
// Mover el botón | // 🔹 Mover el botón debajo de "Reemplazar texto" | ||
const runJobsItem = $('#pt-runjobs').closest('li'); | const runJobsItem = $('#pt-runjobs').closest('li'); | ||
const target = $('a:contains("Reemplazar texto")').closest('li'); | const target = $('a:contains("Reemplazar texto")').closest('li'); | ||
| Línea 110: | Línea 112: | ||
} | } | ||
} | } | ||
// 🧼 Eliminar botones no deseados en cabecera flotante y menú responsive | |||
new MutationObserver(() => { | |||
document.querySelectorAll( | |||
.mw-sticky-header-element #ca-talk, | |||
.mw-sticky-header-element #ca-watch, | |||
.mw-sticky-header-element #ca-unwatch, | |||
.mw-sticky-header-element #ca-protect, | |||
.mw-sticky-header-element #ca-unprotect, | |||
#p-views #ca-talk, | |||
#p-views #ca-watch, | |||
#p-views #ca-unwatch, | |||
#p-views #ca-protect, | |||
#p-views #ca-unprotect | |||
).forEach(el => el.remove()); | |||
}).observe(document.body, { | |||
childList: true, | |||
subtree: true | |||
}); | |||
}); | }); | ||
Revisión del 02:55 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');
const action = mw.config.get('wgAction');
// Solo ejecutar personalizaciones en modo "view"
if (action === 'view') {
// 🛠️ Ocultar elementos si el usuario NO ha iniciado sesión y la skin es Vector-2022
if (user === null && skin === 'vector-2022') {
console.log("🛠️ Ocultando elementos para usuarios anónimos en Vector-2022");
// Ocultar menú herramientas completo, botón incluido
$('#vector-page-tools, #vector-page-tools-dropdown-checkbox, label[for="vector-page-tools-dropdown-checkbox"]').hide();
// Ocultar pestañas de historial y vista principal
$('#ca-view, #ca-history').hide();
// Ocultar pestañas de tipo de contenido ("Artículo", "Categoría", etc.)
$('#ca-nstab-main, #ca-nstab-category, #ca-nstab-special, #ca-nstab-image').closest('li').hide();
}
// 👤 Configuración personalizada para usuarios logueados con skin Vector-2022
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);
}
}
}
// 🧼 Eliminar botones no deseados en cabecera flotante y menú responsive
new MutationObserver(() => {
document.querySelectorAll(
.mw-sticky-header-element #ca-talk,
.mw-sticky-header-element #ca-watch,
.mw-sticky-header-element #ca-unwatch,
.mw-sticky-header-element #ca-protect,
.mw-sticky-header-element #ca-unprotect,
#p-views #ca-talk,
#p-views #ca-watch,
#p-views #ca-unwatch,
#p-views #ca-protect,
#p-views #ca-unprotect
).forEach(el => el.remove());
}).observe(document.body, {
childList: true,
subtree: true
});
});