Aller au contenu

« MediaWiki:Common.js » : différence entre les versions

De WikiName
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
 
(12 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
$(function () {
$(function () {


Ligne 15 : Ligne 16 :


});
});
/* ============================= */
/* DÉTECTION AUTOMATIQUE DES VALEURS NUMÉRIQUES */
/* ============================= */


document.addEventListener("DOMContentLoaded", function () {
mw.hook('wikipage.content').add(function ($content) {
 
    if (!document.body.classList.contains("ns-14")) return; // uniquement pages catégories
 
    const links = document.querySelectorAll(".mw-category a");
 
    const tooltip = document.createElement("div");
    tooltip.className = "category-tooltip";
    document.body.appendChild(tooltip);
 
    links.forEach(link => {
        link.addEventListener("mouseenter", function (e) {
            const pageName = link.getAttribute("title");
 
            // chemin image basé sur nom de page (à adapter si besoin)
            const imgSrc = "/wiki/images/" + pageName + ".webp";


            tooltip.innerHTML = "<img src='" + imgSrc + "'>";
    $content.find('table.fandom-table td, table.wikitable td').each(function () {


            tooltip.style.display = "block";
        const cell = $(this);
            tooltip.style.left = e.pageX + 10 + "px";
        const text = cell.text().trim();
            tooltip.style.top = e.pageY + 10 + "px";
        });


         link.addEventListener("mousemove", function (e) {
         // Nombre entier, décimal, positif/négatif, avec éventuellement %
             tooltip.style.left = e.pageX + 10 + "px";
        if (/^[+-]?\d+(?:[.,]\d+)?%?$/.test(text)) {
            tooltip.style.top = e.pageY + 10 + "px";
             cell.addClass('pne-number');
         });
         }


        link.addEventListener("mouseleave", function () {
            tooltip.style.display = "none";
        });
     });
     });


});
});

Dernière version du 10 août 2026 à 16:01


$(function () {

    const header = document.querySelector('.vector-header-end');
    if (!header) return;

    const container = document.createElement('div');
    container.className = "pne-header-links";

    container.innerHTML = `
<a href="/wiki/index.php/Spécial:Toutes_les_pages">Parcourir</a>
<a href="/wiki/index.php/Spécial:Catégories">Catégories</a>
    `;

    header.prepend(container);

});
/* ============================= */
/* DÉTECTION AUTOMATIQUE DES VALEURS NUMÉRIQUES */
/* ============================= */

mw.hook('wikipage.content').add(function ($content) {

    $content.find('table.fandom-table td, table.wikitable td').each(function () {

        const cell = $(this);
        const text = cell.text().trim();

        // Nombre entier, décimal, positif/négatif, avec éventuellement %
        if (/^[+-]?\d+(?:[.,]\d+)?%?$/.test(text)) {
            cell.addClass('pne-number');
        }

    });

});