前言:一定要知道每一个命令是啥意思,并且要学会看报错信息,学会使用搜索引擎。
前情回顾:小白实战学习Liunx(图文教程四)_chinassj的博客-CSDN博客
本文学习青龙面板如何手动添加任务:鸣谢:
1.添加脚本
2.编辑脚本:
复制黏贴下面的代码,记得右上角保存
/*cron 51 9 * * * juejin_signin.js掘金社区更新时间:2021-09-06活动入口:.js脚本兼容: Node.js脚本二创 harry27 ***********************************************************感谢原作者 hccluck */const $ = new Env('掘金社区');
const notify = $.isNode() ? require('./sendNotify') : '';
const fetch = require('node-fetch');
// const sendMail = require('./sendMail');
const cookie = v.JUEJIN_COOKIE || ''let score = 0;const headers = {'content-type': 'application/json; charset=utf-8','user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36','accept-encoding': 'gzip, deflate, br','accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7','sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"','sec-ch-ua-mobile': '?0',referer: '/',accept: '*/*',cookie
};// 抽奖
const drawFn = async () => {// 查询今日是否有免费抽奖机会const today = await fetch('', {headers,method: 'GET',credentials: 'include'}).then((res) => res.json());if (_no !== 0) ject('已经签到!免费抽奖失败!');if (today.data.free_count === 0) solve('签到成功!今日已经免费抽奖!');// 免费抽奖const draw = await fetch('', {headers,method: 'POST',credentials: 'include'}).then((res) => res.json());if (_no !== 0) ject('已经签到!免费抽奖异常!');console.log(JSON.stringify(draw, null, 2));if (draw.data.lottery_type === 1) score += 66;solve(`签到成功!恭喜抽到:${draw.data.lottery_name}`);
};// 签到
(async () => {// 检查cookie是否存在if(!cookie) ject('cookie不能为空!');// 查询今日是否已经签到const today_status = await fetch('', {headers,method: 'GET',credentials: 'include'}).then((res) => res.json());if (_no !== 0) ject('签到失败!');if (today_status.data) solve('今日已经签到!');// 签到const check_in = await fetch('', {headers,method: 'POST',credentials: 'include'}).then((res) => res.json());if (_no !== 0) ject('签到异常!');solve(`签到成功!当前积分;${check_in.data.sum_point}`);
})().then((msg) => {console.log(msg);return fetch('', {headers,method: 'GET',credentials: 'include'}).then((res) => res.json());}).then((res) => {console.log(res);score = res.data;return drawFn();}).then((msg) => {console.log(msg);notify.sendNotify(`掘金签到通知`,`签到结果:${msg}n`,`当前积分:${score}n`)}).then(() => {// console.log('邮件发送成功!');}).catch((err) => {notify.sendNotify(`掘金签到通知`,`签到结果:${err}n`,`当前积分:${score}n`)});// prettier-ignore
function Env(t,e){"undefined"!=typeof process&&JSON.v).indexOf("GITHUB")>-1&&it(0);class s{constructor(t){v=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let sreturn"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.v,t)}post(t){return this.send.v,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!ports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}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;const idata(t);if(i)try{s=JSON.data(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let idata("@chavy_boxjs_userCfgs.httpapi");i=place(/n/g,"").trim():i;let rdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).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");const t=solve(this.dataFile),e=solve(process.cwd(),this.dataFile),s=istsSync(t),i=!s&&istsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(adFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=solve(this.dataFile),e=solve(process.cwd(),this.dataFile),s=istsSync(t),i=!s&&istsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const iplace(/[(d+)]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(eString().match(/[^.[]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let eval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?).(.*?)$/.exec(t),r=val(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?).(.*?)$/.exec(e),oval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$ad(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){?: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==kieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),Milliseconds()};/(y+)/.test(t)&&(tplace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(tplace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],sdiaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("n")),this.logs=at(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)}
4.添加定时任务:
5.登录后获取掘金cookie: 掘金 - 代码不止,掘金不停
6.添加配置文件变量(cookie换成上面的)
export JUEJIN_COOKIE="cookie"
7.手动执行以下掘金的定时任务:签到成功
本文发布于:2024-01-29 02:09:16,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170646536111970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |