-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchrome.js
65 lines (63 loc) · 2.18 KB
/
chrome.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
let timer = null
let index = 0
let successNums = 0
let failNums = 0
let listUrl = 'https://lahei.xyz/api/v1/public/get-supervisor-list'
let userList
let last = localStorage.getItem('last_block') || 0
let block_url = `${location.protocol}//weibo.com/aj/filter/block?ajwvr=6`
function fetch(url, model) {
return new Promise((resolve, reject) => {
if (userList && index >= userList.length) {
console.log(`任务完成\n成功:${successNums}\n 失败:${failNums}`);
localStorage.setItem('last_block', parseInt(Date.now() / 1000))
return clearInterval(timer)
}
let http = new XMLHttpRequest()
if (model === 'GET') {
http.open('GET', url, true)
http.send()
}
if (model === 'POST') {
http.open('POST', url, true)
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
http.send('uid=' + userList[index].uid + '&filter_type=1&status=1&interact=1&follow=1')
}
http.onreadystatechange = function () {
if (http.readyState === 4 && http.status === 200) {
let res
try {
res = JSON.parse(http.responseText)
} catch (e) {
console.log('网络错误');
}
if (model === 'GET' && res) {
resolve(res.data)
}
if (model === 'POST' && res.code === '100000') {
console.log(`拉黑成功,第${index + 1}个`)
successNums++
index++
resolve()
} else {
if (model === 'POST') {
console.log(`拉黑失败,第${index + 1}个`)
failNums++
index++
reject()
}
}
}
};
})
}
;
(async() => {
userList = await fetch(`${listUrl}?last=${last}`, 'GET')
if (userList.length === 0) {
return alert('列表没有更新')
}
timer = setInterval(function () {
fetch(block_url, 'POST')
}, 2000)
})()