MediaWiki:Common.js
Apparence
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
function fallbackCopyText(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.setAttribute("readonly", "");
textarea.style.position = "absolute";
textarea.style.left = "-9999px";
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy");
} catch (err) {
console.error("Échec de la copie fallback :", err);
}
document.body.removeChild(textarea);
}
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.copy-button').forEach(button => {
button.addEventListener('click', function () {
const targetId = this.getAttribute('data-copy-target');
const target = document.getElementById(targetId);
if (!target) return;
const text = target.innerText || target.textContent;
// Essayons clipboard.writeText d'abord
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(() => {
this.textContent = '✅ Copié';
setTimeout(() => this.textContent = '📋 Copier', 2000);
}).catch(() => {
fallbackCopyText(text);
this.textContent = '📎 Copié';
setTimeout(() => this.textContent = '📋 Copier', 2000);
});
} else {
fallbackCopyText(text);
this.textContent = '📎 Copié';
setTimeout(() => this.textContent = '📋 Copier', 2000);
}
});
});
});