Skip to content

Commit dce55f7

Browse files
committed
seperated html,css,js for clarity
1 parent 4fca803 commit dce55f7

File tree

3 files changed

+41
-342
lines changed

3 files changed

+41
-342
lines changed

serverClient/client.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
console.log("This python based search engine is developed by Tamal Mallick,Sushanta Das and Subham Manna")
12
async function postData(url, searchTopic) {
23
skeletonLoader();
34
const response = await fetch(url, {
@@ -40,10 +41,26 @@ function skeletonLoader() {
4041
mainDivSelector.appendChild(childDivElement);
4142
}
4243
}
43-
44+
var searchResult
45+
const searchQuery = document.getElementById("inputBox");
46+
searchQuery.addEventListener('keydown', function(event) {
47+
// Check if the key pressed is Enter (key code 13)
48+
if (event.keyCode === 13) {
49+
// Prevent the default action (form submission, page reload, etc.)
50+
event.preventDefault();
51+
console.log("Searching : ",searchQuery.value);
52+
postData("/submit",{ searchTopic:searchQuery.value})
53+
.then(searchResult => {
54+
populateMainDiv(searchResult)
55+
})
56+
.catch(error => {
57+
console.error("Error: ", error);
58+
});
59+
}
60+
});
4461
document.getElementById("searchBtn").onclick = function() {
4562
const searchTopic = document.getElementById("inputBox").value;
46-
63+
console.log("Searching : ",searchTopic);
4764
postData("/submit",{ searchTopic:searchTopic})
4865
.then(searchResult => {
4966
populateMainDiv(searchResult)
@@ -52,7 +69,19 @@ document.getElementById("searchBtn").onclick = function() {
5269
console.error("Error: ", error);
5370
});
5471
};
55-
72+
window.addEventListener('beforeunload', function(event) {
73+
fetch("/exit", {
74+
method: "POST",
75+
headers: {
76+
"Content-Type": "application/json"
77+
},
78+
body: JSON.stringify("Client left")
79+
});
80+
// var ws = new WebSocket('ws://localhost:8080'); // Replace with your server's WebSocket URL
81+
// ws.onopen = function() {
82+
// ws.send('TabClosed'); // Send a message to the server
83+
// };
84+
});
5685
/*const searchResult = [
5786
{
5887
"link": "https://www.javatpoint.com/array-in-java",
@@ -109,14 +138,14 @@ function populateMainDiv(searchResult) {
109138
childDivElement.innerHTML = `<br>
110139
<div class="search-result-element">
111140
<div class="flex-container">
112-
<div> <a href="${link}" class="icon"> <img src="${googleFaviconGrabber+domain[2]}"> </a> </div>
141+
<div> <a href="${link}" class="icon" target="_blank"> <img src="${googleFaviconGrabber+domain[2]}"> </a> </div>
113142
<div>
114-
<div> <a href="${link}" class="domain"> ${domainParts[1]} </a> </div>
115-
<div> <a href="${link}" class="link"> ${link} </a> </div>
143+
<div> <a href="${link}" class="domain" target="_blank"> ${domainParts[1]} </a> </div>
144+
<div> <a href="${link}" class="link" target="_blank"> ${link} </a> </div>
116145
</div>
117146
</div>
118147
<div class="heading-div">
119-
<a href="${link}" class="heading"> ${title} </a>
148+
<a href="${link}" class="heading" target="_blank"> ${title} </a>
120149
</div>
121150
<div class="description">
122151
${desc.substring(0, 225) + " ..."}

0 commit comments

Comments
 (0)