email-dns-tools/assets/scripts/validator.js
2026-01-14 10:39:19 +01:00

39 lines
1.1 KiB
JavaScript

import { DmarcTool } from "./tools/DmarcTool.js";
const tools = {
"/dmarc-validator": DmarcTool,
};
const Tool = tools[location.pathname];
document.getElementById("input").oninput = event => validate(event.target.value);
if (document.getElementById("input").value !== "") {
validate(document.getElementById("input").value);
}
function validate(value) {
document.getElementById("input").classList.remove("valid", "invalid");
document.getElementById("error").style.display = "none"
document.getElementById("success").style.display = "none";
document.getElementById("result-placeholder").style.display = "none";
if (!value) {
document.getElementById("result-placeholder").style.display = "flex";
return;
}
const tool = new Tool(value);
try {
tool.validate();
document.getElementById("input").classList.add("valid");
document.getElementById("success").style.display = "flex";
} catch (e) {
document.getElementById("input").classList.add("invalid");
document.getElementById("error").style.display = "flex";
document.getElementById("error-message").innerText = e.message;
}
}