Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +25 -27
templates/index.html
CHANGED
|
@@ -12,53 +12,51 @@
|
|
| 12 |
<form id="scrapeForm">
|
| 13 |
<div class="form-group">
|
| 14 |
<label for="url">Website URL:</label>
|
| 15 |
-
<input type="url" id="url" name="url" placeholder="https://example.com"
|
| 16 |
</div>
|
| 17 |
<div class="form-group">
|
| 18 |
-
<label for="
|
| 19 |
-
<input type="
|
| 20 |
</div>
|
| 21 |
<div class="form-group">
|
| 22 |
-
<label for="
|
| 23 |
-
<input type="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
</div>
|
| 25 |
<button type="submit">Scrape Website</button>
|
| 26 |
</form>
|
| 27 |
|
| 28 |
-
<
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
</div>
|
| 31 |
|
| 32 |
<script>
|
| 33 |
-
document.getElementById('scrapeForm').addEventListener('submit', async (
|
| 34 |
-
|
| 35 |
-
|
| 36 |
const url = document.getElementById('url').value;
|
| 37 |
-
const
|
| 38 |
-
const
|
| 39 |
-
const
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
try {
|
| 44 |
-
const
|
| 45 |
-
if (bot_name) queryParams.append('bot_name', bot_name);
|
| 46 |
-
if (nativemsg_token) queryParams.append('nativemsg_token', nativemsg_token);
|
| 47 |
-
|
| 48 |
-
const response = await fetch(`/scrape?${queryParams.toString()}`, {
|
| 49 |
-
method: 'GET',
|
| 50 |
-
headers: { 'Content-Type': 'application/json' }
|
| 51 |
-
});
|
| 52 |
-
|
| 53 |
if (!response.ok) {
|
| 54 |
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 55 |
}
|
| 56 |
-
|
| 57 |
const data = await response.json();
|
| 58 |
-
|
|
|
|
| 59 |
} catch (error) {
|
| 60 |
-
|
| 61 |
-
|
| 62 |
}
|
| 63 |
});
|
| 64 |
</script>
|
|
|
|
| 12 |
<form id="scrapeForm">
|
| 13 |
<div class="form-group">
|
| 14 |
<label for="url">Website URL:</label>
|
| 15 |
+
<input type="url" id="url" name="url" required placeholder="https://example.com">
|
| 16 |
</div>
|
| 17 |
<div class="form-group">
|
| 18 |
+
<label for="email">Email Address:</label>
|
| 19 |
+
<input type="email" id="email" name="email" required placeholder="your.email@example.com">
|
| 20 |
</div>
|
| 21 |
<div class="form-group">
|
| 22 |
+
<label for="botName">Bot Name:</label>
|
| 23 |
+
<input type="text" id="botName" name="botName" placeholder="Enter Bot Name">
|
| 24 |
+
</div>
|
| 25 |
+
<div class="form-group">
|
| 26 |
+
<label for="apiToken">NativeMSG API Token:</label>
|
| 27 |
+
<input type="password" id="apiToken" name="apiToken" placeholder="Enter NativeMSG Tokens">
|
| 28 |
</div>
|
| 29 |
<button type="submit">Scrape Website</button>
|
| 30 |
</form>
|
| 31 |
|
| 32 |
+
<div id="result">
|
| 33 |
+
<h2>Result</h2>
|
| 34 |
+
<div id="message"></div>
|
| 35 |
+
</div>
|
| 36 |
</div>
|
| 37 |
|
| 38 |
<script>
|
| 39 |
+
document.getElementById('scrapeForm').addEventListener('submit', async (e) => {
|
| 40 |
+
e.preventDefault();
|
|
|
|
| 41 |
const url = document.getElementById('url').value;
|
| 42 |
+
const email = document.getElementById('email').value;
|
| 43 |
+
const botName = document.getElementById('botName').value;
|
| 44 |
+
const apiToken = document.getElementById('apiToken').value;
|
| 45 |
+
const messageDiv = document.getElementById('message');
|
| 46 |
|
| 47 |
+
messageDiv.textContent = 'Scraping in progress...';
|
| 48 |
|
| 49 |
try {
|
| 50 |
+
const response = await fetch(`/scrape?url=${encodeURIComponent(url)}&email=${encodeURIComponent(email)}${botName ? `&bot_name=${encodeURIComponent(botName)}` : ''}${apiToken ? `&nativemsg_token=${encodeURIComponent(apiToken)}` : ''}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
if (!response.ok) {
|
| 52 |
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 53 |
}
|
|
|
|
| 54 |
const data = await response.json();
|
| 55 |
+
messageDiv.textContent = `RCS for website is generated and sent to ${email}.`;
|
| 56 |
+
messageDiv.style.color = 'green';
|
| 57 |
} catch (error) {
|
| 58 |
+
messageDiv.textContent = `Error: ${error.message}`;
|
| 59 |
+
messageDiv.style.color = 'red';
|
| 60 |
}
|
| 61 |
});
|
| 62 |
</script>
|