// Add event listener to button document.getElementById("ssl").addEventListener("click", function () { getSSL(); }); // Add enter key listener to input document.getElementById("domain").addEventListener("keyup", function (event) { if (event.key === "Enter") { getSSL(); } }); function getSSL() { // Get the input value const domain = document.getElementById("domain").value.trim().toLowerCase(); // Set the domain parameter var params; if (window.location.search){ params = new URLSearchParams(window.location.search); params.set("domain", domain); } else { params = new URLSearchParams(); params.append("domain", domain); } // Add the parameters to the URL const url = `/?${params.toString()}`; // Push the URL to the history history.pushState(null, null, url); // Add a loading spinner document.getElementById("ssl-results").innerHTML = `
Loading...
`; // Send a GET request to the API fetch(`/api/v1/ssl/${domain}`) .then(response => response.json()) .then(data => { // Check if the request was successful if (data.success) { // Display the results document.getElementById("ssl-results").innerHTML = `

SSL Certificate Details

`; // Add event listeners for all toggle buttons document.querySelector('.tlsa-toggle').addEventListener('click', function() { const detailsDiv = document.querySelector('.tlsa-details'); if (detailsDiv.style.display === 'none') { detailsDiv.style.display = 'block'; this.textContent = 'Hide Details'; } else { detailsDiv.style.display = 'none'; this.textContent = 'Show Details'; } }); document.querySelector('.cert-toggle').addEventListener('click', function() { const certDiv = document.querySelector('.cert-details'); if (certDiv.style.display === 'none') { certDiv.style.display = 'block'; this.textContent = 'Hide Details'; } else { certDiv.style.display = 'none'; this.textContent = 'Show Details'; } }); document.querySelector('.dnssec-toggle').addEventListener('click', function() { const dnssecDiv = document.querySelector('.dnssec-details'); if (dnssecDiv.style.display === 'none') { dnssecDiv.style.display = 'block'; this.textContent = 'Hide Details'; } else { dnssecDiv.style.display = 'none'; this.textContent = 'Show Details'; } }); } else { // Display an error message document.getElementById("ssl-results").innerHTML = `

Error

${data.message}

`; } }) .catch(error => { // Display an error message document.getElementById("ssl-results").innerHTML = `

Error

${error.message}

`; }); } // On load check if params are present if (window.location.search) { const params = new URLSearchParams(window.location.search); const domain = params.get('domain'); if (domain) { // Add domain to input document.getElementById("domain").value = domain; getSSL(domain); } }