-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
249 lines (243 loc) · 8.55 KB
/
index.html
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
248
249
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap");
* {
transition: 0.3s;
}
html,
body,
.viewport {
background-color: #000000;
/*background-color: #000814;*/
}
input {
opacity: 0;
pointer-events: none;
display: hidden;
}
.text-show {
width: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: transparent;
border: none;
outline: none;
font-size: 2em;
color: #7ae582;
text-align: center;
font-family: "Jetbrains mono", sans-serif;
font-weight: 300;
}
.cursor {
color: #c1121f;
}
.ligntning-search {
font-size: 0.6em !important;
color: #edae49 !important;
}
</style>
</head>
<body>
<input type="search" autocomplete="off" defaultvalue="" />
<span class="text-show">
<font style="color: #c1121f">></font>
<font class="typed-text"></font>
<br />
<div class="ligntning-search"></div>
<div class="ligntning-time ligntning-search"></div>
</span>
<script>
const input = document.querySelector("input");
const lightning = document.querySelector(".ligntning-search");
const lightning2 = document.querySelector(".ligntning-time");
input.focus();
// no matter if input is focussed or not, pressing a key will change the value
input.addEventListener("blur", () => {
input.focus();
});
time = new Date();
let timeShown =
time.getHours().toString().padStart(2, "0") +
":" +
time.getMinutes().toString().padStart(2, "0") +
" / " +
time.getDate().toString().padStart(2, "0") +
"-" +
(time.getMonth() + 1).toString().padStart(2, "0") +
"-" +
time.getFullYear();
lightning2.innerHTML = "? " + timeShown;
input.addEventListener("focus", (e) => {
const inputVal = e.target.value;
setInterval(function () {
time = new Date();
timeShown =
time.getHours().toString().padStart(2, "0") +
":" +
time.getMinutes().toString().padStart(2, "0") +
" / " +
time.getDate().toString().padStart(2, "0") +
"-" +
(time.getMonth() + 1).toString().padStart(2, "0") +
"-" +
time.getFullYear();
lightning2.innerHTML = "? " + timeShown;
}, 1000);
});
input.addEventListener("input", (e) => {
const inputVal = e.target.value;
const textShow = document.querySelector(".typed-text");
textShow.textContent = inputVal.trim();
console.log(inputVal);
if (inputVal.trim() !== "") {
lightning2.style.display = "none";
lightning.style.display = "block";
if (
!inputVal.match(/[^0-9\+\-\*\/\%\(\)\.]/g)
) {
lightning.innerHTML = "? = " + eval(inputVal);
} else if (inputVal.startsWith("bing")) {
lightning.innerHTML = "? bing " + inputVal.replace("bing", "");
} else if (inputVal.startsWith("ddg")) {
lightning.innerHTML = "? duck " + inputVal.replace("ddg", "");
} else if (inputVal.startsWith("yt")) {
lightning.innerHTML = "? youtube " + inputVal.replace("yt", "");
} else if (inputVal.startsWith("gh")) {
lightning.innerHTML = "? github " + inputVal.replace("gh", "");
} else if (inputVal.includes("www.")) {
lightning.innerHTML = "? " + inputVal;
} else if (inputVal.includes(".com")) {
lightning.innerHTML = "? " + inputVal;
} else if (inputVal.includes(".in")) {
lightning.innerHTML = "? " + inputVal;
} else if (inputVal === "random random random") {
setInterval(function () {
chars =
"qwertyuiopasdfghjklzxcvbnm1234567890!@#$%^&*()_+/.,<>?;':[]{}|";
var randomstring = "";
for (var i = 0; i < 10; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
lightning.innerHTML = randomstring;
textShow.innerHTML = randomstring;
}, 50);
} else {
// get search results from duckduckgo api
let results;
fetch(
`https://api.duckduckgo.com/?q=${inputVal}&format=json&pretty=1`
)
.then((res) => res.json())
.then((data) => {
results = data.RelatedTopics;
if (results.length > 0) {
lightning.innerHTML = "? " + results[0].Text;
console.log(results)
} else {
lightning.innerHTML = "? google " + inputVal;
}
})
.catch((err) => {
console.log(err);
lightning.innerHTML = "? google " + inputVal;
});
}
} else {
lightning2.style.display = "block";
lightning.style.display = "none";
}
});
input.addEventListener("keydown", (e) => {
if (e.key === "Enter" && e.target.value.trim() !== "") {
switch (true) {
case e.target.value.startsWith("bing "):
window.location.href = `https://www.bing.com/search?q=${e.target.value.replace(
"bing ",
""
)}`;
break;
case e.target.value.startsWith("ddg "):
window.location.href = `https://duckduckgo.com/?q=${e.target.value.replace(
"ddg ",
""
)}`;
break;
case e.target.value.startsWith("yt"):
window.location.href =
e.target.value.trim().replace("yt", "") !== ""
? `https://www.youtube.com/results?search_query=${e.target.value.replace(
"yt ",
""
)}`
: "https://www.youtube.com";
break;
case e.target.value.startsWith("gh "):
window.location.href = `https://www.github.com/search?q=${e.target.value.replace(
"gh ",
""
)}`;
break;
case e.target.value.includes("www."):
window.location.href = `https://${e.target.value}`;
break;
case e.target.value.includes(".com"):
window.location.href = `https://${e.target.value}`;
break;
case e.target.value.includes(".in"):
window.location.href = `https://${e.target.value}`;
break;
default:
window.location.href = `https://www.google.com/search?q=${e.target.value}`;
break;
}
}
});
input.addEventListener("keyup", (e) => {
var cursorPosition = input.selectionStart;
const textShow = document.querySelector(".typed-text");
var cursor = "|";
var textBeforeCursor = e.target.value.substring(0, cursorPosition);
var textAfterCursor = e.target.value.substring(
cursorPosition,
e.target.value.length
);
if (input.selectionStart !== input.selectionEnd) {
selectedText = e.target.value.substring(
input.selectionStart,
input.selectionEnd
);
textAfterSelection = e.target.value.substring(
input.selectionEnd,
e.target.value.length
);
textShow.innerHTML =
textBeforeCursor +
"<font class='cursor'>" +
cursor +
"</font>" +
selectedText +
"<font class='cursor'>" +
cursor +
"</font>" +
textAfterSelection;
} else {
textShow.innerHTML =
textBeforeCursor +
"<font class='cursor'>" +
cursor +
"</font>" +
textAfterCursor;
}
});
</script>
</body>
</html>