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
 
(11 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;
 
    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 pageTitle = link.getAttribute("title");
 
            fetch("/wiki/api.php?action=query&titles=" + encodeURIComponent(pageTitle) + "&prop=pageimages&format=json&pithumbsize=200")
                .then(res => res.json())
                .then(data => {
 
                    const pages = data.query.pages;
                    const page = Object.values(pages)[0];
 
                    if (page.thumbnail) {
                        tooltip.innerHTML = "<img src='" + page.thumbnail.source + "'>";
                    } else {
                        tooltip.innerHTML = "Pas d'image";
                    }


                    tooltip.style.display = "block";
    $content.find('table.fandom-table td, table.wikitable td').each(function () {
                });


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


         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');
        }

    });

});