var documentLocked = false; window.addEventListener('load', function() { document.getElementById('lookup-submit').addEventListener('click', function(ev) { ev.preventDefault(); whoisLookup(document.getElementById('lookup-input').value); }); }); window.addEventListener('popstate', function(ev) { if(!ev.state) return; document.getElementById('lookup-input').value = ev.state.target || ''; document.getElementById('lookup-result').innerText = ev.state.responseText || 'Enter a domain or IP address!'; }); function lockDocument() { if(documentLocked) return false; document.body.classList.add('locked'); document.getElementById('lookup-input').disabled = true; documentLocked = true; return true; } function freeDocument() { if(!documentLocked) return false; document.body.classList.remove('locked'); document.getElementById('lookup-input').disabled = false; documentLocked = false; return true; } function whoisLookup(domain) { if(!lockDocument()) return; var xhr = new XMLHttpRequest; xhr.addEventListener('readystatechange', function() { if(xhr.readyState != 4) return; var response = JSON.parse(xhr.responseText); history.pushState(response, null, location.pathname + '?domain=' + encodeURIComponent(domain)); document.getElementById('lookup-result').innerText = response.responseText; freeDocument(); }); xhr.open('GET', whoisUrl + '?ajax=1&domain=' + encodeURIComponent(domain)); xhr.send(); }