mckabue commited on
Commit
9368514
·
1 Parent(s): 27010b4

Refactor script to improve structure and maintainability

Browse files
Files changed (1) hide show
  1. index.html +20 -16
index.html CHANGED
@@ -73,22 +73,7 @@
73
  </div>
74
 
75
  <script>
76
- document.addEventListener("DOMContentLoaded", () => {
77
- const domain = [...new URL(location.href).searchParams]
78
- .find(([key, value]) => key?.toLowerCase()?.trim() === "domain")?.[1]
79
- ?.toLowerCase()
80
- ?.trim();
81
- if ((domain || "").length > 0) {
82
- document.getElementById("domain").value = domain;
83
- }
84
- });
85
- document.getElementById("searchForm").onsubmit = async (e) => {
86
- e.preventDefault();
87
- const domain = document.getElementById("domain").value;
88
- if ((domain || "").trim().length == 0) {
89
- return;
90
- }
91
-
92
  const result = document.getElementById("result");
93
  const spinner = document.getElementById("spinner");
94
  const resultText = document.getElementById("resultText");
@@ -126,6 +111,25 @@
126
  }
127
  spinner.classList.add("d-none");
128
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  </script>
130
  </body>
131
  </html>
 
73
  </div>
74
 
75
  <script>
76
+ const submitFn = async (domain) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  const result = document.getElementById("result");
78
  const spinner = document.getElementById("spinner");
79
  const resultText = document.getElementById("resultText");
 
111
  }
112
  spinner.classList.add("d-none");
113
  };
114
+ document.addEventListener("DOMContentLoaded", () => {
115
+ const domain = [...new URL(location.href).searchParams]
116
+ .find(([key, value]) => key?.toLowerCase()?.trim() === "domain")?.[1]
117
+ ?.toLowerCase()
118
+ ?.trim();
119
+ if ((domain || "").length > 0) {
120
+ document.getElementById("domain").value = domain;
121
+ submitFn(domain);
122
+ }
123
+ });
124
+ document.getElementById("searchForm").onsubmit = (e) => {
125
+ e.preventDefault();
126
+ const domain = document.getElementById("domain").value;
127
+ if ((domain || "").trim().length == 0) {
128
+ return;
129
+ }
130
+
131
+ submitFn(domain);
132
+ };
133
  </script>
134
  </body>
135
  </html>