(() => {
const OWNER = "You-re-like-Windows-a-bitch";
const REPO = "ISO";
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]");
const currentVersionDateNode = document.querySelector("[data-current-version-date]");
const currentReleaseNoteNode = document.querySelector("[data-current-release-note]");
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 "";
const date = new Date(value);
if (Number.isNaN(date.getTime())) return "";
return date.toLocaleDateString("fr-FR", {
year: "numeric",
month: "long",
day: "numeric",
});
}
function getReleaseLabel(entry) {
return entry?.name || entry?.tag_name || entry?.ref || "Sans nom";
}
function getReleasePageUrl(entry, mode) {
if (mode === "releases") {
return pickDirectDownloadUrl(entry);
}
if (entry?.name) {
return `${REPO_URL}/releases/tag/${encodeURIComponent(entry.name)}`;
}
return REPO_URL;
}
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(//g, ">");
}
function parseInline(text) {
let result = escapeHtml(text);
result = result.replace(/\*\*\*(.+?)\*\*\*/g, "$1");
result = result.replace(/\*\*(.+?)\*\*/g, "$1");
result = result.replace(/\*(.+?)\*/g, "$1");
result = result.replace(/`([^`]+)`/g, "$1");
result = result.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '');
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1');
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 += "
" + blockquoteBuffer + "\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 += "
" + escapeHtml(codeBlockContent.trim()) + "\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 += "" + parseInline(content) + "
"; continue; } else { flushBlockquote(); } if (line.includes("|") && !isTableSep(line)) { flushList(); var cells = parseTableCells(line); var tag = tableHeader ? "th" : "td"; tableRows.push("" + parseInline(line) + "
\n"; } flushBlockquote(); flushList(); flushTable(); if (inCodeBlock) { var langAttr2 = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : ""; html += "" + escapeHtml(codeBlockContent.trim()) + "\n";
}
return html;
}
function sanitizeRenderedHtml(rawHtml) {
const wrapper = document.createElement("div");
wrapper.innerHTML = rawHtml;
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 || release.html_url || REPO_URL;
}
return release?.zipball_url || release?.html_url || REPO_URL;
}
function renderEmptyState(title, message) {
if (!versionsListNode) return;
versionsListNode.innerHTML = `
Release GitHub la plus récente.
"; if (toggleNoteNode) { toggleNoteNode.style.display = result.truncated ? "inline-block" : "none"; toggleNoteNode.dataset.expanded = "false"; toggleNoteNode.textContent = "Voir plus"; } } 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. } try { const tags = await fetchJson(TAGS_URL); if (Array.isArray(tags) && tags.length > 0) { const latestTag = tags[0]; const latestLabel = getReleaseLabel(latestTag); const latestDownloadUrl = `${REPO_URL}/releases/tag/${encodeURIComponent(latestTag.name)}`; if (currentVersionNode) currentVersionNode.textContent = `${latestLabel} (tag)`; if (currentVersionDateNode) currentVersionDateNode.textContent = ""; if (currentReleaseNoteNode) { currentReleaseNoteNode.textContent = "Aucune release GitHub publiée pour le moment, affichage des tags du dépôt."; } if (latestDownloadNode) latestDownloadNode.href = latestDownloadUrl; renderList(tags, "tags"); return; } if (currentVersionNode) currentVersionNode.textContent = "Aucune release trouvée"; if (currentReleaseNoteNode) { currentReleaseNoteNode.textContent = "Le dépôt ne renvoie ni release ni tag public."; } 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.`; } renderEmptyState("Impossible de charger les releases", "Ouvre le repo GitHub pour vérifier les releases ou les tags."); } } loadReleases(); })();