-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
247 lines (217 loc) · 6.42 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPSearchX</title>
<!-- linking of enternal module and scripts-->
<link rel="stylesheet" href="./style.css">
<script src="main.js"></script>
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="./icon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./icon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./icon/favicon-16x16.png">
<link rel="shortcut icon" href="./icon/favicon.ico" type="image/x-icon">
<link rel="manifest" href="./icon/site.webmanifest">
</head>
<style>
/* Add your existing CSS here */
@media only screen and (max-width: 800px) {
.main {
width: 100%;
}
}
/* Media Queries */
@media only screen and (max-width: 480px) {
.main {
width: 100%;
font-family: arial;
}
.search_bar input {
width: calc(100% - 100px);
font-family: 'Courier New', Courier, monospace;
padding: 5px;
}
.search_bar button {
width: 100px;
}
.items {
width: 100%;
margin: 0px;
margin-bottom: 5px;
}
.top img {
height: 30px;
width: 30px;
margin: 0px;
margin-right: 5px;
margin-left: 5px;
margin-top: 5px;
padding: 0px;
}
.top {
margin: 0px;
padding: 0px;
margin-top: 6px;
}
.footer {
width: 100%;
height: auto;
flex-direction: column;
justify-content: center;
align-items: center;
}
.showpage {
height: auto;
width: 100%;
background-color: #40810240;
display: flex;
flex-direction: row;
text-align: center;
justify-content: center;
align-items: center;
}
.showpage a {
height: auto;
width: auto;
margin: 0px;
padding: 10px;
}
.showpage a:hover {
background-color: #40810240;
}
.showpage .active {
border-bottom: 2px solid blue;
}
}
.load_more{
height: auto;
width: 90%;
border: 1px solid white;
font-family: cursive;
box-shadow: 0px 0px 4px gray;
padding: 5px;
margin: 0px;
align-self:center;
}
.load_more:hover{
box-shadow: 0px 0px 10px gray;
}
</style>
<body>
<div class="main">
<div class="header">
<h2>CPSearchX</h2>
<!-- Search Form -->
<form id="searchForm" class="search_bar">
<input type="text" id="query" name="q" placeholder="Search the world">
<button type="submit">Search</button>
</form>
<div class="filter">
<!-- Filter options go here -->
</div>
</div>
<div id="item_list" class="body">
<!-- Search results will be appended here -->
</div>
<!-- HTML -->
<!-- CSS -->
<style>
.loading {
width: 100%;
height: 5px;
border-radius: 10px;
/* background-color: transparent; */
background-color: #40810240;
box-shadow: 0px 0px 4px gray;
align-self:center;
}
.loading-bar-inner {
width: 0%;
height: 100%;
background-color: #40810260;
border-radius: 10px;
transition: width 0.5s;
}
.loading {
display: none; /* hide by default */
}
</style>
<div class="loading" id="loading" style="display:none;">
<div class="loading-bar-inner"></div>
</div>
<div class="footer">
<!-- Pagination Links -->
<button style="display:none" class='load_more' id='load_more' type='submit'>Load More..</button>
<!-- About Section -->
<div class="about">
<h2>About</h2>
<p>This is a Search Engine which searches user query. Built by an undergraduate student overnight.</p>
<p>By the way you can follow me on github: <a href="https://github.com/h4jack"><strong>h4jack<strong></p>
</div>
</div>
</div>
<script>
const loadingBarInner = document.querySelector('.loading-bar-inner');
const loading = document.getElementById('loading');
let progress = 0;
function animateLoadingBar() {
progress += 1;
loadingBarInner.style.width = `${progress}%`;
if (progress < 100) {
requestAnimationFrame(animateLoadingBar);
} else {
progress = 0;
animateLoadingBar();
}
}
animateLoadingBar();
</script>
<script>
const urlParams = new URLSearchParams(window.location.search);
let start = urlParams.get('start');
start = start && start < 100 && start > 0 ? start : 1;
const query = urlParams.get('q');
document.getElementById('load_more').onclick = function() {
// alert("hello"); // just to test if this function is working or not...
if (query) {
start += start == 100 ? 0 : 10;
fetchResults(query, start);
window.history.pushState({}, '', `?q=${encodeURIComponent(query)}`);
}
};
function showLoadingBar() {
loadingElement.style.display = "block";
animateLoadingBar();
}
function hideLoadingBar() {
loadingElement.style.display = "none";
}
window.onload = function () {
// Show the loading bar
// showLoadingBar();
if (query) {
document.getElementById('query').value = query;
if(start){
fetchResults(query, start);
}else{
fetchResults(query);
}
}else{
const itemList = document.getElementById('item_list');
itemList.innerHTML = `
<h3 class='title'>
Welcome to the CPSearchX
</h3>
<p>don't know.<br>
try this search
<a href='?q=best food for morning'>
<strong>best food for morning</strong>
</a>`;
}
// Hide the loading bar
// hideLoadingBar();
};
</script>
</body>
</html>