-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgethtml.js
More file actions
108 lines (100 loc) · 3.44 KB
/
gethtml.js
File metadata and controls
108 lines (100 loc) · 3.44 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
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
// ==UserScript==
// @name 进入链接读取html
// @namespace gethtml
// @description 进入链接读取html
// @version 1.0
// @grant Chang
// ==/UserScript==
(function() {
console.log('pachongceshi');
var topdiv = document.createElement('div');
var btn = document.createElement('button');
var input = document.createElement('input');
var timeInterval;
var isGo = false;
var reload = () => {
isGo = false;
btn.style.backgroundColor = '#090';
btn.innerText = '开始 ' + input.value;
clearInterval(timeInterval);
btn.onclick = startBtn;
};
var init = function(value) {
var end = 27547;
var getPage = (indexppppp) => {
input.value = indexppppp;
if (indexppppp <= end) {
var $content = document.getElementById('content');
var $list = $content.querySelectorAll('a');
if ($list && $list.length) {
const retList = [];
for (let i = 0; i < $list.length; i += 1) {
const item = $list[i];
retList.push({
name: item.innerText,
url: item.href,
});
}
var data = {
index: indexppppp,
data: retList,
};
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:9000/pachong', true);
xhr.setRequestHeader('Content-Type', 'appivation/form-data');
xhr.send(JSON.stringify(data));
console.log('go', indexppppp);
xhr.onreadystatechange = () => {
//响应信息返回后处理,在页面提示用户
if (xhr.readyState === 4 && isGo) {
console.log('result', indexppppp, xhr);
$imgList = $content.querySelectorAll('img');
if ($imgList && $imgList.length) {
$imgList[2].click();
setTimeout(() => {
getPage(indexppppp + 1);
}, 2000);
} else {
reload();
console.error('出错了,页码:', indexppppp);
}
}
};
} else {
reload();
console.error('页码报错,当前页码', indexppppp);
}
}
};
if (Number(value)) {
getPage(Number(value));
} else {
console.error('请输入正确的数字');
}
};
var startBtn = () => {
isGo = true;
btn.style.backgroundColor = '#f00';
var itime = 0;
var BtnTime = function() {
btn.innerText = '正在扒东西,请稍等(' + (itime = itime + 0.1).toFixed(2) + 's)';
};
timeInterval = setInterval(BtnTime, 100);
init(input.value);
btn.onclick = reload;
};
topdiv.style = 'width: 100%; height: 40px; position: relative; opacity: 0;';
input.id = 'pachonginput';
input.value = '1';
input.style =
'width: 100%; height: 40px; display: block; font-size: 14px; position: fixed; top: 0; left: 0; z-index: 9999999999999;';
btn.id = 'ChangImgGoToDown';
btn.value = '开始';
btn.innerText = '开始';
btn.style =
'width: 100%; height: 40px; display: block; font-size: 14px; position: fixed; top: 40px; left: 0; z-index: 9999999999999; background-color: #090; color: #fff;';
btn.onclick = startBtn;
document.body.insertBefore(input, document.getElementsByTagName('table')[0]);
document.body.insertBefore(btn, document.getElementsByTagName('table')[0]);
document.body.insertBefore(topdiv, document.getElementsByTagName('table')[0]);
})();