-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (76 loc) · 2.16 KB
/
main.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
var shiftDown = false;
function setDate($) {
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
d = new Date(),
currentDate = days[d.getDay()] + ' ' + d.getDate() + ' ' + months[d.getMonth()],
mins = (d.getMinutes() > 9) ? d.getMinutes() : '0' + d.getMinutes(),
currentTime = d.getHours() + ':' + mins,
previousTime = $('#timeArea .time .timeInner').html();
if (currentTime != previousTime) {
$('#timeArea .time .timeInner').html(currentTime);
$('#timeArea .time .date').html(currentDate);
}
setTimeout(function () {
setDate($);
}, 1000);
}
function search(query, engine) {
query = query.replace(/ /g, '+', query);
switch (engine) {
case 'google':
default:
var url = 'https://www.google.co.uk/search?q=' + query;
break;
case 'youtube':
var url = 'https://www.youtube.com/results?search_query=' + query;
break;
case 'tpb':
var url = 'https://piratehole.com/search/' + query + '/0/99/0';
break;
case 'kickass':
var url = 'http://kickasstorrent.proxyindex.co/usearch/' + query + '/';
break;
case 'duck':
var url = 'https://duckduckgo.com/?q=' + query;
break;
case 'wa':
var url = 'http://www.wolframalpha.com/input/?i=' + query;
break;
case 'wiki':
var url = 'http://en.wikipedia.org/w/index.php?search=' + query;
break;
case 'imdb':
var url = 'http://www.imdb.com/find?q=' + query + '&s=tt';
break;
}
if (!shiftDown) {
window.location.replace(url);
} else {
$('<a>').attr('href', url).attr('target', '_blank')[0].click();
}
}
$(function () {
setDate($);
$(window).keydown(function (e) {
if (e.keyCode == 36) {
$('.hideable').toggleClass('hide');
}
if (e.keyCode == 16) {
shiftDown = true;
}
});
$(window).keyup(function (e) {
if (e.keyCode == 16) {
shiftDown = false;
}
});
$('#searchForm input, #searchForm select').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
var query = $('#searchForm input').val();
var engine = 'google'
search(query, engine);
}
});
});