-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaozhishu.js
90 lines (88 loc) · 2.53 KB
/
taozhishu.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
// ==UserScript==
// @name ZhishuBot2
// @namespace ZhishuBot2
// @version 0.1.1
// @description help
// @include http://shu.taobao.com/*
// @copyright 2013 Cooper
// @run-at document-end
// ==/UserScript==
if ($('#q').val() === '') {
fetch_keyword();
} else {
if (window.location.pathname == "/trendindex") {
// 市场趋势
// get_data('query');
// get_data('trade');
// get_data('query,trade');
var data = $('div#nav').next()[0].innerText;
data = $.parseJSON(data.substring(data.indexOf('{'), data.indexOf(')')));
console.log(data);
console.log(JSON.stringify(data));
post_data(data);
var types = data.types.join(',');
// types = 'holder';
if (types == 'query') {
$('div#trend .select_box a.tab')[1].click();
setInterval(function() {
location.reload();
}, 3000);
} else if (types == 'trade') {
$('div#trend .select_box a.tab')[0].click();
setInterval(function() {
fetch_keyword();
}, 2000);
} else if (types == 'query,trade') {
// 取消对第三个标签的处理
$('div#trend .select_box a.tab')[0].click();
setInterval(function() {
fetch_keyword();
}, 2000);
}
} else if (window.location.pathname == "/search") {
// 市场细分
var data = $('footer').prev()[0].innerText;
console.log(data);
}
}
/*
* 将数据 POST 到 Py 服务端
* {
* data: {} # 数据
* type: query/trade/query,trade # 三种,分别代表搜索指数/成交指数/搜索与成交指数
* }
*/
function post_data(data) {
$.ajax({
type: 'POST',
url: 'http://localhost:8866',
crossDomain: true,
data: {
'data': JSON.stringify(data),
'type': data.types.join(',')
},
dataType: 'json',
success: function(result, textStatus, jqXHR) {
console.log(result);
}
});
}
/*
* 从服务器获取需要抓包的关键词并填充
*/
function fetch_keyword() {
$.ajax({
type: 'GET',
url: 'http://localhost:8866',
crossDomain: true,
dataType: 'json',
success: function(result, textStatus, jqXHR) {
keyword = result.keyword;
if ($('#q').val() !== '' && keyword === null) {
return;
}
$('#q').val(keyword);
$('#query-btn').click();
}
});
}