Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +78 -16
templates/index.html
CHANGED
|
@@ -4,32 +4,94 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>DuckDuckGo Search</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<script>
|
| 8 |
async function performSearch() {
|
| 9 |
const query = document.getElementById('search-query').value;
|
| 10 |
-
const response = await fetch(`/search?query=${encodeURIComponent(query)}`);
|
| 11 |
-
const results = await response.json();
|
| 12 |
-
|
| 13 |
const resultsContainer = document.getElementById('results');
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
</script>
|
| 28 |
</head>
|
| 29 |
<body>
|
| 30 |
<h1>DuckDuckGo Search</h1>
|
| 31 |
-
|
|
|
|
| 32 |
<button onclick="performSearch()">Search</button>
|
|
|
|
| 33 |
|
| 34 |
<div id="results"></div>
|
| 35 |
</body>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>DuckDuckGo Search</title>
|
| 7 |
+
<style>
|
| 8 |
+
/* Simple loading spinner */
|
| 9 |
+
.spinner {
|
| 10 |
+
border: 4px solid rgba(0, 0, 0, 0.1);
|
| 11 |
+
border-left-color: #000;
|
| 12 |
+
border-radius: 50%;
|
| 13 |
+
width: 30px;
|
| 14 |
+
height: 30px;
|
| 15 |
+
animation: spin 1s linear infinite;
|
| 16 |
+
display: none;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
@keyframes spin {
|
| 20 |
+
0% { transform: rotate(0deg); }
|
| 21 |
+
100% { transform: rotate(360deg); }
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* Result container styling */
|
| 25 |
+
.result-item {
|
| 26 |
+
margin-bottom: 20px;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.result-item h3 {
|
| 30 |
+
margin: 0;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.result-item img {
|
| 34 |
+
width: 16px;
|
| 35 |
+
height: 16px;
|
| 36 |
+
vertical-align: middle;
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
<script>
|
| 40 |
async function performSearch() {
|
| 41 |
const query = document.getElementById('search-query').value;
|
|
|
|
|
|
|
|
|
|
| 42 |
const resultsContainer = document.getElementById('results');
|
| 43 |
+
const spinner = document.getElementById('spinner');
|
| 44 |
+
|
| 45 |
+
if (!query) {
|
| 46 |
+
alert('Please enter a search query.');
|
| 47 |
+
return;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// Clear previous results
|
| 51 |
+
resultsContainer.innerHTML = '';
|
| 52 |
+
spinner.style.display = 'inline-block'; // Show loading spinner
|
| 53 |
+
|
| 54 |
+
try {
|
| 55 |
+
// Perform search query
|
| 56 |
+
const response = await fetch(`/search?query=${encodeURIComponent(query)}`);
|
| 57 |
+
const results = await response.json();
|
| 58 |
+
|
| 59 |
+
if (results.error) {
|
| 60 |
+
throw new Error(results.error);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Hide loading spinner
|
| 64 |
+
spinner.style.display = 'none';
|
| 65 |
+
|
| 66 |
+
// Display search results
|
| 67 |
+
if (results.length > 0) {
|
| 68 |
+
results.forEach(result => {
|
| 69 |
+
const resultItem = document.createElement('div');
|
| 70 |
+
resultItem.classList.add('result-item');
|
| 71 |
+
resultItem.innerHTML = `
|
| 72 |
+
<h3><a href="${result.link}" target="_blank">${result.title}</a></h3>
|
| 73 |
+
<p>${result.description}</p>
|
| 74 |
+
<img src="${result.icon}" alt="Icon"> <a href="${result.link}" target="_blank">${result.link}</a>
|
| 75 |
+
<hr>
|
| 76 |
+
`;
|
| 77 |
+
resultsContainer.appendChild(resultItem);
|
| 78 |
+
});
|
| 79 |
+
} else {
|
| 80 |
+
resultsContainer.innerHTML = '<p>No results found.</p>';
|
| 81 |
+
}
|
| 82 |
+
} catch (error) {
|
| 83 |
+
spinner.style.display = 'none';
|
| 84 |
+
resultsContainer.innerHTML = `<p>Error: ${error.message}</p>`;
|
| 85 |
+
}
|
| 86 |
}
|
| 87 |
</script>
|
| 88 |
</head>
|
| 89 |
<body>
|
| 90 |
<h1>DuckDuckGo Search</h1>
|
| 91 |
+
|
| 92 |
+
<input type="text" id="search-query" placeholder="Enter search query" style="width: 300px;">
|
| 93 |
<button onclick="performSearch()">Search</button>
|
| 94 |
+
<div id="spinner" class="spinner"></div>
|
| 95 |
|
| 96 |
<div id="results"></div>
|
| 97 |
</body>
|