fix(affichage): affichage dans download

This commit is contained in:
BlackAngelTV committed 2026-08-24 15:05:36 +02:00
1 parent ae289cffa3
commit 3f8cff47bf
5 files changed
+389 -25

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
.freebuff/
gestionnaire/
+1
View File
@@ -0,0 +1 @@
Options +Indexes
+272 -23
View File
@@ -1,8 +1,8 @@
(() => {
const OWNER = "You-re-like-Windows-a-bitch";
const REPO = "ISO";
const RELEASES_URL = `https://api.github.com/repos/${OWNER}/${REPO}/releases?per_page=6`;
const TAGS_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=6`;
const RELEASES_URL = `https://api.github.com/repos/${OWNER}/${REPO}/releases?per_page=5`;
const TAGS_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=5`;
const REPO_URL = `https://github.com/${OWNER}/${REPO}`;
const currentVersionNode = document.querySelector("[data-current-version]");
@@ -11,6 +11,10 @@
const latestDownloadNode = document.querySelector("[data-latest-download]");
const viewMoreNode = document.querySelector("[data-view-more]");
const versionsListNode = document.querySelector("[data-versions-list]");
const toggleNoteNode = document.querySelector("[data-toggle-release-note]");
let fullReleaseBodyHtml = "";
const TRUNCATE_LENGTH = 600;
function formatDate(value) {
if (!value) return "";
@@ -29,7 +33,7 @@
function getReleasePageUrl(entry, mode) {
if (mode === "releases") {
return entry?.html_url || REPO_URL;
return pickDirectDownloadUrl(entry);
}
if (entry?.name) {
@@ -39,37 +43,274 @@
return REPO_URL;
}
function sanitizeReleaseHtml(html) {
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
function parseInline(text) {
let result = escapeHtml(text);
result = result.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>");
result = result.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
result = result.replace(/\*(.+?)\*/g, "<em>$1</em>");
result = result.replace(/`([^`]+)`/g, "<code>$1</code>");
result = result.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img alt="$1" src="$2" loading="lazy">');
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
return result;
}
function renderMarkdown(md) {
if (!md) return "";
var lines = md.split(/\r?\n/);
var html = "";
var inCodeBlock = false;
var codeBlockContent = "";
var codeBlockLang = "";
var listBuffer = "";
var listKind = "";
var tableRows = [];
var tableHeader = true;
var blockquoteBuffer = "";
function flushList() {
if (listBuffer) {
html += "<" + listKind + ">\n" + listBuffer + "</" + listKind + ">\n";
listBuffer = "";
listKind = "";
}
}
function flushTable() {
if (tableRows.length) {
html += "<table>\n" + tableRows.join("\n") + "\n</table>\n";
tableRows = [];
tableHeader = true;
}
}
function flushBlockquote() {
if (blockquoteBuffer) {
html += "<blockquote>" + blockquoteBuffer + "</blockquote>\n";
blockquoteBuffer = "";
}
}
function parseTableCells(line) {
var trimmed = line.replace(/^\|/, "").replace(/\|$/, "");
return trimmed.split("|").map(function (c) { return c.trim(); });
}
function isTableSep(line) {
return /^\|?[\s|:\-]+\|?$/.test(line) && line.indexOf("-") !== -1;
}
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.startsWith("```")) {
flushBlockquote();
flushList();
flushTable();
if (inCodeBlock) {
var langAttr = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : "";
html += "<pre><code" + langAttr + ">" + escapeHtml(codeBlockContent.trim()) + "</code></pre>\n";
codeBlockContent = "";
codeBlockLang = "";
inCodeBlock = false;
} else {
inCodeBlock = true;
codeBlockLang = line.slice(3).trim();
}
continue;
}
if (inCodeBlock) {
codeBlockContent += (codeBlockContent ? "\n" : "") + line;
continue;
}
if (line.trim() === "") {
flushBlockquote();
flushList();
flushTable();
continue;
}
var hMatch = line.match(/^(#{1,6})\s+(.+)$/);
if (hMatch) {
flushBlockquote();
flushList();
flushTable();
var level = hMatch[1].length;
html += "<h" + level + ">" + parseInline(hMatch[2]) + "</h" + level + ">\n";
continue;
}
if (/^[-*_]{3,}\s*$/.test(line.trim())) {
flushBlockquote();
flushList();
flushTable();
html += "<hr>\n";
continue;
}
if (line.startsWith("> ") || line.startsWith(">")) {
flushList();
flushTable();
var content = line.replace(/^>\s?/, "");
blockquoteBuffer += "<p>" + parseInline(content) + "</p>";
continue;
} else {
flushBlockquote();
}
if (line.includes("|") && !isTableSep(line)) {
flushList();
var cells = parseTableCells(line);
var tag = tableHeader ? "th" : "td";
tableRows.push("<tr>" + cells.map(function (c) { return "<" + tag + ">" + parseInline(c) + "</" + tag + ">"; }).join("") + "</tr>");
if (tableHeader) tableHeader = false;
continue;
}
if (isTableSep(line)) {
tableHeader = false;
continue;
}
if (line.includes("|")) {
flushTable();
}
var ulMatch = line.match(/^(\s*)[-*+]\s+(.+)$/);
if (ulMatch) {
flushTable();
if (listKind !== "ul") {
flushList();
listKind = "ul";
}
listBuffer += "<li>" + parseInline(ulMatch[2]) + "</li>\n";
continue;
}
var olMatch = line.match(/^(\s*)\d+\.\s+(.+)$/);
if (olMatch) {
flushTable();
if (listKind !== "ol") {
flushList();
listKind = "ol";
}
listBuffer += "<li>" + parseInline(olMatch[2]) + "</li>\n";
continue;
}
if (listBuffer && /^\s{2,}/.test(line)) {
listBuffer = listBuffer.replace(/<\/li>\n$/, " " + parseInline(line.trim()) + "</li>\n");
continue;
}
flushList();
flushTable();
html += "<p>" + parseInline(line) + "</p>\n";
}
flushBlockquote();
flushList();
flushTable();
if (inCodeBlock) {
var langAttr2 = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : "";
html += "<pre><code" + langAttr2 + ">" + escapeHtml(codeBlockContent.trim()) + "</code></pre>\n";
}
return html;
}
function sanitizeRenderedHtml(rawHtml) {
const wrapper = document.createElement("div");
wrapper.innerHTML = html || "";
wrapper.innerHTML = rawHtml;
wrapper.querySelectorAll("script, iframe, object, embed, link, style").forEach((node) => node.remove());
wrapper.querySelectorAll("*").forEach((node) => {
Array.from(node.attributes).forEach((attribute) => {
const name = attribute.name.toLowerCase();
const value = attribute.value || "";
if (name.startsWith("on")) {
node.removeAttribute(attribute.name);
return;
}
if ((name === "href" || name === "src") && /^javascript:/i.test(value)) {
node.removeAttribute(attribute.name);
}
wrapper.querySelectorAll("script, iframe, object, embed, link, style").forEach(function (node) { node.remove(); });
wrapper.querySelectorAll("*").forEach(function (node) {
Array.from(node.attributes).forEach(function (attribute) {
var name = attribute.name.toLowerCase();
var value = attribute.value || "";
if (name.startsWith("on")) { node.removeAttribute(attribute.name); return; }
if ((name === "href" || name === "src") && /^javascript:/i.test(value)) { node.removeAttribute(attribute.name); }
});
});
return wrapper.innerHTML;
}
function truncateHtml(fullHtml) {
var temp = document.createElement("div");
temp.innerHTML = fullHtml;
var text = temp.textContent || "";
if (text.length <= TRUNCATE_LENGTH) {
return { html: fullHtml, truncated: false };
}
var acc = "";
var count = 0;
var truncatedHtml = "";
var children = Array.from(temp.childNodes);
for (var ci = 0; ci < children.length; ci++) {
var child = children[ci];
var childText = child.textContent || "";
if (count + childText.length > TRUNCATE_LENGTH && count > 0) {
break;
}
if (child.nodeType === Node.ELEMENT_NODE) {
truncatedHtml += child.outerHTML;
} else {
var remaining = TRUNCATE_LENGTH - count;
if (childText.length > remaining) {
truncatedHtml += escapeHtml(childText.slice(0, remaining)) + "…";
count = TRUNCATE_LENGTH;
break;
}
truncatedHtml += escapeHtml(childText);
}
count += childText.length;
}
return { html: truncatedHtml, truncated: true };
}
function setupToggle() {
if (!toggleNoteNode || !currentReleaseNoteNode) return;
toggleNoteNode.addEventListener("click", function () {
var expanded = toggleNoteNode.dataset.expanded === "true";
if (expanded) {
var result = truncateHtml(fullReleaseBodyHtml);
currentReleaseNoteNode.innerHTML = result.html;
toggleNoteNode.textContent = "Voir plus";
toggleNoteNode.dataset.expanded = "false";
} else {
currentReleaseNoteNode.innerHTML = fullReleaseBodyHtml;
toggleNoteNode.textContent = "Voir moins";
toggleNoteNode.dataset.expanded = "true";
}
});
}
setupToggle();
function pickDirectDownloadUrl(release) {
const assets = Array.isArray(release?.assets) ? release.assets : [];
const isoAsset = assets.find((asset) => /\.iso$/i.test(asset?.name || ""));
const directAsset = isoAsset || assets[0];
if (directAsset) {
return directAsset.browser_download_url || directAsset.url || release.html_url || REPO_URL;
return directAsset.browser_download_url || release.html_url || REPO_URL;
}
return release?.zipball_url || release?.html_url || REPO_URL;
@@ -163,15 +404,22 @@
if (currentVersionNode) currentVersionNode.textContent = latestLabel;
if (currentVersionDateNode) currentVersionDateNode.textContent = latestDate ? ` · ${latestDate}` : "";
if (currentReleaseNoteNode) {
const bodyHtml = sanitizeReleaseHtml(latest.body || "");
currentReleaseNoteNode.innerHTML = bodyHtml || "Release GitHub la plus récente.";
fullReleaseBodyHtml = sanitizeRenderedHtml(renderMarkdown(latest.body || ""));
var result = truncateHtml(fullReleaseBodyHtml);
currentReleaseNoteNode.innerHTML = result.html || "<p>Release GitHub la plus récente.</p>";
if (toggleNoteNode) {
toggleNoteNode.style.display = result.truncated ? "inline-block" : "none";
toggleNoteNode.dataset.expanded = "false";
toggleNoteNode.textContent = "Voir plus";
}
}
if (latestDownloadNode) latestDownloadNode.href = latest.html_url || REPO_URL;
if (latestDownloadNode) latestDownloadNode.href = latestDownloadUrl;
renderList(releases, "releases");
return;
}
} catch (error) {
console.error("Erreur fetch releases:", error.message);
// On tente le fallback tags ci-dessous.
}
@@ -200,6 +448,7 @@
}
renderEmptyState("Aucune release trouvée", "Le dépôt ne renvoie ni release ni tag public.");
} catch (error) {
console.error("Erreur fetch tags:", error.message);
if (currentVersionNode) currentVersionNode.textContent = "Impossible de charger les releases";
if (currentReleaseNoteNode) {
currentReleaseNoteNode.textContent = `Erreur: ${error.message}. Vérifie que le repo GitHub est public et qu'il expose des releases ou des tags.`;
+111
View File
@@ -32,6 +32,100 @@
margin: 0.85rem 0 0;
color: var(--muted);
line-height: 1.6;
max-height: none;
overflow: visible;
}
.latest-note h1,
.latest-note h2,
.latest-note h3,
.latest-note h4 {
color: #e2e8f0;
margin: 1.2rem 0 0.5rem;
}
.latest-note h2 {
font-size: 1.2rem;
}
.latest-note h3 {
font-size: 1.05rem;
}
.latest-note p {
margin: 0.5rem 0;
}
.latest-note ul,
.latest-note ol {
margin: 0.4rem 0;
padding-left: 1.4rem;
}
.latest-note li {
margin: 0.25rem 0;
}
.latest-note table {
width: 100%;
border-collapse: collapse;
margin: 0.75rem 0;
font-size: 0.92rem;
}
.latest-note th,
.latest-note td {
padding: 0.45rem 0.65rem;
border: 1px solid rgba(148, 163, 184, 0.18);
text-align: left;
}
.latest-note th {
background: rgba(148, 163, 184, 0.08);
font-weight: 600;
color: #cbd5e1;
}
.latest-note blockquote {
margin: 0.6rem 0;
padding: 0.5rem 0.9rem;
border-left: 3px solid #7dd3fc;
background: rgba(125, 211, 252, 0.06);
border-radius: 0 0.4rem 0.4rem 0;
color: #b0bec5;
}
.latest-note blockquote p {
margin: 0;
}
.latest-note code {
background: rgba(148, 163, 184, 0.12);
padding: 0.15em 0.4em;
border-radius: 0.3rem;
font-size: 0.9em;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
.latest-note pre {
background: rgba(2, 6, 23, 0.5);
border: 1px solid rgba(148, 163, 184, 0.12);
border-radius: 0.5rem;
padding: 0.8rem 1rem;
overflow-x: auto;
margin: 0.6rem 0;
}
.latest-note pre code {
background: none;
padding: 0;
font-size: 0.88rem;
}
.latest-note hr {
border: none;
border-top: 1px solid rgba(148, 163, 184, 0.15);
margin: 1rem 0;
}
.latest-note img {
@@ -51,6 +145,23 @@
text-decoration: underline;
}
.toggle-note {
display: inline-block;
margin-top: 0.5rem;
padding: 0.35rem 0.9rem;
font-size: 0.88rem;
background: rgba(125, 211, 252, 0.08);
color: #7dd3fc;
border: 1px solid rgba(125, 211, 252, 0.2);
border-radius: 0.4rem;
cursor: pointer;
transition: background 0.2s;
}
.toggle-note:hover {
background: rgba(125, 211, 252, 0.16);
}
.versions-archive {
margin-top: 1rem;
}
+3 -2
View File
@@ -25,11 +25,12 @@
<a class="button" data-latest-download href="#" target="_blank" rel="noreferrer">Télécharger</a>
</div>
</div>
<p class="latest-note" data-current-release-note></p>
<div class="latest-note" data-current-release-note></div>
<button class="toggle-note" data-toggle-release-note style="display:none">Voir plus</button>
</div>
<div class="versions-archive">
<h3>5 versions précédentes</h3>
<h3>Versions précédentes</h3>
<ul class="versions-list" data-versions-list></ul>
</div>
</div>