Diferencia entre revisiones de «MediaWiki:Common.js»
Página de la interfaz de MediaWiki
Más acciones
Sin resumen de edición Etiqueta: Revertido |
Sin resumen de edición Etiqueta: Revertido |
||
| Línea 2: | Línea 2: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
$('div.syntaxhighlighter').each(function() { | $('div.syntaxhighlighter').each(function() { | ||
// | // Evita duplicar botones | ||
if ($(this).find('.copy-btn').length === 0) { | if ($(this).find('.copy-btn').length === 0) { | ||
// | // Botón con emoji de portapapeles | ||
const btn = $('<button class="copy-btn"> | const btn = $('<button class="copy-btn">📋</button>'); | ||
$(this).prepend(btn); | $(this).prepend(btn); | ||
// Evento click | // Evento click: copia el texto del bloque | ||
btn.on('click', () => { | btn.on('click', () => { | ||
const textToCopy = $(this).text(); | const textToCopy = $(this).text(); | ||
navigator.clipboard.writeText(textToCopy).then(() => { | navigator.clipboard.writeText(textToCopy).then(() => { | ||
btn.text('✔'); | btn.text('✔'); // mostrar ✔ al copiar | ||
setTimeout(() => btn.text(' | setTimeout(() => btn.text('📋'), 1000); // volver al emoji | ||
}); | }); | ||
}); | }); | ||
Revisión del 12:39 26 ene 2026
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
$(document).ready(function() {
$('div.syntaxhighlighter').each(function() {
// Evita duplicar botones
if ($(this).find('.copy-btn').length === 0) {
// Botón con emoji de portapapeles
const btn = $('<button class="copy-btn">📋</button>');
$(this).prepend(btn);
// Evento click: copia el texto del bloque
btn.on('click', () => {
const textToCopy = $(this).text();
navigator.clipboard.writeText(textToCopy).then(() => {
btn.text('✔'); // mostrar ✔ al copiar
setTimeout(() => btn.text('📋'), 1000); // volver al emoji
});
});
}
});
});