(function() { var locked = false, input = document.getElementById('lookup-input'), submit = document.getElementById('lookup-submit'), result = document.getElementById('lookup-result'), tabs = document.getElementById('lookup-tabs'); var lock = function() { if(locked) return false; document.body.classList.add('whois-locked'); input.disabled = true; locked = true; return true; } var unlock = function() { if(!locked) return false; document.body.classList.remove('whois-locked'); input.disabled = false; locked = false; return true; } var lookup = function(target) { if(!lock()) return; var xhr = new XMLHttpRequest; xhr.addEventListener('load', function() { var resp = JSON.parse(xhr.responseText); if(resp.error) alert(resp.text); tabs.innerHTML = ''; if(resp.result && resp.result.responses) { for(var i = 0; i < resp.result.responses.length; ++i) { (function(response) { var tab = document.createElement('a'), tabHeader = document.createElement('div'), tabServer = document.createElement('div'); tab.href = 'javascript:;'; tab.className = 'whois-result-tab'; if(i === 0) tab.className += ' whois-result-tab-active'; tab.onclick = function() { var active = document.querySelector('.whois-result-tab-active'); if(active) active.classList.remove('whois-result-tab-active'); tab.classList.add('whois-result-tab-active'); result.textContent = response.lines.join("\r\n").trim(); }; tabHeader.className = 'whois-result-tab-header'; tabHeader.textContent = i === 0 ? 'Result' : ('Hop #' + (resp.result.responses.length - i).toString()); tabServer.className = 'whois-result-tab-server'; tabServer.textContent = response.server; console.log(response); tab.appendChild(tabHeader); tab.appendChild(tabServer); tabs.appendChild(tab); })(resp.result.responses[i]); } } if(tabs.firstChild) tabs.firstChild.click(); unlock(); }); xhr.open('GET', '/whois/lookup?target=' + encodeURIComponent(target)); xhr.send(); } var readHash = function() { if(location.hash.length < 2) { result.textContent = 'Enter a domain or IP address!'; return; } var target = decodeURIComponent(location.hash.substring(1)); if(input.value !== target) input.value = target; lookup(target); }; window.addEventListener('hashchange', function(ev) { readHash(); }, false); submit.addEventListener('click', function(ev) { ev.preventDefault(); location.hash = encodeURIComponent(input.value); }); readHash(); })();