-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentscript.js
176 lines (156 loc) · 5.33 KB
/
contentscript.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
var href = window.location.href;
function nextPage(links){ //links-title url clicked
var divs=document.getElementsByClassName("rc");
if(divs.length==0)
{
divs=null;
divs=document.getElementsByClassName("g");
}
var index=0;
var findFlag=false;
for(index=0;index<divs.length;index++){
var atag=divs[index].getElementsByTagName("a")[0];
//change part
for (var i = 0; i < links.length; i++) {
if(links[i].clicked)
continue;
else
{
if(atag.href==links[i].url||atag.innerHTML.replace(/[^\u4e00-\u9fa5]/gi,"").indexOf(links[i].title)>-1)
{
//open this link
links[i].clicked=true;
if(findFlag){
(function(a){
setTimeout(function(){
a.target="_blank";
a.click(function(){});},Math.floor(Math.random()*6+2)*1000)
})(atag);
}
else{
atag.target="_blank";
atag.click(function(){});
}
send_bg_msg_updatelinks(i);
findFlag=true;
break;
}
}
}
}
if(index==divs.length)
{
var intervals=Math.floor(Math.random()*6+2)*1000;//[2-7秒]
setTimeout(function() {
var spanclick=null;
var nav=document.getElementById('nav');
var spans=nav.getElementsByTagName('span');
for(var j=0;j<spans.length;j++){
if(spans[j].innerHTML.indexOf('下一页')>-1||(spans[j].innerHTML.indexOf('下一頁')>-1)){
spanclick=spans[j];
spanclick.click(function(){});
break;
}
}
}, intervals);
}
}
function getElementsByName(tag,names){
var tags=document.getElementsByTagName(tag);
for(var i=0;i<tags.length;i++)
{
for(var j=0;j<names.length;j++){
if(tags[i].name==names[j])
return tags[i];
}
}
}
function send_bg_msg_info(){
chrome.extension.sendRequest({type:"hostpage"},function(response){
googleHostPage(response.keyword);
});
}
function send_bg_msg_stratery(){
chrome.extension.sendRequest({type:"searchpage"},function(response){
for(var i=0;i<response.links.length;i++)
{
if(!response.links[i].clicked){
googleSearchPage(response.mode,response.links,response.keyword);
break;
}
}
});
}
function send_bg_msg_updatelinks(index){
var indexStr=index.toString();
chrome.extension.sendRequest({type:"updateLink"+index},function(response){
console.log("123");
});
}
function send_bg_msg_aaa(){
chrome.extension.sendRequest({type:"openTab"},function(response){
console.log("123");
});
}
//only search onne when in http://google.com.hk/ search lw+keyword and submit the form
function googleHostPage(keyword){
var search_value=keyword;
var queryText=getElementsByName("input",["q"]);
if(queryText)queryText.value=search_value;
setTimeout(function() {
var btn=getElementsByName("input",["btnK","btnG"]);
btn.click(function(){
});
}, 2000);
}
function googleSearchPage(mode,links,keyword){
if(mode==1){
setTimeout(function() {
nextPage(links);
},2000);
}
else if(mode == 2){
setTimeout(function(){
var searchTextValue=getElementsByName("input",["q"]);
if(searchTextValue.value.indexOf(" ")>-1)
nextPage(links);
else{
if(searchTextValue.value== keyword[0]){
setTimeout(function(){
searchTextValue.value = keyword[1];
},2000);
}
else if(searchTextValue.value== keyword[1]){
setTimeout(function(){
searchTextValue.value= keyword[0]+" "+keyword[1];
},2000);
}
setTimeout(function(){
var form=getElementsByName("button",["btnG"]);
form.click(function(){});
},2000);
}
},2000);
}
}
//search 3 times when in http://googole.com.hk search lw and sumbit
function autoRegister()
{
if(href=="http://www.google.com.hk/"||href=="https://www.google.com.hk/"||href=="http://www.google.com.hk/?gws_rd=ssl"||href=="https://www.google.com.hk/?gws_rd=ssl")
{
send_bg_msg_info();
}
else if(href.indexOf("http://www.google.com.hk/search?")>-1||href.indexOf("https://www.google.com.hk/search?")>-1){
send_bg_msg_stratery();;
}
}
function hashCheck() {
if(location.hash){
send_bg_msg_stratery();
}
}
window.addEventListener('hashchange', hashCheck);
window.addEventListener("load", function load(event){
window.removeEventListener("load", load, false); //remove listener, no longer needed
autoRegister();
}, false);