email-dns-tools/assets/scripts/validator.js
2026-01-14 15:46:37 +01:00

41 lines
1.2 KiB
JavaScript

import { DmarcTool } from "./tools/DmarcTool.js";
import { SpfTool } from "./tools/SpfTool.js";
const tools = {
"/dmarc-validator": DmarcTool,
"/spf-validator": SpfTool,
};
const Tool = tools[location.pathname];
document.getElementById("record").oninput = event => validate(event.target.value);
if (document.getElementById("record").value !== "") {
validate(document.getElementById("record").value);
}
function validate(value) {
document.getElementById("record").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("record").classList.add("valid");
document.getElementById("success").style.display = "flex";
} catch (e) {
document.getElementById("record").classList.add("invalid");
document.getElementById("error").style.display = "flex";
document.getElementById("error-message").innerText = e.message;
}
}