-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
98 lines (88 loc) · 3.21 KB
/
search.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
String.prototype.replaceChars = function(character, replacement){
var str = this;
var a;
var b;
for(var i=0; i < str.length; i++){
if(str.charAt(i) == character){
a = str.substr(0, i) + replacement;
b = str.substr(i + 1);
str = a + b;
}
}
return str;
}
function search(query){
switch(query.substr(0, 2)){
case "-a":
query = query.substr(3);
window.location = "http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=" +
query.replaceChars(" ", "+");
break;
case "-y":
query = query.substr(3);
window.location =
"https://www.youtube.com/results?search_query=" +
query.replaceChars(" ", "+");
break;
case "-w":
query = query.substr(3);
window.location =
"https://en.wikipedia.org/w/index.php?search=" +
query.replaceChars(" ", "%20");
break;
case "-m":
query = query.substr(3);
window.location =
"http://www.wolframalpha.com/input/?i=" +
query.replaceChars("+", "%2B");
break;
case "-h":
query=query.substr(3);
window.location =
"http://alpha.wallhaven.cc/search?q=" +
query.concat("&categories=111&purity=100&resolutions=1920x1080&sorting=relevance&order=desc");
break;
// case "-4":
// query = query.substr(3);
// window.location =
// "http://boards.4chan.org/" +
// query.replaceChars(" ", "%20");
// break;
default:
window.location="https://www.google.com/#q=" +
query.replaceChars(" ", "+");
}
}
window.onload = function(){
// search
searchinput = document.getElementById("searchbox");
if(!!searchinput){
searchinput.addEventListener("keypress", function(a){
var key = a.keyCode;
if(key == 13){
var query = this.value;
search(query);
}
});
}
// jump to search when tab is pressed
var search_sqr = document.getElementById("search_sqr");
}
//
// To add a new search provider, paste the following between the last "break;" and "default:" (Line 39 & 40)
//
// case "-a":
// query = query.substr(3);
// window.location =
// "https://en.website.com/" +
// query.replaceChars(" ", "%20");
// break;
//
// -a on ln68 should be replaced with a "-letter" of your choice. You can also change it to !a, .a, /a etc.
// https://en.website.com/ on ln70 should be replaced with the search page of the website. To find this, make a few searches on your website.
//Try to identify where your search is in the URL. If you're not sure, post in the thread and someone should help you out
//
// You can use the above two to modify an existing rule
//
// If you wish to change the number of characters in a "case", you need to change the line below, changing query.substr() to n+1, n being the number of characters.
// This ensures that when you search for something, the whole of your idenfier and the space between the identifier and query are removed.