1
+ console . log ( "This python based search engine is developed by Tamal Mallick,Sushanta Das and Subham Manna" )
1
2
async function postData ( url , searchTopic ) {
2
3
skeletonLoader ( ) ;
3
4
const response = await fetch ( url , {
@@ -40,10 +41,26 @@ function skeletonLoader() {
40
41
mainDivSelector . appendChild ( childDivElement ) ;
41
42
}
42
43
}
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
+ } ) ;
44
61
document . getElementById ( "searchBtn" ) . onclick = function ( ) {
45
62
const searchTopic = document . getElementById ( "inputBox" ) . value ;
46
-
63
+ console . log ( "Searching : " , searchTopic ) ;
47
64
postData ( "/submit" , { searchTopic :searchTopic } )
48
65
. then ( searchResult => {
49
66
populateMainDiv ( searchResult )
@@ -52,7 +69,19 @@ document.getElementById("searchBtn").onclick = function() {
52
69
console . error ( "Error: " , error ) ;
53
70
} ) ;
54
71
} ;
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
+ } ) ;
56
85
/*const searchResult = [
57
86
{
58
87
"link": "https://www.javatpoint.com/array-in-java",
@@ -109,14 +138,14 @@ function populateMainDiv(searchResult) {
109
138
childDivElement . innerHTML = `<br>
110
139
<div class="search-result-element">
111
140
<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>
113
142
<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>
116
145
</div>
117
146
</div>
118
147
<div class="heading-div">
119
- <a href="${ link } " class="heading"> ${ title } </a>
148
+ <a href="${ link } " class="heading" target="_blank" > ${ title } </a>
120
149
</div>
121
150
<div class="description">
122
151
${ desc . substring ( 0 , 225 ) + " ..." }
0 commit comments