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