Spaces:
Sleeping
Sleeping
Implemented URL validation and alert for invalid URLs before sending the request.
Browse files
script.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
| 1 |
const { convertHtmlToMarkdown } = htmlToSMD;
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
document
|
| 4 |
.getElementById("converter-form")
|
| 5 |
.addEventListener("submit", async function (e) {
|
|
@@ -7,6 +16,11 @@ document
|
|
| 7 |
|
| 8 |
const urlInput = document.getElementById("url-input").value;
|
| 9 |
const markdownOutput = document.getElementById("markdown-output");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
const extractMainContent = document.getElementById(
|
| 11 |
"extract-main-content"
|
| 12 |
).checked;
|
|
|
|
| 1 |
const { convertHtmlToMarkdown } = htmlToSMD;
|
| 2 |
|
| 3 |
+
function isValidUrl(string) {
|
| 4 |
+
try {
|
| 5 |
+
new URL(string);
|
| 6 |
+
return true;
|
| 7 |
+
} catch (_) {
|
| 8 |
+
return false;
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
document
|
| 13 |
.getElementById("converter-form")
|
| 14 |
.addEventListener("submit", async function (e) {
|
|
|
|
| 16 |
|
| 17 |
const urlInput = document.getElementById("url-input").value;
|
| 18 |
const markdownOutput = document.getElementById("markdown-output");
|
| 19 |
+
|
| 20 |
+
if (!isValidUrl(urlInput)) {
|
| 21 |
+
alert("Please enter a valid URL");
|
| 22 |
+
return;
|
| 23 |
+
}
|
| 24 |
const extractMainContent = document.getElementById(
|
| 25 |
"extract-main-content"
|
| 26 |
).checked;
|