(function() { let locked = false; const input = $i('lookup-input'), submit = $i('lookup-submit'), result = $i('lookup-result'), tabs = $i('lookup-tabs'); const lock = function() { if(locked) return false; document.body.classList.add('whois-locked'); input.disabled = true; locked = true; return true; } const unlock = function() { if(!locked) return false; document.body.classList.remove('whois-locked'); input.disabled = false; locked = false; return true; } const lookup = function(target) { if(!lock()) return; $x.post('/whois/lookup', {}, { _csrfp: $csrfp.get(), target: target }).then(output => { let headers = output.headers(); if(headers.has('x-csrfp')) $csrfp.set(headers.get('x-csrfp')); let resp = output.json(); if(resp.error) alert(resp.text); let count = 0; tabs.innerHTML = ''; if(resp.result && resp.result.responses) for(const response of resp.result.responses) { const tab = document.createElement('a'), tabHeader = document.createElement('div'), tabServer = document.createElement('div'); tab.href = 'javascript:;'; tab.className = 'whois-result-tab'; if(count === 0) tab.className += ' whois-result-tab-active'; tab.onclick = function() { const active = $q('.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 = count === 0 ? 'Result' : ('Hop #' + (resp.result.responses.length - count).toString()); tabServer.className = 'whois-result-tab-server'; tabServer.textContent = response.server; tab.appendChild(tabHeader); tab.appendChild(tabServer); tabs.appendChild(tab); ++count; } if(tabs.firstChild) tabs.firstChild.click(); unlock(); }); } const readHash = function() { if(location.hash.length < 2) { result.textContent = 'Enter a domain or IP address!'; return; } const 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(); })();