feat/proposer-antifragile #31

Merged
Archicratia merged 4 commits from feat/proposer-antifragile into master 2026-01-19 21:30:26 +01:00
Showing only changes of commit 0149c132bb - Show all commits

View File

@@ -95,9 +95,26 @@
/** @type {"correction"|"fact"|""} */
let kind = "";
const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const upsertLine = (text, key, value) => {
const re = new RegExp(`^\\s*${key}\\s*:\\s*.*$`, "mi");
const re = new RegExp(`^\\s*${esc(key)}\\s*:\\s*.*$`, "mi");
// value vide => supprimer la ligne si elle existe
if (!value) {
if (!re.test(text)) return text;
return (
text
.replace(re, "")
.replace(/\n{3,}/g, "\n\n")
.trimEnd() + "\n"
);
}
// remplace si existe
if (re.test(text)) return text.replace(re, `${key}: ${value}`);
// sinon append
const sep = text && !text.endsWith("\n") ? "\n" : "";
return text + sep + `${key}: ${value}\n`;
};
@@ -171,12 +188,16 @@
const cat = btn.getAttribute("data-category") || "";
let body = pending.searchParams.get("body") || "";
if (cat) body = upsertLine(body, "Category", cat);
body = upsertLine(body, "Category", cat);
pending.searchParams.set("body", body);
const u = pending.toString();
dlg.close();
window.open(pending.toString(), "_blank", "noopener,noreferrer");
const w = window.open(u, "_blank", "noopener,noreferrer");
if (!w) window.location.href = u;
});
})();
</script>