Skip to content

Commit a2c3193

Browse files
committed
Merged main
2 parents ded3de8 + dce55f7 commit a2c3193

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

serverClient/client.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ fetch('/public-key').then(res=>res.json()).then(publicKey => {
193193

194194
async function postData(url, searchTopic) {
195195
skeletonLoader();
196+
if(public_key_server==null) return
196197
const searchTopicEnc = ks.encryption((JSON.stringify(searchTopic)), public_key_server);
197198
console.log("Encrypted search",searchTopicEnc)
198199
// Create the request body with encrypted searchTopic and public key
@@ -260,10 +261,33 @@ function skeletonLoader() {
260261
mainDivSelector.appendChild(childDivElement);
261262
}
262263
}
263-
264+
var searchResult
265+
const searchQuery = document.getElementById("inputBox");
266+
searchQuery.addEventListener('keydown', function(event) {
267+
// Check if the key pressed is Enter (key code 13)
268+
if (event.keyCode === 13) {
269+
// Prevent the default action (form submission, page reload, etc.)
270+
event.preventDefault();
271+
const searchTopic = document.getElementById("inputBox").value;
272+
console.log("Searching : ",searchTopic);
273+
postData("/submit",{ searchTopic:searchTopic})
274+
.then(searchResult => {
275+
console.log("search result before Decryption",searchResult)
276+
277+
decryptedSearchResult= ks.decryption(searchResult)
278+
279+
decryptedSearchResult=JSON.parse(decryptedSearchResult)
280+
281+
populateMainDiv(decryptedSearchResult)
282+
})
283+
.catch(error => {
284+
console.error("Error: ", error);
285+
});
286+
}
287+
});
264288
document.getElementById("searchBtn").onclick = function() {
265289
const searchTopic = document.getElementById("inputBox").value;
266-
290+
console.log("Searching : ",searchTopic);
267291
postData("/submit",{ searchTopic:searchTopic})
268292
.then(searchResult => {
269293
console.log("search result before Decryption",searchResult)
@@ -278,7 +302,19 @@ document.getElementById("searchBtn").onclick = function() {
278302
console.error("Error: ", error);
279303
});
280304
};
281-
305+
window.addEventListener('beforeunload', function(event) {
306+
fetch("/exit", {
307+
method: "POST",
308+
headers: {
309+
"Content-Type": "application/json"
310+
},
311+
body: JSON.stringify("Client left")
312+
});
313+
// var ws = new WebSocket('ws://localhost:8080'); // Replace with your server's WebSocket URL
314+
// ws.onopen = function() {
315+
// ws.send('TabClosed'); // Send a message to the server
316+
// };
317+
});
282318
/*const searchResult = [
283319
{
284320
"link": "https://www.javatpoint.com/array-in-java",
@@ -335,14 +371,14 @@ function populateMainDiv(searchResult) {
335371
childDivElement.innerHTML = `<br>
336372
<div class="search-result-element">
337373
<div class="flex-container">
338-
<div> <a href="${link}" class="icon"> <img src="${googleFaviconGrabber+domain[2]}"> </a> </div>
374+
<div> <a href="${link}" class="icon" target="_blank"> <img src="${googleFaviconGrabber+domain[2]}"> </a> </div>
339375
<div>
340-
<div> <a href="${link}" class="domain"> ${domainParts[1]} </a> </div>
341-
<div> <a href="${link}" class="link"> ${link} </a> </div>
376+
<div> <a href="${link}" class="domain" target="_blank"> ${domainParts[1]} </a> </div>
377+
<div> <a href="${link}" class="link" target="_blank"> ${link} </a> </div>
342378
</div>
343379
</div>
344380
<div class="heading-div">
345-
<a href="${link}" class="heading"> ${title} </a>
381+
<a href="${link}" class="heading" target="_blank"> ${title} </a>
346382
</div>
347383
<div class="description">
348384
${desc.substring(0, 225) + " ..."}

serverClient/style.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ body {
22
margin-left: 160px;
33
margin-right: 76px;
44
}
5-
5+
::-webkit-scrollbar {
6+
display: none;
7+
}
68
#inputBox {
79
width: 600px;
810
height: 44px;

0 commit comments

Comments
 (0)