-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaidu.js
More file actions
48 lines (47 loc) · 1.7 KB
/
Copy pathbaidu.js
File metadata and controls
48 lines (47 loc) · 1.7 KB
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
function getByClass(a,b){
if(a.getElementsByClassName){
return a.getElementsByClassName(b);
}
var arr = [];
var all = a.getElementsByTagName('*');
var re = RegExp("\\b"+b+"\\b","g");
for (var i = 0; i < all.length; i++) {
if(re.test(all[i].className)){
arr.push(all[i]);
}
};
return arr;
};
window.onload = function(){
var oT = getByClass(document,"search_1")[0];
var oDiv = getByClass(document,"hide_div")[0];
oT.onkeyup=function(){
oDiv.innerHTML="";
jsonp({
url:"https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",
data:{wd:this.value},
success:function(json){
var arr = json.s;
if(arr.length==0){
oDiv.style.display="none";
}else{
for (var i = 0; i < arr.length; i++) {
var oA = document.createElement('a');
oA.href = 'https://www.baidu.com/s?wd='+arr[i];
oA.innerHTML = arr[i];
oDiv.appendChild(oA);
(function(b){
oA.onclick=function(){
window.open(b.href,"_blank");
oDiv.style.display="none";
oT.value="";
return false;
};
})(oA);
};
oDiv.style.display="block";
};
}
});
};
};