« MediaWiki:Common.js » : différence entre les versions
Apparence
Aucun résumé des modifications Balise : Révoqué |
Aucun résumé des modifications Balise : Révoqué |
||
| Ligne 46 : | Ligne 46 : | ||
const doc = new DOMParser().parseFromString(html, "text/html"); | const doc = new DOMParser().parseFromString(html, "text/html"); | ||
const images = doc.querySelectorAll(".mw-parser-output img"); | |||
const images = | |||
let chosenImg = null; | |||
// on part de la FIN | |||
for (let i = images.length - 1; i >= 0; i--) { | |||
const | const img = images[i]; | ||
const width = parseInt(img.getAttribute("width") || "0"); | |||
// | // on ignore les petites icônes | ||
if ( | if (width > 80) { | ||
const srcset = | chosenImg = img; | ||
break; | |||
} | |||
} | |||
if (chosenImg) { | |||
let src = chosenImg.src; | |||
if (chosenImg.srcset) { | |||
const srcset = chosenImg.srcset.split(","); | |||
src = srcset[srcset.length - 1].split(" ")[0]; | src = srcset[srcset.length - 1].split(" ")[0]; | ||
} | } | ||
Version du 24 avril 2026 à 16:51
$(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");
let chosenImg = null;
// on part de la FIN
for (let i = images.length - 1; i >= 0; i--) {
const img = images[i];
const width = parseInt(img.getAttribute("width") || "0");
// on ignore les petites icônes
if (width > 80) {
chosenImg = img;
break;
}
}
if (chosenImg) {
let src = chosenImg.src;
if (chosenImg.srcset) {
const srcset = chosenImg.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";
});
});
});