-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (120 loc) · 3.58 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
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
let typed = "";
let engine = "google"
isEngineSet = false
engineInnerHtml = {
google: 'Google<image class="engine-logo" src="images/google.png"></image>',
youtube: 'Youtube<image class="engine-logo" src="images/youtube.png"></image>',
github: 'Github<image class="engine-logo" src="images/github.png"></image>',
docs: 'Google Docs<image class="engine-logo" src="images/docs.png"></image>',
slides: 'Google Slides<image class="engine-logo" src="images/slides.png"></image>',
sheets: 'Google Sheets<image class="engine-logo" src="images/sheets.png"></image>',
}
engineQuery = {
google: 'https://www.google.com/search?q=',
youtube: 'https://www.youtube.com/results?search_query=',
github: 'https://github.com/search?q=',
docs: 'https://docs.google.com/document/u/0/?tgif=d&q=',
slides: 'https://docs.google.com/presentation/u/0/?tgif=d&q=',
sheets: 'https://docs.google.com/spreadsheets/u/0/?tgif=d&q='
}
$(".search").on("submit",(event)=>{
event.preventDefault();
$('.searchbar').value = "";
submitEventHandler();
})
$(".searchimg").click((event)=>{
$('.searchbar').value = "";
submitEventHandler();
})
$(".searchbar").on("input",(event)=>{
typed = event.target.value;
console.log(typed)
if(typed === ""){
isEngineSet = false
setEngine('google')
dispEngine();
}
else if(typed === "google"){
setEngine('google')
isEngineSet = true
dispEngine();
}
else if(typed === "youtube"){
setEngine('youtube');
isEngineSet = true
dispEngine();
}
else if(typed === "github"){
setEngine('github');
isEngineSet = true
dispEngine();
}
else if(typed === "docs"){
setEngine('docs');
isEngineSet = true
dispEngine();
}
else if(typed === "slides"){
setEngine('slides');
isEngineSet = true
dispEngine();
}
else if(typed === "sheets"){
setEngine('sheets');
isEngineSet = true
dispEngine();
}
})
const setEngine = (engineName) => {
engine = engineName;
}
const dispEngine = () => {
if(engine === "google"){
$('.enginename').html(engineInnerHtml.google)
}
else if(engine === "youtube"){
$('.enginename').html(engineInnerHtml.youtube)
}
else if(engine === "github"){
$('.enginename').html(engineInnerHtml.github)
}
else if(engine === "docs"){
$('.enginename').html(engineInnerHtml.docs)
}
else if(engine === "slides"){
$('.enginename').html(engineInnerHtml.slides)
}
else if(engine === "sheets"){
$('.enginename').html(engineInnerHtml.sheets)
}
}
const submitEventHandler = () => {
let searchQuery = '';
if(isEngineSet){
typed = typed.split(' ').slice(1).join(' ');
}
if(engine === "google"){
searchQuery = engineQuery.google + typed;
window.location.href = searchQuery
}
else if(engine === "youtube"){
searchQuery = engineQuery.youtube + typed;
window.location.href = searchQuery
}
else if(engine === "github"){
searchQuery = engineQuery.github + typed;
window.location.href = searchQuery
}
else if(engine === "docs"){
searchQuery = engineQuery.docs + typed;
window.location.href = searchQuery
}
else if(engine === "slides"){
searchQuery = engineQuery.slides + typed;
window.location.href = searchQuery
}
else if(engine === "sheets"){
searchQuery = engineQuery.sheets + typed;
window.location.href = searchQuery
}
}