Modal: open antifragile + Category clear + popup fallback
This commit is contained in:
@@ -95,9 +95,26 @@
|
|||||||
/** @type {"correction"|"fact"|""} */
|
/** @type {"correction"|"fact"|""} */
|
||||||
let kind = "";
|
let kind = "";
|
||||||
|
|
||||||
|
const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
|
|
||||||
const upsertLine = (text, key, value) => {
|
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}`);
|
if (re.test(text)) return text.replace(re, `${key}: ${value}`);
|
||||||
|
|
||||||
|
// sinon append
|
||||||
const sep = text && !text.endsWith("\n") ? "\n" : "";
|
const sep = text && !text.endsWith("\n") ? "\n" : "";
|
||||||
return text + sep + `${key}: ${value}\n`;
|
return text + sep + `${key}: ${value}\n`;
|
||||||
};
|
};
|
||||||
@@ -171,12 +188,16 @@
|
|||||||
|
|
||||||
const cat = btn.getAttribute("data-category") || "";
|
const cat = btn.getAttribute("data-category") || "";
|
||||||
let body = pending.searchParams.get("body") || "";
|
let body = pending.searchParams.get("body") || "";
|
||||||
if (cat) body = upsertLine(body, "Category", cat);
|
body = upsertLine(body, "Category", cat);
|
||||||
|
|
||||||
|
|
||||||
pending.searchParams.set("body", body);
|
pending.searchParams.set("body", body);
|
||||||
|
|
||||||
|
const u = pending.toString();
|
||||||
dlg.close();
|
dlg.close();
|
||||||
window.open(pending.toString(), "_blank", "noopener,noreferrer");
|
|
||||||
|
const w = window.open(u, "_blank", "noopener,noreferrer");
|
||||||
|
if (!w) window.location.href = u;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user