-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
42 lines (42 loc) · 1.47 KB
/
index.js
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
let current_search = 'google'
document.querySelector('.search_input').addEventListener('keyup', e => {
const input = e.target.value;
let search_engine = input.split(' ')[0].toLowerCase();
let search_query = input.split(' ').splice(0).join(' ');
switch(search_engine){
case 'google':
case 'youtube':
case 'docs': break;
default: search_engine = 'google';
search_query = input;
}
if(search_engine !== current_search) {
current_search = search_engine;
const image = document.querySelector('.search_icon');
switch(search_engine){
case 'google':
image.src = 'google.png';
image.alt = 'Google icon';
break;
case 'youtube':
image.src = 'youtube.png';
image.alt = 'YouTube icon';
break;
case 'docs':
image.src = 'docs.png';
image.alt = 'Google Docs icon';
break;
}
}
if(e.key === 'Enter')
switch(search_engine) {
case 'docs':
window.location = `https://docs.google.com/document/?q=${search_query}`;
break;
case 'youtube':
window.location = `https://www.youtube.com/results?search_query=${search_query}`;
break;
default:
window.location = `https://www.google.com/search?q=${search_query}`;
}
});