Skip to content

Commit

Permalink
feat: remove redundant map for nameserver
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Mar 10, 2021
1 parent 27fa414 commit 0dc61ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
23 changes: 5 additions & 18 deletions cmd/doggo/api/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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");
Expand All @@ -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()
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/doggo/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ <h1 class="text-5xl font-black text-center"><span class="text-indigo-700">Doggo<
</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>
Expand Down

0 comments on commit 0dc61ac

Please sign in to comment.