Prathmesh48's picture
Upload index.html
0725035 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Search Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
}
.container {
background-color: #fff;
padding: 20px 40px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
text-align: center;
width: 40vmax;
margin: auto;
}
h1 {
margin-bottom: 20px;
}
h2 {
text-align: center;
}
label {
width: 100%;
display: block;
margin: 10px 0 5px;
}
input[type="text"],
select {
box-sizing: border-box;
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#display {
width: 95%;
margin: auto;
display: flex;
flex-direction: column;
background-color: white;
overflow-x: scroll;
}
#loading-container {
display: none;
height: 100vh;
background: white;
justify-content: center;
align-items: center;
}
.loading {
display: flex;
flex-direction: row;
}
.loading__letter {
font-size: 88px;
font-weight: normal;
letter-spacing: 4px;
text-transform: uppercase;
font-family: "Audiowide";
color: cyan;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.loading__letter:nth-child(2) {
animation-delay: .1s;
}
.loading__letter:nth-child(3) {
animation-delay: .2s;
}
.loading__letter:nth-child(4) {
animation-delay: .3s;
}
.loading__letter:nth-child(5) {
animation-delay: .4s;
}
.loading__letter:nth-child(6) {
animation-delay: .5s;
}
.loading__letter:nth-child(7) {
animation-delay: .6s;
}
.loading__letter:nth-child(8) {
animation-delay: .8s;
}
.loading__letter:nth-child(9) {
animation-delay: 1s;
}
.loading__letter:nth-child(10) {
animation-delay: 1.2s;
}
@keyframes bounce {
0% {
transform: translateY(0px)
}
40% {
transform: translateY(-40px);
}
80%,
100% {
transform: translateY(0px);
}
}
@media (max-width: 700px) {
.loading__letter {
font-size: 50px;
}
}
@media (max-width: 340px) {
.loading__letter {
font-size: 40px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Product Search Form</h1>
<form onsubmit="handleSubmit(event)" method="post">
<label for="product">Product:</label>
<input type="text" id="product" name="product" placeholder="Enter product name" required>
<label for="searchEngine">Choose a Source:</label>
<select id="searchEngine" name="searchEngine" required>
<option value="all">All Sources (Will take time)</option>
<option value="google">Google</option>
<option value="duckduckgo">DuckDuckGo</option>
<option value="archive">Internet Archive</option>
<option value="github">Github</option>
</select>
<button type="submit">Search</button>
</form>
</div>
<h2>Results</h2>
<div id="loading-container">
<div class="loading">
<div class="loading__letter">S</div>
<div class="loading__letter">C</div>
<div class="loading__letter">R</div>
<div class="loading__letter">A</div>
<div class="loading__letter">P</div>
<div class="loading__letter">I</div>
<div class="loading__letter">N</div>
<div class="loading__letter">G</div>
<div class="loading__letter">.</div>
<div class="loading__letter">.</div>
<div class="loading__letter">.</div>
</div>
</div>
<div id="display"></div>
</body>
<script>
function fillData(data) {
// console.log(data)
const source = document.getElementById('searchEngine').text;
const parentDiv = document.getElementById('display');
for (const key in data) {
if (data.hasOwnProperty(key)) {
// Create a div for each object
const objectDiv = document.createElement('div');
objectDiv.className = 'object-div';
// Add the object name
const objectName = document.createElement('h2');
objectName.innerText = `Product: ${key}`;
objectDiv.appendChild(objectName);
// Add source titles and links
for (const item of data[key]) {
if (typeof item === 'string') {
// If it's a string (URL), create a link
const linkElement = document.createElement('a');
linkElement.href = item;
linkElement.innerText = item;
linkElement.target = '_blank'; // Open link in a new tab
const listItem = document.createElement('li');
listItem.appendChild(linkElement);
objectDiv.appendChild(listItem);
} else if (typeof item === 'object') {
// If it's an object, it contains nested sources
for (const source in item) {
const sourceTitle = document.createElement('h3');
sourceTitle.innerText = `${source}:`;
objectDiv.appendChild(sourceTitle);
const linksList = document.createElement('ul');
for (const link of item[source]) {
const linkElement = document.createElement('a');
linkElement.href = link;
linkElement.innerText = link;
linkElement.target = '_blank'; // Open link in a new tab
const listItem = document.createElement('li');
listItem.appendChild(linkElement);
linksList.appendChild(listItem);
}
objectDiv.appendChild(linksList);
}
}
}
parentDiv.appendChild(objectDiv);
}
}
}
async function handleSubmit(event) {
event.preventDefault();
const parentDiv = document.getElementById('display');
parentDiv.innerHTML = '';
let loading = document.getElementById('loading-container');
loading.style.display = 'flex';
const product = document.getElementById('product').value;
const source = document.getElementById('searchEngine').value;
const url = `http://127.0.0.1:8000/search/${source}`;
let final_result = '';
const data = {
API_KEY: "12345",
product: product,
};
let p = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
final_result = data
})
.catch((error) => {
console.log(error)
alert('Request failed');
});
loading.style.display = 'none';
fillData(final_result);
}
</script>
</html>