-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (48 loc) · 2.02 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
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('searchForm');
const queryInput = document.getElementById('searchQuery');
const buttons = form.querySelectorAll('button[data-engine]');
queryInput.addEventListener('keydown', function(event) {
if (event.keyCode === 13) {
event.preventDefault();
}
});
buttons.forEach(button => {
button.addEventListener('click', function() {
const query = queryInput.value;
if (!query) {
buttons.forEach(e => { e.disabled = true; })
queryInput.value = "Insira algo na caixa de pesquisa para continuar."
queryInput.disabled = true;
setTimeout(() => {
buttons.forEach(e => { e.disabled = false; })
queryInput.value = "";
queryInput.disabled = false;
}, 2000)
return;
}
const engine = button.getAttribute('data-engine');
let url;
switch (engine) {
case 'google':
url = `https://www.google.com/search?q=${encodeURIComponent(query)}`;
break;
case 'bing':
url = `https://www.bing.com/search?q=${encodeURIComponent(query)}`;
break;
case 'youtube':
url = `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`;
break;
case 'duckduckgo':
url = `https://duckduckgo.com/?q=${encodeURIComponent(query)}`;
break;
case 'startpage':
url = `https://startpage.com/do/search?q=${encodeURIComponent(query)}`;
break;
default:
return;
}
window.location.href = url;
});
});
});