-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathweibotalk.js
340 lines (313 loc) · 14.6 KB
/
weibotalk.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/**********
🐬作者
@Evilbutcher。 https://github.com/evilbutcher
@toulanboy。https://github.com/toulanboy/scripts
📌不定期更新各种签到、有趣的脚本,欢迎star🌟
***********************************
【配置步骤,请认真阅读,每一个细节都很重要】
***********************************
1. 根据你当前的软件,配置好srcipt。由于是远程文件,记得顺便更新文件。
2. 打开微博APP --> 底部栏“我的“ --> 中间的”超话社区“ --> 底部栏"我的" --> ”关注“, 弹出通知,提示获取已关注超话链接成功。
3. 点进一个超话页面,手动签到一次。弹出通知,提示获取超话签到链接成功。 若之前所有已经签到,请关注一个新超话进行签到。
4. 回到quanx等软件,关掉获取cookie的rewrite。(loon是关掉获取cookie的脚本)
📌 配置第2个账号方法:第1个账号获取cookie结束后。在微博app中切换到第2个号,进行相同的获取逻辑。
***************************************
【boxjs 订阅, 用于修改脚本配置】
***************************************
box订阅链接:https://raw.githubusercontent.com/toulanboy/scripts/master/toulanboy.boxjs.json
订阅后,可以在box里面进行 cookie清空、通知个数、签到延迟 等设置.
*************************
【Surge 4.2+ 脚本配置】
*************************
微博超话cookie获取 = type=http-request,pattern=^https?://m?api\.weibo\.c(n|om)\/2\/(cardlist|page\/button),script-path=https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.cookie.js
微博超话 = type=cron,cronexp="5 0 * * *",script-path=https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.js,wake-system=true,timeout=600
*************************
【Loon 2.1+ 脚本配置】
*************************
[script]
cron "5 0 * * *" script-path=https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.js, timeout=600, tag=微博超话
http-request ^https?://m?api\.weibo\.c(n|om)\/2\/(cardlist|page\/button) script-path=https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.cookie.js,requires-body=false, tag=微博超话cookie获取
*************************
【 QX 1.0.10+ 脚本配置 】
*************************
[rewrite_local]
^https?://m?api\.weibo\.c(n|om)\/2\/(cardlist|page\/button) url script-request-header https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.cookie.js
[task]
5 0 * * * https://raw.githubusercontent.com/toulanboy/scripts/master/weibo/weibotalk.js, tag=微博超话
[MITM]
hostname = api.weibo.cn
*********/
const $ = new Env("微博超话")
/*
* 可自定义的参数
*/
$.delete_cookie = false //若需要清空cookie,请把它置为true。清空完毕后,请重新置为false.
$.msg_max_num = 30 //一个通知显示30个超话的签到情况
$.time = 700 //【签到间隔,单位ms】,若超话过多,建议填1000ms以上。
debug = false
!(async () => {
if(!get_setting()) return
if(!get_counts()) return
console.log(`🌟 账号数 = ${$.count_num}`)
for (var current = 1; current <= $.count_num; ++current) {
init_env(current)
await get_page_number();
for (var i = 1; i <= $.pagenumber; i++) {
await get_talk_id(i);
}
for (var i in $.name_list) {
await checkin($.id_list[i], $.name_list[i]);
$.wait($.time);
}
output(current)
}
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done()
})
function get_setting() {
$.delete_cookie = JSON.parse($.getdata('wb_delete_cookie') || $.delete_cookie)
$.msg_max_num = $.getdata('wb_msg_max_num') * 1 || $.msg_max_num
$.time = $.getdata('wb_request_time') * 1 || $.time
$.listurl = $.getdata("evil_tokenurl");
$.listheaders = $.getdata("evil_tokenheaders");
$.checkinurl = $.getdata("evil_tokencheckinurl");
$.checkinheaders = $.getdata("evil_tokencheckinheaders");
$.listurl2 = $.getdata("evil_tokenurl2");
$.listheaders2 = $.getdata("evil_tokenheaders2");
$.checkinurl2 = $.getdata("evil_tokencheckinurl2");
$.checkinheaders2 = $.getdata("evil_tokencheckinheaders2");
if ($.delete_cookie) {
$.setdata("", "evil_tokenurl")
$.setdata("", "evil_tokenheaders")
$.setdata("", "evil_tokencheckinurl")
$.setdata("", "evil_tokencheckinheaders")
$.setdata("", "evil_tokenurl2")
$.setdata("", "evil_tokenheaders2")
$.setdata("", "evil_tokencheckinurl2")
$.setdata("", "evil_tokencheckinheaders2")
$.setdata("false", "wb_delete_cookie")
$.msg($.name, "", "✅已清空cookie,同时已关闭清空功能。\n🔍请按流程开始获取cookie把~")
return false;
}
return true;
}
function get_counts() {
$.count_num = 0;
if ($.listurl == undefined || $.listurl == "" ||
$.listheaders == undefined || $.listheaders == "" ||
$.checkinurl == undefined || $.checkinurl == "" ||
$.checkinheaders == undefined || $.checkinheaders == "") {
$.msg($.name, "🚫cookie不完整 或 没有cookie", "🚫请认真阅读配置,按流程获取cookie。\n🔍若仍无法解决,请先清空cookie再获取。\n🔍如何清空?\n1️⃣本地文件:将文件内delete_cookie置为true。\n2️⃣远程文件:使用boxjs,在box内打开清空cookie开关")
return false;
} else {
$.count_num = 1
}
if (!($.listurl2 == undefined || $.listurl2 == "" ||
$.listheaders2 == undefined || $.listheaders2 == "" ||
$.checkinurl2 == undefined || $.checkinurl2 == "" ||
$.checkinheaders2 == undefined || $.checkinheaders2 == "")) {
$.count_num = 2;
}
return true;
}
function init_env(current) {
console.log(`🌟 清空环境,开始账号 ${current}`)
$.message = [];
$.name_list = []
$.id_list = []
$.val_list = []
$.successNum = 0
$.failNum = 0
$.allnumber = 0;
$.pagenumber = 0;
$.stopNum = 0;
if (current == 2) {
$.listurl = $.listurl2
$.listheaders = $.listheaders2
$.checkinurl = $.checkinurl2
$.checkinheaders = $.checkinheaders2
}
}
function output(current) {
$.this_msg = ""
for (var i = 1; i <= $.message.length; ++i) {
if (i % ($.msg_max_num) == 0) {
$.msg(`${$.name}${$.count_num==1?"":(current==1?"[账号一]":"[账号二]")}: 成功${$.successNum}个,失败${$.failNum}`, `当前第${Math.ceil(i/$.msg_max_num)}页 ,共${Math.ceil($.message.length/$.msg_max_num)}页`, $.this_msg)
$.this_msg = ""
}
$.this_msg += `${$.message[i-1]}\n`
}
if ($.message.length % $.msg_max_num != 0) {
$.msg(`${$.name}${$.count_num==1?"":(current==1?"[账号一]":"[账号二]")}: 成功${$.successNum}个,失败${$.failNum}`, `当前第${Math.ceil((i-1)/$.msg_max_num)}页 ,共${Math.ceil($.message.length/$.msg_max_num)}页`, $.this_msg)
}
}
function get_page_number() {
return new Promise((resolve) => {
var idrequest = {
url: $.listurl,
header: $.listheaders
};
$.get(idrequest, (error, response, data) => {
if (error) {
throw new Error(error)
}
var body = response.body;
var obj = JSON.parse(body);
if (obj.hasOwnProperty('errmsg')||obj.cardlistInfo.total==undefined||obj.cardlistInfo.total==null) {
$.msg($.name, "🚨获取页数出现错误", `⚠️微博原话:${obj.errmsg}\n🧑🏻💻作者:账号过期了,清空cookie吧,重新获取。`)
$.pagenumber = 0
resolve()
return
}
$.allnumber = obj.cardlistInfo.total;
console.log("当前已关注超话" + $.allnumber + "个");
// $.message.push(`当前已关注超话${allnumber}个`);
$.pagenumber = Math.ceil($.allnumber / 20);
//$notify("超话","",JSON.stringify($.message))
resolve();
});
});
}
//获取超话签到id
function get_talk_id(page) {
var getlisturl = $.listurl.replace(
new RegExp("&page=.*?&"),
"&page=" + page + "&"
);
//console.log(getlisturl);
var idrequest = {
url: getlisturl,
header: $.listheaders
};
// console.log(idrequest)
return new Promise((resove) => {
$.get(idrequest, (error, response, data) => {
if (error) {
throw new Error(error)
}
var body = response.body;
var obj = JSON.parse(body);
if (obj.hasOwnProperty('errmsg')||obj.cards==undefined||obj.cards==null) {
$.msg($.name, "🚨获取超话ID出现错误", `⚠️微博原话:${obj.errmsg}\n`)
resolve()
return
}
var group = obj.cards[0]["card_group"];
number = group.length;
for (i = 0; i < number; i++) {
var name = group[i]["title_sub"];
$.name_list.push(name)
var val = group[i].desc;
$.val_list.push(val)
var id = group[i].scheme.slice(33, 71);
$.id_list.push(id)
if (debug) {
console.log(name)
console.log(val)
console.log(id)
}
// checkin(id, name, val, time);
}
resove()
})
})
}
//签到
function checkin(id, name) {
var sendcheckinurl = $.checkinurl
.replace(new RegExp("&fid=.*?&"), "&fid=" + id + "&")
.replace(new RegExp("pageid%3D.*?%26"), "pageid%3D" + id + "%26");
var checkinrequest = {
url: sendcheckinurl,
header: $.checkinheaders
};
return new Promise(resolve => {
$.get(checkinrequest, (error, response, data) => {
if (error) {
throw new Error(error)
}
name = name.replace(/超话/, "")
if (response.statusCode == 200) {
msg_info = JSON.parse(response.body);
if(msg_info.hasOwnProperty('error_msg')){
$.failNum += 1;
error_code = msg_info.error_msg.match(/\((\d*?)\)/)[1]
if(error_code == 382004){
$.message.push(`【${name}】:✨今天已签到`);
console.log(`【${name}】:${msg_info.error_msg}`);
}
else{
$.message.push(`【${name}】:${msg_info.error_msg}`);
console.log(`【${name}】:"未知错误⚠️ 该请求的返回情况如下"`);
console.log(response.body)
}
}
else if (msg_info.hasOwnProperty('result') && msg_info.result == 1) {
$.successNum += 1
$.message.push(`【${name}】:✅${msg_info.button.name}`)
console.log(`【${name}】:${msg_info.button.name}`);
}
else{
$.failNum += 1
$.message.push(`【${name}】:未知错误⚠️`);
console.log(`【${name}】:"未知错误⚠️ 该请求的返回情况如下"`);
console.log(response.body)
}
}else if ((response.statusCode == 418)) {
$.failNum += 1
$.message.push(`【${name}】:"签到太频繁啦,请稍后再试"`);
console.log(`【${name}】:"签到太频繁啦,请稍后再试"`);
} else if (response.statusCode == 511) {
$.failNum += 1;
$.message.push(`【${name}】:"需要身份验证,请稍后再试"`);
console.log(`【${name}】:"需要身份验证,请稍后再试"`);
} else {
$.failNum += 1
$.message.push(`【${name}】:未知错误⚠️`);
console.log(`【${name}】:"未知错误⚠️ 该请求的返回情况如下"`);
console.log(JSON.stringify(response))
}
resolve();
})
})
}
//@Chavy
function Env(s) {
this.name = s, this.data = null, this.logs = [], this.isSurge = (() => "undefined" != typeof $httpClient), this.isQuanX = (() => "undefined" != typeof $task), this.isNode = (() => "undefined" != typeof module && !!module.exports), this.log = ((...s) => {
this.logs = [...this.logs, ...s], s ? console.log(s.join("\n")) : console.log(this.logs.join("\n"))
}), this.msg = ((s = this.name, t = "", i = "") => {
this.isSurge() && $notification.post(s, t, i), this.isQuanX() && $notify(s, t, i);
const e = ["", "==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];
s && e.push(s), t && e.push(t), i && e.push(i), console.log(e.join("\n"))
}), this.getdata = (s => {
if (this.isSurge()) return $persistentStore.read(s);
if (this.isQuanX()) return $prefs.valueForKey(s);
if (this.isNode()) {
const t = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), this.fs.existsSync(t) ? (this.data = JSON.parse(this.fs.readFileSync(t)), this.data[s]) : null
}
}), this.setdata = ((s, t) => {
if (this.isSurge()) return $persistentStore.write(s, t);
if (this.isQuanX()) return $prefs.setValueForKey(s, t);
if (this.isNode()) {
const i = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), !!this.fs.existsSync(i) && (this.data = JSON.parse(this.fs.readFileSync(i)), this.data[t] = s, this.fs.writeFileSync(i, JSON.stringify(this.data)), !0)
}
}), this.wait = ((s, t = s) => i => setTimeout(() => i(), Math.floor(Math.random() * (t - s + 1) + s))), this.get = ((s, t) => this.send(s, "GET", t)), this.post = ((s, t) => this.send(s, "POST", t)), this.send = ((s, t, i) => {
if (this.isSurge()) {
const e = "POST" == t ? $httpClient.post : $httpClient.get;
e(s, (s, t, e) => {
t && (t.body = e, t.statusCode = t.status), i(s, t, e)
})
}
this.isQuanX() && (s.method = t, $task.fetch(s).then(s => {
s.status = s.statusCode, i(null, s, s.body)
}, s => i(s.error, s, s))), this.isNode() && (this.request = this.request ? this.request : require("request"), s.method = t, s.gzip = !0, this.request(s, (s, t, e) => {
t && (t.status = t.statusCode), i(null, t, e)
}))
}), this.done = ((s = {}) => this.isNode() ? null : $done(s))
}