|
|
| Ligne 13 : |
Ligne 13 : |
|
| |
|
| header.prepend(container); | | 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");
| |
|
| |
| // CIBLE EXACTE : images centrées (tes images finales)
| |
| const figures = doc.querySelectorAll(".mw-parser-output figure.mw-halign-center img");
| |
|
| |
| if (figures.length > 0) {
| |
|
| |
| const lastImg = figures[figures.length - 1];
| |
|
| |
| let src = lastImg.src;
| |
|
| |
| if (lastImg.srcset) {
| |
| const srcset = lastImg.srcset.split(",");
| |
| src = srcset[srcset.length - 1].split(" ")[0];
| |
| }
| |
|
| |
| cacheImg = src;
| |
|
| |
| tooltip.innerHTML = "<img src='" + cacheImg + "'>";
| |
| } else {
| |
| tooltip.innerHTML = "<span>Pas d'image</span>";
| |
| }
| |
|
| |
| tooltip.style.display = "block";
| |
| });
| |
|
| |
| tooltip.style.left = e.pageX + 15 + "px";
| |
| tooltip.style.top = e.pageY + 15 + "px";
| |
| });
| |
|
| |
| link.addEventListener("mousemove", function (e) {
| |
| tooltip.style.left = e.pageX + 15 + "px";
| |
| tooltip.style.top = e.pageY + 15 + "px";
| |
| });
| |
|
| |
| link.addEventListener("mouseleave", function () {
| |
| tooltip.style.display = "none";
| |
| });
| |
|
| |
| });
| |
|
| |
|
| }); | | }); |