|
1 | | -const cookieName = "百度贴吧"; |
2 | | -const cookieKey = "chavy_cookie_tieba"; |
3 | | -const cookieVal = $prefs.valueForKey(cookieKey); |
| 1 | +const cookieName = '百度贴吧' |
| 2 | +const cookieKey = 'chavy_cookie_tieba' |
| 3 | +const cookieVal = $prefs.valueForKey(cookieKey) |
4 | 4 |
|
5 | 5 | function sign() { |
6 | 6 | let url = { |
7 | | - url: `http://tieba.baidu.com/f/like/mylike`, |
| 7 | + url: `https://tieba.baidu.com/mo/q/newmoindex`, |
8 | 8 | headers: { |
9 | 9 | Cookie: cookieVal |
10 | 10 | } |
11 | | - }; |
12 | | - $task.fetch(url).then(response => { |
13 | | - let data = response.body; |
14 | | - let regex = /\/f\?kw=([^{'"}]*)/g; |
15 | | - let cnt = 0; |
16 | | - for (const bar of data.matchAll(regex)) { |
17 | | - cnt += 1; |
18 | | - setTimeout(() => signBar(bar), cnt * 500); |
| 11 | + } |
| 12 | + |
| 13 | + $task.fetch(url).then((response) => { |
| 14 | + let data = response.body |
| 15 | + let result = JSON.parse(data) |
| 16 | + let tbs = result.data.tbs |
| 17 | + let forums = result.data.like_forum |
| 18 | + let signinfo = { |
| 19 | + forumCnt: forums.length, |
| 20 | + signedCnt: 0, |
| 21 | + successCnt: 0, |
| 22 | + failedCnt: 0, |
| 23 | + skipedCnt: 0 |
| 24 | + } |
| 25 | + |
| 26 | + let singIndex = 0 |
| 27 | + for (const bar of forums) { |
| 28 | + // 已签 |
| 29 | + if (bar.is_sign == 1) { |
| 30 | + signinfo.signedCnt += 1 |
| 31 | + signinfo.skipedCnt += 1 |
| 32 | + console.log(`签到跳过: ${bar.forum_name}, 原因: 重复签到`) |
| 33 | + } |
| 34 | + // 未签 |
| 35 | + else { |
| 36 | + singIndex += 1 |
| 37 | + setTimeout( |
| 38 | + () => |
| 39 | + signBar(bar, tbs, (response) => { |
| 40 | + let data = response.body |
| 41 | + let signresult = JSON.parse(data) |
| 42 | + if (signresult.no == 0 || signresult.no == 1011) { |
| 43 | + signinfo.signedCnt += 1 |
| 44 | + signinfo.successCnt += 1 |
| 45 | + console.log(`签到成功: ${bar.forum_name}`) |
| 46 | + } else { |
| 47 | + signinfo.failedCnt += 1 |
| 48 | + console.log(`签到失败: ${bar[1]}, 编码: ${signresult.no}, 原因: ${signresult.error}`) |
| 49 | + } |
| 50 | + }), |
| 51 | + singIndex * 100 |
| 52 | + ) |
| 53 | + } |
19 | 54 | } |
20 | | - }); |
| 55 | + check(forums, signinfo) |
| 56 | + }) |
21 | 57 | } |
22 | 58 |
|
23 | | -function signBar(bar) { |
| 59 | +function signBar(bar, tbs, cb) { |
24 | 60 | let url = { |
25 | | - url: `http://tieba.baidu.com/sign/add?ie=utf-8&kw=${bar[1]}`, |
26 | | - method: "POST", |
27 | | - headers: { Cookie: cookieVal } |
28 | | - }; |
29 | | - $task.fetch(url).then(response => { |
30 | | - let data = response.body; |
31 | | - let result = JSON.parse(data); |
32 | | - if (result.no == 0) { |
33 | | - console.log(`正在签到: ${bar[1]}, 签到成功`); |
| 61 | + url: `http://tieba.baidu.com/sign/add`, |
| 62 | + method: 'POST', |
| 63 | + headers: { Cookie: cookieVal }, |
| 64 | + body: `ie=utf-8&kw=${bar.forum_name}&tbs=${tbs}` |
| 65 | + } |
| 66 | + $task.fetch(url).then(cb) |
| 67 | +} |
| 68 | + |
| 69 | +function check(forums, signinfo, checkms = 0) { |
| 70 | + if (signinfo.forumCnt == signinfo.signedCnt) { |
| 71 | + let title = `签到结果: ${cookieName}` |
| 72 | + let subTitle = `` |
| 73 | + let detail = `今日共签: ${signinfo.signedCnt}, 本次成功: ${signinfo.successCnt}, 失败: ${signinfo.failedCnt}, 跳过: ${signinfo.skipedCnt}` |
| 74 | + |
| 75 | + // 成功数+跳过数=总数 = 全部签到完成 |
| 76 | + if (signinfo.successCnt + signinfo.skipedCnt == signinfo.signedCnt) { |
| 77 | + subTitle = `全部签到完成` |
| 78 | + } else { |
| 79 | + subTitle = `部分签到完成` |
| 80 | + } |
| 81 | + console.log(`${title}, ${subTitle}, ${detail}`) |
| 82 | + $notify(title, subTitle, detail) |
| 83 | + } else { |
| 84 | + if (checkms > 5000) { |
34 | 85 | } else { |
35 | | - console.log( |
36 | | - `正在签到: ${bar[1]}, 错误编码: ${result.no}, 错误原因: ${result.error}` |
37 | | - ); |
| 86 | + setTimeout(() => check(forums, signinfo, checkms + 100), 100) |
38 | 87 | } |
39 | | - }); |
| 88 | + } |
40 | 89 | } |
41 | 90 |
|
42 | | -sign(); |
| 91 | +sign() |
0 commit comments