feat: remove redundant map for nameserver

pull/16/head
Karan Sharma 2021-03-10 16:41:55 +05:30
parent 27fa414ca9
commit 0dc61ac8ec
2 changed files with 9 additions and 22 deletions

View File

@ -2,13 +2,6 @@ const $ = document.querySelector.bind(document);
const $new = document.createElement.bind(document);
const apiURL = "/api/lookup/";
const isMobile = window.matchMedia("only screen and (max-width: 760px)").matches;
const nsAddrMap = {
"google": "8.8.8.8",
"cloudflare": "1.1.1.1",
"cloudflare-doh": "https://cloudflare-dns.com/dns-query",
"quad9": "9.9.9.9",
}
function handleNSChange() {
if ($('select[name=ns]').value == "custom") {
@ -17,7 +10,7 @@ function handleNSChange() {
} else {
$('div[id=custom_ns]').classList.add("hidden");
$('div[id=ns]').classList.remove("hidden");
$('input[name=ns]').placeholder = nsAddrMap[$('select[name=ns]').value];
$('input[name=ns]').placeholder = $('select[name=ns]').value;
}
}
@ -60,7 +53,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
// createList creates a table row with the given cell values.
// `createList` creates a table row with the given cell values.
function createList(item) {
const ul = $new('ul');
ul.classList.add("m-4", "block", "bg-indigo-100");
@ -77,18 +70,12 @@ window.addEventListener('DOMContentLoaded', (event) => {
function prepareNSAddr(ns) {
switch (ns) {
case "google":
return "tcp://8.8.8.8:53"
case "cloudflare":
return "tcp://1.1.1.1:53"
case "cloudflare-doh":
return "https://cloudflare-dns.com/dns-query"
case "quad9":
return "tcp://9.9.9.9:53"
// If it's a custom nameserver, get the value from the user's input.
case "custom":
return $('input[name=custom_ns]').value.trim()
// Else get it from the select dropdown field.
default:
return ""
return $('select[name=ns]').value.trim()
}
}

View File

@ -70,10 +70,10 @@
</label>
<select name="ns" onchange="handleNSChange()"
class="w-full border-gray-300 rounded-lg shadown-sm focus:border-indigo-500 focus:ring-indigo-500">
<option default value="cloudflare">Cloudflare</option>
<option value="cloudflare-doh">Cloudflare (DOH)</option>
<option value="google">Google</option>
<option value="quad9">Quad9</option>
<option default value="tcp://1.1.1.1:53">Cloudflare</option>
<option value="https://cloudflare-dns.com/dns-query">Cloudflare (DOH)</option>
<option value="tcp://8.8.8.8:53">Google</option>
<option value="tcp://9.9.9.9:53">Quad9</option>
<option value="custom">Custom</option>
</select>
</div>