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
Balise : Révoqué
Ligne 27 : Ligne 27 :


     links.forEach(link => {
     links.forEach(link => {
        let cacheImg = null;
         link.addEventListener("mouseenter", function (e) {
         link.addEventListener("mouseenter", function (e) {


             const pageTitle = link.getAttribute("title");
             const url = link.href;


             fetch("/wiki/api.php?action=query&titles=" + encodeURIComponent(pageTitle) + "&prop=pageimages&format=json&pithumbsize=200")
             if (cacheImg) {
                 .then(res => res.json())
                tooltip.innerHTML = "<img src='" + cacheImg + "'>";
                 .then(data => {
                 tooltip.style.display = "block";
                 return;
            }


                    const pages = data.query.pages;
            fetch(url)
                    const page = Object.values(pages)[0];
                .then(res => res.text())
                .then(html => {


                     if (page.thumbnail) {
                    const doc = new DOMParser().parseFromString(html, "text/html");
                         tooltip.innerHTML = "<img src='" + page.thumbnail.source + "'>";
                    const images = doc.querySelectorAll(".mw-parser-output img");
 
                     if (images.length > 0) {
                        const lastImg = images[images.length - 1];
                        cacheImg = lastImg.src;
 
                         tooltip.innerHTML = "<img src='" + cacheImg + "'>";
                     } else {
                     } else {
                         tooltip.innerHTML = "Pas d'image";
                         tooltip.innerHTML = "Pas d'image";
Ligne 59 : Ligne 71 :
             tooltip.style.display = "none";
             tooltip.style.display = "none";
         });
         });
     });
     });


});
});

Version du 24 avril 2026 à 16:45

$(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);

});

document.addEventListener("DOMContentLoaded", function () {

    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 => {

        let cacheImg = null;

        link.addEventListener("mouseenter", function (e) {

            const url = link.href;

            if (cacheImg) {
                tooltip.innerHTML = "<img src='" + cacheImg + "'>";
                tooltip.style.display = "block";
                return;
            }

            fetch(url)
                .then(res => res.text())
                .then(html => {

                    const doc = new DOMParser().parseFromString(html, "text/html");
                    const images = doc.querySelectorAll(".mw-parser-output img");

                    if (images.length > 0) {
                        const lastImg = images[images.length - 1];
                        cacheImg = lastImg.src;

                        tooltip.innerHTML = "<img src='" + cacheImg + "'>";
                    } else {
                        tooltip.innerHTML = "Pas d'image";
                    }

                    tooltip.style.display = "block";
                });

            tooltip.style.left = e.pageX + 10 + "px";
            tooltip.style.top = e.pageY + 10 + "px";
        });

        link.addEventListener("mousemove", function (e) {
            tooltip.style.left = e.pageX + 10 + "px";
            tooltip.style.top = e.pageY + 10 + "px";
        });

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

    });

});