-
Notifications
You must be signed in to change notification settings - Fork 1
/
skyeye.js
137 lines (128 loc) · 4.32 KB
/
skyeye.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
// ==UserScript==
// @name 天眼查-统一社会信用代码
// @namespace http://www.creditchina.gov.cn
// @version 1.0.0
// @license LGPL-3.0
// @description 获取天眼查网统一社会信用代码
// @author isaac
// @include *://www.tianyancha.com/search*
// @include *://www.tianyancha.com/company/*
// @updateURL https://tampermonkey.isaacxu.com/skyeye.js
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @supportURL https://github.com/meterXu/mtMonkeyJs
// @run-at document-idle
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function () {
'use strict';
let requireCrawl = null;
let i=0;
let rp=1;
let timer=null;
let sleepTime=1000*60*5;
let baseUrl='http://localhost:3000';
let action={
search:'/getData',
update:'/updateData'
};
$(function(){
let key = getRequest()['key']
let iscompany = window.location.href.indexOf('company')>-1
if(key){
openNewTab();
}else if(iscompany){
setTimeout(c=>{
inDb([{
trade_code:localStorage.getItem('trade_code'),
social_credit_code:$(".block-data table:eq(1) tr:eq(2) td:eq(1)").text(),
trade_full_name:$("h1[class='name']").text(),
}],c=>{
window.opener=null;
window.open('','_self');
window.close();
});
},5000);
}else{
initData();
}
});
function initData(){
$.ajax({
url:baseUrl+action.search,
type:'get',
dataType:'json',
data:{page:1,rp:rp},
success:function(res){
timer=null;
i=0;
$("#showRcount").remove();
$("body").append(`<div id="showRcount" style="position: fixed;top: 200px;right: 0px;padding: 0 10px;min-width: 100px;height: 40px;line-height: 40px;text-align: center;font-size: 16px;background: cadetblue;">剩余抓取数量:<span style="color:#fff;font-weight: bold">${res.rCount}</span></div>`)
if(res.data&&res.data.length>0){
initGet(res.data);
}else{
setTimeout(c=>{
initData()
},sleepTime)
}
}
});
}
function initGet(datas){
let interval=getInterval();
console.log(`[${new Date().toLocaleString()}]${interval/1000}秒后开始抓取数据`)
timer=window.setTimeout(c=>{
getData(datas,i);
},interval);
}
function inDb(datas,callback){
$.ajax({
url:baseUrl+action.update,
type:'put',
dataType:'json',
data:{entityList:datas},
success:function(res){
if(res.success){
console.log(`[${new Date().toLocaleString()}]更新数据成功`)
}
},
complete:function(){
callback&&callback()
}
});
}
function getData(datas,index){
localStorage.setItem('trade_code',datas[index].trade_code);
$("#header-company-search").val(datas[index].trade_name);
$(".search-group .input-group-btn:first").trigger('click')
}
function getInterval() {
let rd = Math.floor(Math.random()*10-4);
if(rd<=3){
rd=3
}
return (10+rd)*1000;
}
function getRequest () {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
theRequest.count = 0;
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
theRequest.count++;
}
}
return theRequest;
}
function openNewTab(){
if($(".result-list .search-item").length>0){
let url=$(".result-list .search-item:first .select-none").prop('href')
window.open(url,"_blank")
initData();
}
}
})();