47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
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 = `<summary>${Tool.categories[category]}</summary>`;
|
|
|
|
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 += `
|
|
<label for="${field.key}">${field.displayName}</label>
|
|
<p class="description">${field.description ?? ""}</p>
|
|
${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;
|
|
}
|