|
| 1 | +const $ = new Env('有道云笔记') |
| 2 | +$.VAL_sign_url = $.getdata('chavy_signurl_noteyoudao') |
| 3 | +$.VAL_sign_body = $.getdata('chavy_signbody_noteyoudao') |
| 4 | +$.VAL_sign_headers = $.getdata('chavy_signheaders_noteyoudao') |
| 5 | + |
| 6 | +!(async () => { |
| 7 | + $.log('', `🔔 ${$.name}, 开始!`, '') |
| 8 | + await signinapp() |
| 9 | + await logindaily() |
| 10 | + await showmsg() |
| 11 | +})() |
| 12 | + .catch((e) => { |
| 13 | + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') |
| 14 | + }) |
| 15 | + .finally(() => { |
| 16 | + $.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done() |
| 17 | + }) |
| 18 | + |
| 19 | +function logindaily() { |
| 20 | + const url = { url: 'https://note.youdao.com/yws/api/daupromotion?method=sync', headers: JSON.parse($.VAL_sign_headers) } |
| 21 | + return new Promise((resove) => { |
| 22 | + $.post(url, (error, response, data) => { |
| 23 | + try { |
| 24 | + if (error) throw new Error(error) |
| 25 | + $.log(`❕ ${$.name}, 每日登录: ${data}`) |
| 26 | + $.daily = JSON.parse(data) |
| 27 | + } catch (e) { |
| 28 | + $.log(`❗️ ${$.name}, 每日登录: 失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '') |
| 29 | + } finally { |
| 30 | + resove() |
| 31 | + } |
| 32 | + }) |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +function signinapp() { |
| 37 | + const url = { url: $.VAL_sign_url, body: $.VAL_sign_body, headers: JSON.parse($.VAL_sign_headers) } |
| 38 | + return new Promise((resove) => { |
| 39 | + $.post(url, (error, response, data) => { |
| 40 | + try { |
| 41 | + if (error) throw new Error(error) |
| 42 | + $.log(`❕ ${$.name}, 每日签到: ${data}`) |
| 43 | + $.signin = JSON.parse(data) |
| 44 | + } catch (e) { |
| 45 | + $.log(`❗️ ${$.name}, 每日登录: 失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '') |
| 46 | + } finally { |
| 47 | + resove() |
| 48 | + } |
| 49 | + }) |
| 50 | + }) |
| 51 | +} |
| 52 | + |
| 53 | +function showmsg() { |
| 54 | + return new Promise((resove) => { |
| 55 | + const dailyFlag = $.daily.accept === true ? '成功' : '重复' |
| 56 | + const signinFlag = $.signin.success === 1 ? '成功' : $.signin.success === 0 ? '重复' : '错误' |
| 57 | + $.subt = `每日登录: ${dailyFlag}, 每日签到: ${signinFlag}` |
| 58 | + const continuousDays = `连签: ${$.daily.rewardSpace / 1024 / 1024}天` |
| 59 | + const rewardSpace = `本次获得: ${$.daily.rewardSpace / 1024 / 1024}MB` |
| 60 | + const totalReward = `总共获得: ${$.daily.totalRewardSpace / 1024 / 1024}MB` |
| 61 | + $.desc = `${continuousDays}, ${rewardSpace}, ${totalReward}` |
| 62 | + resove() |
| 63 | + }) |
| 64 | +} |
| 65 | + |
| 66 | +// prettier-ignore |
| 67 | +function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i),this.log("==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),t&&this.log(t),s&&this.log(s),i&&this.log(i)}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))} |
0 commit comments