import { DmarcTool } from "./tools/DmarcTool.js"; const tools = { "/dmarc-creator": DmarcTool, }; const Tool = tools[location.pathname]; addFields(document.getElementById("form"), Tool.fields.filter(field => !field.categoryName)); const categories = Tool.fields.map(field => field.categoryName).filter(isUnique).filter(val => val); for (const category of categories) { const details = document.createElement("details"); details.innerHTML = `${Tool.categories[category]}`; document.getElementById("form").appendChild(details); addFields(details, Tool.fields.filter(field => field.categoryName === category)); } function addFields(elem, fields) { for (const field of fields) { if (!field.getInputHtml()) continue; elem.innerHTML += `

${field.description ?? ""}

${field.getInputHtml()} `; } } document.getElementById("form").onchange = () => generate(); generate(); function generate() { const tool = new Tool(); document.getElementById("record").value = tool.fieldsToString(); } function isUnique(value, index, array) { return array.indexOf(value) === index; }