diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..25bcb91d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +node_modules/* +.DS_Store + +.vscode +.idea + +test/* +tncj/* +*/unblock/* +*.private.* +*.dat +*copy.js \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..6b1caa4ee --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "quoteProps": "consistent", + "semi": false, + "singleQuote": true, + "trailingComma": "none" +} diff --git a/10000/10000.js b/10000/10000.js index 23cca1d6e..61d529def 100644 --- a/10000/10000.js +++ b/10000/10000.js @@ -135,4 +135,4 @@ function encrypt(word) { } // prettier-ignore -function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch{return{}}}}}writedata(){if(this.isNode){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),o=JSON.stringify(this.data);e?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(s,o):this.fs.writeFileSync(t,o)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return e;return o}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),o=e?this.getval(e):"";if(o)try{const t=JSON.parse(o);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(s),h=this.getval(i),a=i?"null"===h?null:h||"{}":"{}";try{const s=JSON.parse(a);this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i),console.log(`${i}: ${JSON.stringify(s)}`)}catch{const s={};this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i),console.log(`${i}: ${JSON.stringify(s)}`)}}else e=$.setval(t,s);return e}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||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,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t))}}msg(s=t,e="",i="",o){this.isSurge()||this.isLoon()?$notification.post(s,e,i):this.isQuanX()&&$notify(s,e,i),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t=null){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)} +function Env(t,e){class s{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,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,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("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}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 i=this.getdata(t);if(i)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,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(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 i=e.replace(/\[(\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)||(e=e.toString().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 e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(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),o=this.getval(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()?$persistentStore.read(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){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=(()=>{})){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})),$httpClient.get(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),this.got(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}=t;this.got.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){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).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"],s=t.mediaUrl||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=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(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("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} diff --git a/10000/README.md b/10000/README.md index a5e38de2f..bda7e8449 100644 --- a/10000/README.md +++ b/10000/README.md @@ -10,7 +10,7 @@ wapside.189.cn:9001 [Script] -http-request ^https:\/\/wapside.189.cn:9001\/api\/home\/homeInfo script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.cookie.js, requires-body=true +http-request ^https:\/\/wapside.189.cn:9001\/jt-sign\/api\/home\/homeInfo script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.cookie.js, requires-body=true cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.js ``` diff --git a/10010/10010.js b/10010/10010.js index 388faaa76..3180a18e0 100644 --- a/10010/10010.js +++ b/10010/10010.js @@ -40,8 +40,9 @@ let gosign = JSON.parse(chavy.getdata("chavy_gosign_10010")||chavygosign) } await getinfo() showmsg() - chavy.done() -})().catch((e) => chavy.log(`❌ ${cookieName} 签到失败: ${e}`), chavy.done()) +})() + .catch((e) => chavy.log(`❌ ${cookieName} 签到失败: ${e}`)) + .finally(() => chavy.done()) function loginapp() { return new Promise((resolve, reject) => { diff --git a/10086/10086.fee.cookie.js b/10086/10086.fee.cookie.js deleted file mode 100644 index c2464b0c8..000000000 --- a/10086/10086.fee.cookie.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * hostname = clientaccess.10086.cn - * - * # Surge - * Rewrite: CMCC = type=http-request,pattern=^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js,requires-body=true,debug=true - * Rewrite: CMCC = type=http-request,pattern=^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js,requires-body=true,debug=true - * Tasks: 10086-查话费 = type=cron,cronexp=10 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js,wake-system=true - * - * # QuanX - * ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js - * ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js - * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=10086-查话费 - * - * # Loon - * http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true - * http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true - * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js - * - */ - -const $ = new Env('中国移动') -$.KEY_autologin = 'chavy_autologin_cmcc' -$.KEY_getfee = 'chavy_getfee_cmcc' - -!(async () => { - const session = {} - session.url = $request.url - session.body = $request.body - session.headers = $request.headers - let key = '' - if (/autoLogin/.test(session.url)) { - key = $.KEY_autologin - } else if (/getRealFee/.test(session.url)) { - key = $.KEY_getfee - } - if ($.setdata(JSON.stringify(session), key)) { - $.subt = `获取会话: 成功! (${key})` - } else { - $.subt = `获取会话: 失败! (${key})` - } - $.msg($.name, $.subt, $.desc) -})() - .catch((e) => $.logErr(e)) - .finally(() => $.done()) - -// prettier-ignore -function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),o=JSON.stringify(this.data);e?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(s,o):this.fs.writeFileSync(t,o)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return e;return o}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),o=e?this.getval(e):"";if(o)try{const t=JSON.parse(o);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(s),h=this.getval(i),a=i?"null"===h?null:h||"{}":"{}";try{const s=JSON.parse(a);this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i),console.log(`${i}: ${JSON.stringify(s)}`)}catch(s){const h={};this.lodash_set(h,o,t),e=this.setval(JSON.stringify(h),i),console.log(`${i}: ${JSON.stringify(h)}`)}}else e=$.setval(t,s);return e}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||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,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t))}}msg(s=t,e="",i="",o){const h=t=>!t||!this.isLoon()&&this.isSurge()?t:"string"==typeof t?this.isLoon()?t:this.isQuanX()?{"open-url":t}:void 0:"object"==typeof t&&(t["open-url"]||t["media-url"])?this.isLoon()?t["open-url"]:this.isQuanX()?t:void 0:void 0;this.isSurge()||this.isLoon()?$notification.post(s,e,i,h(o)):this.isQuanX()&&$notify(s,e,i,h(o)),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)} diff --git a/Env.js b/Env.js index 8cb5abb00..d2ed4cbfd 100644 --- a/Env.js +++ b/Env.js @@ -10,12 +10,26 @@ function Env(name, opts) { if (method === 'POST') { sender = this.post } - return new Promise((resolve, reject) => { + + const delayPromise = (promise, delay = 1000) => { + return Promise.race([ + promise, + new Promise((resolve, reject) => { + setTimeout(() => { + reject(new Error('请求超时')) + }, delay) + }) + ]) + } + + const call = new Promise((resolve, reject) => { sender.call(this, opts, (err, resp, body) => { if (err) reject(err) else resolve(resp) }) }) + + return opts.timeout ? delayPromise(call, opts.timeout) : call } get(opts) { @@ -29,32 +43,61 @@ function Env(name, opts) { return new (class { constructor(name, opts) { + this.logLevels = { debug: 0, info: 1, warn: 2, error: 3 } + this.logLevelPrefixs = { + debug: '[DEBUG] ', + info: '[INFO] ', + warn: '[WARN] ', + error: '[ERROR] ' + } + this.logLevel = 'info' this.name = name this.http = new Http(this) this.data = null this.dataFile = 'box.dat' this.logs = [] this.isMute = false + this.isNeedRewrite = false this.logSeparator = '\n' + this.encoding = 'utf-8' this.startTime = new Date().getTime() Object.assign(this, opts) this.log('', `🔔${this.name}, 开始!`) } + getEnv() { + if ('undefined' !== typeof $environment && $environment['surge-version']) + return 'Surge' + if ('undefined' !== typeof $environment && $environment['stash-version']) + return 'Stash' + if ('undefined' !== typeof module && !!module.exports) return 'Node.js' + if ('undefined' !== typeof $task) return 'Quantumult X' + if ('undefined' !== typeof $loon) return 'Loon' + if ('undefined' !== typeof $rocket) return 'Shadowrocket' + } + isNode() { - return 'undefined' !== typeof module && !!module.exports + return 'Node.js' === this.getEnv() } isQuanX() { - return 'undefined' !== typeof $task + return 'Quantumult X' === this.getEnv() } isSurge() { - return 'undefined' !== typeof $httpClient && 'undefined' === typeof $loon + return 'Surge' === this.getEnv() } isLoon() { - return 'undefined' !== typeof $loon + return 'Loon' === this.getEnv() + } + + isShadowrocket() { + return 'Shadowrocket' === this.getEnv() + } + + isStash() { + return 'Stash' === this.getEnv() } toObj(str, defaultValue = null) { @@ -65,9 +108,9 @@ function Env(name, opts) { } } - toStr(obj, defaultValue = null) { + toStr(obj, defaultValue = null, ...args) { try { - return JSON.stringify(obj) + return JSON.stringify(obj, ...args) } catch { return defaultValue } @@ -102,14 +145,26 @@ function Env(name, opts) { return new Promise((resolve) => { let httpapi = this.getdata('@chavy_boxjs_userCfgs.httpapi') httpapi = httpapi ? httpapi.replace(/\n/g, '').trim() : httpapi - let httpapi_timeout = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout') + let httpapi_timeout = this.getdata( + '@chavy_boxjs_userCfgs.httpapi_timeout' + ) httpapi_timeout = httpapi_timeout ? httpapi_timeout * 1 : 20 - httpapi_timeout = runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout + httpapi_timeout = + runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout const [key, addr] = httpapi.split('@') const opts = { url: `http://${addr}/v1/scripting/evaluate`, - body: { script_text: script, mock_type: 'cron', timeout: httpapi_timeout }, - headers: { 'X-Key': key, 'Accept': '*/*' } + body: { + script_text: script, + mock_type: 'cron', + timeout: httpapi_timeout + }, + headers: { + 'X-Key': key, + 'Accept': '*/*' + }, + policy: 'DIRECT', + timeout: httpapi_timeout } this.post(opts, (err, resp, body) => resolve(body)) }).catch((e) => this.logErr(e)) @@ -120,11 +175,17 @@ function Env(name, opts) { this.fs = this.fs ? this.fs : require('fs') this.path = this.path ? this.path : require('path') const curDirDataFilePath = this.path.resolve(this.dataFile) - const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) + const rootDirDataFilePath = this.path.resolve( + process.cwd(), + this.dataFile + ) const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) - const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) + const isRootDirDataFile = + !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) if (isCurDirDataFile || isRootDirDataFile) { - const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath + const datPath = isCurDirDataFile + ? curDirDataFilePath + : rootDirDataFilePath try { return JSON.parse(this.fs.readFileSync(datPath)) } catch (e) { @@ -139,9 +200,13 @@ function Env(name, opts) { this.fs = this.fs ? this.fs : require('fs') this.path = this.path ? this.path : require('path') const curDirDataFilePath = this.path.resolve(this.dataFile) - const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) + const rootDirDataFilePath = this.path.resolve( + process.cwd(), + this.dataFile + ) const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) - const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) + const isRootDirDataFile = + !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) const jsondata = JSON.stringify(this.data) if (isCurDirDataFile) { this.fs.writeFileSync(curDirDataFilePath, jsondata) @@ -170,9 +235,13 @@ function Env(name, opts) { if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || [] path .slice(0, -1) - .reduce((a, c, i) => (Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {})), obj)[ - path[path.length - 1] - ] = value + .reduce( + (a, c, i) => + Object(a[c]) === a[c] + ? a[c] + : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {}), + obj + )[path[path.length - 1]] = value return obj } @@ -199,7 +268,11 @@ function Env(name, opts) { if (/^@/.test(key)) { const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key) const objdat = this.getval(objkey) - const objval = objkey ? (objdat === 'null' ? null : objdat || '{}') : '{}' + const objval = objkey + ? objdat === 'null' + ? null + : objdat || '{}' + : '{}' try { const objedval = JSON.parse(objval) this.lodash_set(objedval, paths, val) @@ -216,30 +289,38 @@ function Env(name, opts) { } getval(key) { - if (this.isSurge() || this.isLoon()) { - return $persistentStore.read(key) - } else if (this.isQuanX()) { - return $prefs.valueForKey(key) - } else if (this.isNode()) { - this.data = this.loaddata() - return this.data[key] - } else { - return (this.data && this.data[key]) || null + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.read(key) + case 'Quantumult X': + return $prefs.valueForKey(key) + case 'Node.js': + this.data = this.loaddata() + return this.data[key] + default: + return (this.data && this.data[key]) || null } } setval(val, key) { - if (this.isSurge() || this.isLoon()) { - return $persistentStore.write(val, key) - } else if (this.isQuanX()) { - return $prefs.setValueForKey(val, key) - } else if (this.isNode()) { - this.data = this.loaddata() - this.data[key] = val - this.writedata() - return true - } else { - return (this.data && this.data[key]) || null + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.write(val, key) + case 'Quantumult X': + return $prefs.setValueForKey(val, key) + case 'Node.js': + this.data = this.loaddata() + this.data[key] = val + this.writedata() + return true + default: + return (this.data && this.data[key]) || null } } @@ -249,89 +330,232 @@ function Env(name, opts) { this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar() if (opts) { opts.headers = opts.headers ? opts.headers : {} - if (undefined === opts.headers.Cookie && undefined === opts.cookieJar) { - opts.cookieJar = this.ckjar + if (opts) { + opts.headers = opts.headers ? opts.headers : {} + if ( + undefined === opts.headers.cookie && + undefined === opts.headers.Cookie && + undefined === opts.cookieJar + ) { + opts.cookieJar = this.ckjar + } } } } - get(opts, callback = () => {}) { - if (opts.headers) { - delete opts.headers['Content-Type'] - delete opts.headers['Content-Length'] + get(request, callback = () => {}) { + if (request.headers) { + delete request.headers['Content-Type'] + delete request.headers['Content-Length'] + + // HTTP/2 全是小写 + delete request.headers['content-type'] + delete request.headers['content-length'] } - if (this.isSurge() || this.isLoon()) { - $httpClient.get(opts, (err, resp, body) => { - if (!err && resp) { - resp.body = body - resp.statusCode = resp.status + if (request.params) { + request.url += '?' + this.queryStr(request.params) + } + // followRedirect 禁止重定向 + if ( + typeof request.followRedirect !== 'undefined' && + !request['followRedirect'] + ) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) + request.opts + ? (request['opts']['redirection'] = false) + : (request.opts = { redirection: false }) // Quantumult X + } + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + if (this.isSurge() && this.isNeedRewrite) { + request.headers = request.headers || {} + Object.assign(request.headers, { 'X-Surge-Skip-Scripting': false }) } - callback(err, resp, body) - }) - } else if (this.isQuanX()) { - $task.fetch(opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) - }, - (err) => callback(err) - ) - } else if (this.isNode()) { - this.initGotEnv(opts) - this.got(opts) - .on('redirect', (resp, nextOpts) => { - try { - const ck = resp.headers['set-cookie'].map(this.cktough.Cookie.parse).toString() - this.ckjar.setCookieSync(ck, null) - nextOpts.cookieJar = this.ckjar - } catch (e) { - this.logErr(e) + $httpClient.get(request, (err, resp, body) => { + if (!err && resp) { + resp.body = body + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode } - // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) + callback(err, resp, body) }) - .then( + break + case 'Quantumult X': + if (this.isNeedRewrite) { + request.opts = request.opts || {} + Object.assign(request.opts, { hints: false }) + } + $task.fetch(request).then( (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) + const { + statusCode: status, + statusCode, + headers, + body, + bodyBytes + } = resp + callback( + null, + { status, statusCode, headers, body, bodyBytes }, + body, + bodyBytes + ) }, - (err) => callback(err) + (err) => callback((err && err.error) || 'UndefinedError') ) + break + case 'Node.js': + let iconv = require('iconv-lite') + this.initGotEnv(request) + this.got(request) + .on('redirect', (resp, nextOpts) => { + try { + if (resp.headers['set-cookie']) { + const ck = resp.headers['set-cookie'] + .map(this.cktough.Cookie.parse) + .toString() + if (ck) { + this.ckjar.setCookieSync(ck, null) + } + nextOpts.cookieJar = this.ckjar + } + } catch (e) { + this.logErr(e) + } + // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) + }) + .then( + (resp) => { + const { + statusCode: status, + statusCode, + headers, + rawBody + } = resp + const body = iconv.decode(rawBody, this.encoding) + callback( + null, + { status, statusCode, headers, rawBody, body }, + body + ) + }, + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } + ) + break } } - post(opts, callback = () => {}) { - // 如果指定了请求体, 但没指定`Content-Type`, 则自动生成 - if (opts.body && opts.headers && !opts.headers['Content-Type']) { - opts.headers['Content-Type'] = 'application/x-www-form-urlencoded' + post(request, callback = () => {}) { + const method = request.method + ? request.method.toLocaleLowerCase() + : 'post' + + // 如果指定了请求体, 但没指定 `Content-Type`、`content-type`, 则自动生成。 + if ( + request.body && + request.headers && + !request.headers['Content-Type'] && + !request.headers['content-type'] + ) { + // HTTP/1、HTTP/2 都支持小写 headers + request.headers['content-type'] = 'application/x-www-form-urlencoded' + } + // 为避免指定错误 `content-length` 这里删除该属性,由工具端 (HttpClient) 负责重新计算并赋值 + if (request.headers) { + delete request.headers['Content-Length'] + delete request.headers['content-length'] + } + // followRedirect 禁止重定向 + if ( + typeof request.followRedirect !== 'undefined' && + !request['followRedirect'] + ) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) + request.opts + ? (request['opts']['redirection'] = false) + : (request.opts = { redirection: false }) // Quantumult X } - if (opts.headers) delete opts.headers['Content-Length'] - if (this.isSurge() || this.isLoon()) { - $httpClient.post(opts, (err, resp, body) => { - if (!err && resp) { - resp.body = body - resp.statusCode = resp.status + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + if (this.isSurge() && this.isNeedRewrite) { + request.headers = request.headers || {} + Object.assign(request.headers, { 'X-Surge-Skip-Scripting': false }) } - callback(err, resp, body) - }) - } else if (this.isQuanX()) { - opts.method = 'POST' - $task.fetch(opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) - }, - (err) => callback(err) - ) - } else if (this.isNode()) { - this.initGotEnv(opts) - const { url, ..._opts } = opts - this.got.post(url, _opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) - }, - (err) => callback(err) - ) + $httpClient[method](request, (err, resp, body) => { + if (!err && resp) { + resp.body = body + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode + } + callback(err, resp, body) + }) + break + case 'Quantumult X': + request.method = method + if (this.isNeedRewrite) { + request.opts = request.opts || {} + Object.assign(request.opts, { hints: false }) + } + $task.fetch(request).then( + (resp) => { + const { + statusCode: status, + statusCode, + headers, + body, + bodyBytes + } = resp + callback( + null, + { status, statusCode, headers, body, bodyBytes }, + body, + bodyBytes + ) + }, + (err) => callback((err && err.error) || 'UndefinedError') + ) + break + case 'Node.js': + let iconv = require('iconv-lite') + this.initGotEnv(request) + const { url, ..._request } = request + this.got[method](url, _request).then( + (resp) => { + const { statusCode: status, statusCode, headers, rawBody } = resp + const body = iconv.decode(rawBody, this.encoding) + callback( + null, + { status, statusCode, headers, rawBody, body }, + body + ) + }, + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } + ) + break } } /** @@ -340,26 +564,59 @@ function Env(name, opts) { * :$.time('yyyyMMddHHmmssS') * y:年 M:月 d:日 q:季 H:时 m:分 s:秒 S:毫秒 * 其中y可选0-4位占位符、S可选0-1位占位符,其余可选0-2位占位符 - * @param {*} fmt 格式化参数 + * @param {string} fmt 格式化参数 + * @param {number} 可选: 根据指定时间戳返回格式化日期 * */ - time(fmt) { + time(fmt, ts = null) { + const date = ts ? new Date(ts) : new Date() let o = { - 'M+': new Date().getMonth() + 1, - 'd+': new Date().getDate(), - 'H+': new Date().getHours(), - 'm+': new Date().getMinutes(), - 's+': new Date().getSeconds(), - 'q+': Math.floor((new Date().getMonth() + 3) / 3), - 'S': new Date().getMilliseconds() - } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (new Date().getFullYear() + '').substr(4 - RegExp.$1.length)) + 'M+': date.getMonth() + 1, + 'd+': date.getDate(), + 'H+': date.getHours(), + 'm+': date.getMinutes(), + 's+': date.getSeconds(), + 'q+': Math.floor((date.getMonth() + 3) / 3), + 'S': date.getMilliseconds() + } + if (/(y+)/.test(fmt)) + fmt = fmt.replace( + RegExp.$1, + (date.getFullYear() + '').substr(4 - RegExp.$1.length) + ) for (let k in o) if (new RegExp('(' + k + ')').test(fmt)) - fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) + fmt = fmt.replace( + RegExp.$1, + RegExp.$1.length == 1 + ? o[k] + : ('00' + o[k]).substr(('' + o[k]).length) + ) return fmt } + /** + * + * @param {Object} options + * @returns {String} 将 Object 对象 转换成 queryStr: key=val&name=senku + */ + queryStr(options) { + let queryString = '' + + for (const key in options) { + let value = options[key] + if (value != null && value !== '') { + if (typeof value === 'object') { + value = JSON.stringify(value) + } + queryString += `${key}=${value}&` + } + } + queryString = queryString.substring(0, queryString.length - 1) + + return queryString + } + /** * 系统通知 * @@ -376,49 +633,237 @@ function Env(name, opts) { * @param {*} opts 通知参数 * */ - msg(title = name, subt = '', desc = '', opts) { + msg(title = name, subt = '', desc = '', opts = {}) { const toEnvOpts = (rawopts) => { - if (!rawopts || (!this.isLoon() && this.isSurge())) return rawopts - if (typeof rawopts === 'string') { - if (this.isLoon()) return rawopts - else if (this.isQuanX()) return { 'open-url': rawopts } - else return undefined - } else if (typeof rawopts === 'object' && (rawopts['open-url'] || rawopts['media-url'])) { - if (this.isLoon()) return rawopts['open-url'] - else if (this.isQuanX()) return rawopts - else undefined - } else { - return undefined + const { $open, $copy, $media, $mediaMime } = rawopts + switch (typeof rawopts) { + case undefined: + return rawopts + case 'string': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + default: + return { url: rawopts } + case 'Loon': + case 'Shadowrocket': + return rawopts + case 'Quantumult X': + return { 'open-url': rawopts } + case 'Node.js': + return undefined + } + case 'object': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + case 'Shadowrocket': + default: { + const options = {} + + // 打开URL + let openUrl = + rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open + if (openUrl) + Object.assign(options, { action: 'open-url', url: openUrl }) + + // 粘贴板 + let copy = + rawopts['update-pasteboard'] || + rawopts.updatePasteboard || + $copy + if (copy) { + Object.assign(options, { action: 'clipboard', text: copy }) + } + + // 图片通知 + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media + if (mediaUrl) { + let media = undefined + let mime = undefined + // http 开头的网络地址 + if (mediaUrl.startsWith('http')) { + //不做任何操作 + } + // 带标识的 Base64 字符串 + // data:image/png;base64,iVBORw0KGgo... + else if (mediaUrl.startsWith('data:')) { + const [data] = mediaUrl.split(';') + const [, base64str] = mediaUrl.split(',') + media = base64str + mime = data.replace('data:', '') + } + // 没有标识的 Base64 字符串 + // iVBORw0KGgo... + else { + // https://stackoverflow.com/questions/57976898/how-to-get-mime-type-from-base-64-string + const getMimeFromBase64 = (encoded) => { + const signatures = { + 'JVBERi0': 'application/pdf', + 'R0lGODdh': 'image/gif', + 'R0lGODlh': 'image/gif', + 'iVBORw0KGgo': 'image/png', + '/9j/': 'image/jpg' + } + for (var s in signatures) { + if (encoded.indexOf(s) === 0) { + return signatures[s] + } + } + return null + } + media = mediaUrl + mime = getMimeFromBase64(mediaUrl) + } + + Object.assign(options, { + 'media-url': mediaUrl, + 'media-base64': media, + 'media-base64-mime': $mediaMime ?? mime + }) + } + + Object.assign(options, { + 'auto-dismiss': rawopts['auto-dismiss'], + 'sound': rawopts['sound'] + }) + return options + } + case 'Loon': { + const options = {} + + let openUrl = + rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open + if (openUrl) Object.assign(options, { openUrl }) + + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media + if (mediaUrl) Object.assign(options, { mediaUrl }) + + console.log(JSON.stringify(options)) + return options + } + case 'Quantumult X': { + const options = {} + + let openUrl = + rawopts['open-url'] || rawopts.url || rawopts.openUrl || $open + if (openUrl) Object.assign(options, { 'open-url': openUrl }) + + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media + if (mediaUrl) Object.assign(options, { 'media-url': mediaUrl }) + + let copy = + rawopts['update-pasteboard'] || + rawopts.updatePasteboard || + $copy + if (copy) Object.assign(options, { 'update-pasteboard': copy }) + + console.log(JSON.stringify(options)) + return options + } + case 'Node.js': + return undefined + } + default: + return undefined } } if (!this.isMute) { - if (this.isSurge() || this.isLoon()) { - $notification.post(title, subt, desc, toEnvOpts(opts)) - } else if (this.isQuanX()) { - $notify(title, subt, desc, toEnvOpts(opts)) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + $notification.post(title, subt, desc, toEnvOpts(opts)) + break + case 'Quantumult X': + $notify(title, subt, desc, toEnvOpts(opts)) + break + case 'Node.js': + break + } + } + if (!this.isMuteLog) { + let logs = ['', '==============📣系统通知📣=============='] + logs.push(title) + subt ? logs.push(subt) : '' + desc ? logs.push(desc) : '' + console.log(logs.join('\n')) + this.logs = this.logs.concat(logs) + } + } + + debug(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.debug) { + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.debug}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` + ) + } + } + + info(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.info) { + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.info}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` + ) + } + } + + warn(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.warn) { + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.warn}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` + ) + } + } + + error(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.error) { + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] } + console.log( + `${this.logLevelPrefixs.error}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` + ) } - let logs = ['', '==============📣系统通知📣=============='] - logs.push(title) - subt ? logs.push(subt) : '' - desc ? logs.push(desc) : '' - console.log(logs.join('\n')) - this.logs = this.logs.concat(logs) } log(...logs) { if (logs.length > 0) { this.logs = [...this.logs, ...logs] } - console.log(logs.join(this.logSeparator)) + console.log(logs.map((l) => l ?? String(l)).join(this.logSeparator)) } logErr(err, msg) { - const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon() - if (!isPrintSack) { - this.log('', `❗️${this.name}, 错误!`, err) - } else { - this.log('', `❗️${this.name}, 错误!`, err.stack) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + this.log('', `❗️${this.name}, 错误!`, msg, err) + break + case 'Node.js': + this.log( + '', + `❗️${this.name}, 错误!`, + msg, + typeof err.message !== 'undefined' ? err.message : err, + err.stack + ) + break } } @@ -431,8 +876,17 @@ function Env(name, opts) { const costTime = (endTime - this.startTime) / 1000 this.log('', `🔔${this.name}, 结束! 🕛 ${costTime} 秒`) this.log() - if (this.isSurge() || this.isQuanX() || this.isLoon()) { - $done(val) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + $done(val) + break + case 'Node.js': + process.exit(1) } } })(name, opts) diff --git a/Env.min.js b/Env.min.js index f32835a61..0d0bc12f4 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,o)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=s&&s.timeout?s.timeout:o;const[h,a]=i.split("@"),r={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":h,Accept:"*/*"}};this.post(r,(t,s,i)=>e(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=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),o=JSON.stringify(this.data);e?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(s,o):this.fs.writeFileSync(t,o)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return e;return o}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),o=e?this.getval(e):"";if(o)try{const t=JSON.parse(o);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(s),h=this.getval(i),a=i?"null"===h?null:h||"{}":"{}";try{const s=JSON.parse(a);this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i)}catch(s){const h={};this.lodash_set(h,o,t),e=this.setval(JSON.stringify(h),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||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,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status),s(t,e,i)}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)))}post(t,s=(()=>{})){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())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status),s(t,e,i)});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t))}}time(t){let s={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in s)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?s[e]:("00"+s[e]).substr((""+s[e]).length)));return t}msg(s=t,e="",i="",o){const h=t=>!t||!this.isLoon()&&this.isSurge()?t:"string"==typeof t?this.isLoon()?t:this.isQuanX()?{"open-url":t}:void 0:"object"==typeof t&&(t["open-url"]||t["media-url"])?this.isLoon()?t["open-url"]:this.isQuanX()?t:void 0:void 0;this.isMute||(this.isSurge()||this.isLoon()?$notification.post(s,e,i,h(o)):this.isQuanX()&&$notify(s,e,i,h(o)));let a=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];a.push(s),e&&a.push(e),i&&a.push(i),console.log(a.join("\n")),this.logs=this.logs.concat(a)}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)} \ No newline at end of file +function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;"POST"===t&&(s=this.post);const i=new Promise(((t,i)=>{s.call(this,e,((e,s,o)=>{e?i(e):t(s)}))}));return e.timeout?((e,t=1e3)=>Promise.race([e,new Promise(((e,s)=>{setTimeout((()=>{s(new Error("请求超时"))}),t)}))]))(i,e.timeout):i}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(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,t),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(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;if(this.getdata(e))try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise((t=>{this.get({url:e},((e,s,i)=>t(i)))}))}runScript(e,t){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=t&&t.timeout?t.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},policy:"DIRECT",timeout:o};this.post(n,((e,t,i)=>s(i)))})).catch((e=>this.logErr(e)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t);if(!s&&!i)return{};{const i=s?e:t;try{return JSON.parse(this.fs.readFileSync(i))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t),o=JSON.stringify(this.data);s?this.fs.writeFileSync(e,o):i?this.fs.writeFileSync(t,o):this.fs.writeFileSync(e,o)}}lodash_get(e,t,s){const i=t.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(const e of i)if(o=Object(o)[e],void 0===o)return s;return o}lodash_set(e,t,s){return Object(e)!==e||(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce(((e,s,i)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[i+1])>>0==+t[i+1]?[]:{}),e)[t[t.length-1]]=s),e}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(e),o=s?this.getval(s):"";if(o)try{const e=JSON.parse(o);t=e?this.lodash_get(e,i,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,o,e),s=this.setval(JSON.stringify(t),i)}catch(t){const r={};this.lodash_set(r,o,e),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){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,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",((e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}})).then((e=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:i,response:o}=e;t(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(e);const{url:o,...r}=e;this.got[s](o,r).then((e=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=e,n=i.decode(a,this.encoding);t(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:s,response:o}=e;t(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(e,t=null){const s=t?new Date(t):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),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in i)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?i[t]:("00"+i[t]).substr((""+i[t]).length)));return e}queryStr(e){let t="";for(const s in e){let i=e[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),t+=`${s}=${i}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",i="",o={}){const r=e=>{const{$open:t,$copy:s,$media:i,$mediaMime:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=e.openUrl||e.url||e["open-url"]||t;a&&Object.assign(r,{action:"open-url",url:a});let n=e["update-pasteboard"]||e.updatePasteboard||s;n&&Object.assign(r,{action:"clipboard",text:n});let h=e.mediaUrl||e["media-url"]||i;if(h){let e,t;if(h.startsWith("http"));else if(h.startsWith("data:")){const[s]=h.split(";"),[,i]=h.split(",");e=i,t=s.replace("data:","")}else{e=h,t=(e=>{const t={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in t)if(0===e.indexOf(s))return t[s];return null})(h)}Object.assign(r,{"media-url":h,"media-base64":e,"media-base64-mime":o??t})}return Object.assign(r,{"auto-dismiss":e["auto-dismiss"],sound:e.sound}),r}case"Loon":{const s={};let o=e.openUrl||e.url||e["open-url"]||t;o&&Object.assign(s,{openUrl:o});let r=e.mediaUrl||e["media-url"]||i;return r&&Object.assign(s,{mediaUrl:r}),console.log(JSON.stringify(s)),s}case"Quantumult X":{const o={};let r=e["open-url"]||e.url||e.openUrl||t;r&&Object.assign(o,{"open-url":r});let a=e.mediaUrl||e["media-url"]||i;a&&Object.assign(o,{"media-url":a});let n=e["update-pasteboard"]||e.updatePasteboard||s;return n&&Object.assign(o,{"update-pasteboard":n}),console.log(JSON.stringify(o)),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,i,r(o));break;case"Quantumult X":$notify(t,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let e=["","==============📣系统通知📣=============="];e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.map((e=>e??String(e))).join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t,e);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t,void 0!==e.message?e.message:e,e.stack);break}}wait(e){return new Promise((t=>setTimeout(t,e)))}done(e={}){const t=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${t} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file diff --git a/Loon.cookie.conf b/Loon.cookie.conf new file mode 100644 index 000000000..db5ef4628 --- /dev/null +++ b/Loon.cookie.conf @@ -0,0 +1,66 @@ +# Chavyleung +http-request ^https?:\/\/tieba\.baidu\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js, tag=百度签到(网页) +http-request ^https:\/\/music.163.com\/weapi\/user\/level script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.cookie.js, requires-body=true, tag=网易云音乐 +http-request ^https:\/\/www\.smzdm\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/smzdm/smzdm.cookie.js, tag=什么值得买 +http-request ^https:\/\/www\.v2ex\.com\/mission\/daily script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.cookie.js, tag=V2ex +http-request ^https:\/\/(www|live)\.bilibili\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js, tag=哔哩哔哩 +http-request ^https:\/\/(www\.)?feng\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js, tag=威锋论坛 +http-request ^https:\/\/access.video.qq.com\/user\/auth_refresh script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.cookie.js, tag=腾讯视频 +http-request ^https:\/\/api\-new\.app\.acfun\.cn\/rest\/app\/user\/personalInfo script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.cookie.js, tag=AcFun +http-request ^https?:\/\/(www\.)?rrys2020\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js, tag=字幕组 +http-request ^http:\/\/ios.zmzapi.com\/index.php.*a=(mobile_)?login script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js, tag=字幕组 +http-request ^https?:\/\/.*\/mobile\-user\/(v1\/)?homePage\/.* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.cookie.js,tag=喜马拉雅 +http-request ^https:\/\/api\.rr\.tv\/user\/profile script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/rrtv/rrtv.cookie.js, tag=人人视频 +http-request ^https:\/\/www\.flyertea\.com\/source\/plugin\/mobile\/mobile\.php\?module=getdata&.* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/flyertea/flyertea.cookie.js, tag=飞客茶馆 +http-request ^https:\/\/sf-integral-sign-in.weixinjia.net\/app\/index script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js, tag=顺丰速运 +http-request ^https:\/\/mcs-mimp-web.sf-express.com\/mcs-mimp\/share\/(.*?)Redirect script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js, tag=顺丰速运 +http-request ^https:\/\/wapside.189.cn:9001\/api\/home\/homeInfo script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.cookie.js, requires-body=true, tag=中国电信 +http-request ^https:\/\/api\.dongqiudi\.com\/v2\/user\/is_login script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/dongqiudi/dongqiudi.cookie.js, tag=懂球帝 +http-request ^https:\/\/m\.you\.163\.com\/xhr\/points\/index\.json script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/yanxuan/yanxuan.cookie.js, tag=网易严选 +http-request ^https:\/\/apk\.tw\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js, tag=APK.TW +http-request ^https:\/\/user.qunar.com\/webapi\/member\/signIndexV2.htm script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qunar/qunar.cookie.js, tag=去哪儿 +http-request ^https:\/\/passport.csdn.net\/v2\/api\/app\/login\/checkAndRefreshToken script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.cookie.js, tag=CSDN +http-request ^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.cookie.js, tag=CSDN +http-request ^https:\/\/credits.bz.mgtv.com\/user\/creditsTake script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.cookie.js, tag=芒果tv +http-request ^https:\/\/m.gdoil.cn\/webapi\/usersign\/addusersign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/gdoil/gdoil.cookie.js, tag=加油广东 +http-request https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.cookie.js, tag=猫咪音乐 +# http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 +# http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 +http-request ^https?:\/\/act.10010.com\/SigninApp\/signin\/querySigninActivity.htm script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 +http-request ^https?:\/\/act.10010.com\/SigninApp(.*?)\/signin\/daySign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 +http-request ^https?:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 +http-request ^https:\/\/promotion.waimai.meituan.com\/playcenter\/signIn\/entry script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.cookie.js, tag=美团外卖 +http-request ^https:\/\/promotion.waimai.meituan.com\/playcenter\/signIn\/doaction script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.cookie.js, requires-body=true, tag=美团外卖 +http-request ^https:\/\/(.*?)c\.m\.163\.com\/uc\/api\/sign\/v3\/commit script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasenews/neteasenews.cookie.js, requires-body=true, tag=网易新闻 +http-request ^https:\/\/i.meituan.com\/evolve\/signin\/signpost\/ script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/meituan/meituan.cookie.js, requires-body=true, tag=美团 +http-request ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.cookie.js, tag=时光相册 +# http-request ^https://group\.baicizhan\.com/group/rewards? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js, tag=百词斩 +http-request ^https:\/\/maicai.api.ddxq.mobi\/point\/home script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.cookie.js, tag=叮咚买菜 +http-request ^https://api\.dushu\.io/CheckIn script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js, requires-body=true, tag=樊登读书 +http-request ^https://node\.kg\.qq\.com/webapp/proxy? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.cookie.js, requires-body=true, tag=全民K歌 +http-request ^https:\/\/app\.nio\.com\/api\/1\/app\/daily_checkin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/nio/nio.cookie.js, tag=蔚来 +http-request ^https:\/\/wxprdapplet\.gac-nio\.com\/community\/userSignIn\/simpleAuth\/front\/.*\/sign$ script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hycan/hycan.cookie.js, tag=合创 +http-request ^https:\/\/activity-1\.m\.duiba\.com\.cn\/signactivity\/doSign$ requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/haidilao/hdl.js, tag=海底捞 +http-request ^https:\/\/m-bean\.kaola\.com/m/point/sign\.html script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wykl/wykl.cookie.js, requires-body=true, tag=网易考拉 +http-request ^https:\/\/zt.wps.cn\/2018\/docer_check_in\/api\/act_list script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.cookie.js, tag=WPS +http-request ^https:\/\/xiaoshuo\.qm989\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qimao/qmnovel.js, tag=七猫小说 +http-request ^https:\/\/passport.suning.com\/ids\/login$ script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js, requires-body=true, tag=苏宁易购 +http-request ^https:\/\/luckman.suning.com\/luck-web\/sign\/api\/clock_sign.do script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js, tag=苏宁易购 +http-request ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js, tag=苏宁易购 +http-request ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js, tag=苏宁易购 +http-request ^https:\/\/iphone\.myzaker\.com\/zaker\/sign_in\/\/api\/sign_in\.php script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zaker/zaker.js, tag=Zaker +http-request ^https:\/\/sapi\.beingfine\.cn\/v3\/bb\/reward\/by-sign-in script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js, tag=不背单词 +http-request ^https:\/\/gameapi\.hellobike\.com\/api script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hellobike/hellobike.js, requires-body=true, tag=哈啰出行 +http-request ^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 +http-request ^https:\/\/apiwz\.midukanshu\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/midu/midu.cookie.js, requires-body=true, tag=米读 +http-request ^https:\/\/www\.duokan\.com\/checkin\/v0\/status script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/duokan/duokan.cookie.js, requires-body=true, tag=多看 +http-request ^https:\/\/note.youdao.com\/yws\/mapi\/user\?method=checkin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/noteyoudao/noteyoudao.cookie.js, requires-body=true, tag=有道云笔记 +http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, tag=中国移动-查话费 +http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, tag=中国移动-查话费 +http-request ^https:\/\/user-api-prd-mx\.wandafilm\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.cookie.js, tag=万达电影 +http-request ^https:\/\/wx-mini.pagoda.com.cn\/api\/v1\/wxmini\/signIn\/customer script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/pagoda/pagoda.cookie.js, tag=百果园 +http-response ^https:\/\/my\.ruanmei\.com\/api\/usersign\/getsigninfo? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ithome/ithome.cookie.js, tag=IT之家 +http-response ^http:\/\/api\.infzm\.com\/mobile\/pumpkin_task\/complete? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/nfzm/nfzm.cookie.js ,tag=南方周末 +http-request ^https:\/\/m\.ctrip\.com/restapi/soa2/14593/json/attendanceDay? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zxhc/zxhc.cookie.js, tag=智行火车票 + +hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, m-bean.kaola.com, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, node.kg.qq.com, api.dushu.io, pm.m.fenqile.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, i.meituan.com, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, m.gdoil.cn, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, 113.96.156.178, *.ximalaya.com, *.you.163.com, *.rrys2020.com, ios.zmzapi.com diff --git a/Loon.task.conf b/Loon.task.conf new file mode 100644 index 000000000..8fad48658 --- /dev/null +++ b/Loon.task.conf @@ -0,0 +1,57 @@ +# By chavyleung GitHub:https://github.com/chavyleung/scripts +cron "5 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/jd/JD_BaiTiao.js, tag=京东白条 +cron "10 0 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js,tag=百度签到(网页) +cron "50 0 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.js,tag=电信营业厅 +cron "0 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.js,tag=AcFun +cron "10 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.js,tag=APK.TW +cron "20 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js,tag=哔哩哔哩 +cron "30 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js,tag=哔哩哔哩 +cron "40 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/dongqiudi/dongqiudi.js,tag=懂球帝 +cron "50 1 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js,tag=威锋网 +cron "0 2 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/flyertea/flyertea.js,tag=飞客茶馆 +cron "10 2 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js,tag=网易云音乐 +cron "30 2 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasenews/neteasenews.js,tag=网易新闻 +cron "40 2 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qunar/qunar.js,tag=去哪儿 +cron "50 2 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/rrtv/rrtv.js,tag=人人视频 +cron "0 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js,tag= 顺丰速运 +cron "10 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/smzdm/smzdm.js,tag=什么值得买 +cron "20 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js,tag=V2EX +cron "30 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.js,tag=腾讯视频 +cron "40 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.js,tag=喜马拉雅 +cron "50 3 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/yanxuan/yanxuan.js,tag=网易严选 +cron "0 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.js,tag=字幕组 +cron "10 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qqmusic/qqmusic.js,tag=QQ音乐 +cron "20 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.js,tag=CSDN +cron "30 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/gdoil/gdoil.js,tag=加油广东 +cron "40 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.js,tag=芒果TV +cron "50 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.js,tag=米游社 +cron "0 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.js,tag=中国联通 +cron "10 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.js,tag=猫咪音乐 +# cron "20 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js,tag=中国移动 +cron "30 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.js,tag= 美团外卖 +cron "40 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/meituan/meituan.js,tag=美团 +cron "50 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js,tag=时光相册 +# cron "0 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js,tag=百词斩 +cron "10 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.js,tag=叮咚买菜 +cron "30 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js,tag=樊登读书 +cron "40 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.js,tag=全民K歌 +cron "50 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hycan/hycan.js,tag=合创 +cron "0 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/nio/nio.js,tag=蔚来 +cron "10 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/haidilao/hdl.js,tag=海底捞 +cron "20 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wykl/wykl.js,tag=网易考拉 +cron "30 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.js,tag=WPS +cron "40 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qimao/qmnovel.js,tag=七猫小说 +cron "50 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zxhc/zxhc.js,tag=智行火车 +cron "0 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js,tag=苏宁易购 +cron "10 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zaker/zaker.js,tag=Zaker +cron "20 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js,tag=不背单词 +cron "40 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hellobike/hellobike.js,tag=哈啰出行 +cron "50 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js,tag=掌上飞车 +cron "0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/duokan/duokan.js,tag=多看 +cron "3 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/noteyoudao/noteyoudao.js, tag=有道云笔记 +cron "0 12 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/switcher/box.switcher.js, tag=切换会话 +# cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=中国移动-查话费 +cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.js, tag=万达电影 +cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/pagoda/pagoda.js, tag=百果园 +cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ithome/ithome.js, tag=IT之家 +cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/nfzm/nfzm.js, tag=南方周末 \ No newline at end of file diff --git a/QuantumultX.box.local.conf b/QuantumultX.box.local.conf deleted file mode 100644 index d0f20f667..000000000 --- a/QuantumultX.box.local.conf +++ /dev/null @@ -1,10 +0,0 @@ -hostname = 8.8.8.8, 1.1.1.1 - -^https://8.8.8.8/api url script-request-body chavyleung/chavy.box.js -^https://8.8.8.8/(home|sub|my|app|log|revert)($|\/) url script-echo-response chavy.box.js - -^https?://1.1.1.1/api url script-request-body chavy.box.js -^https?://1.1.1.1/(home|sub|my|app|log|revert)($|\/) url script-echo-response chavy.box.js - -^https?://boxjs.com/api url script-request-body chavy.box.js -^https?://boxjs.com(/home|/sub|/my|/app|/log|/revert)?($|\/) url script-echo-response chavy.box.js \ No newline at end of file diff --git a/QuantumultX.box.remote.conf b/QuantumultX.box.remote.conf deleted file mode 100644 index 5e625e160..000000000 --- a/QuantumultX.box.remote.conf +++ /dev/null @@ -1,10 +0,0 @@ -hostname = 8.8.8.8, 1.1.1.1 - -^https://8.8.8.8/api url script-request-body https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js -^https://8.8.8.8/(home|sub|my|app|log|revert)($|\/) url script-echo-response https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js - -^https?://1.1.1.1/api url script-request-body https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js -^https?://1.1.1.1/(home|sub|my|app|log|revert)($|\/) url script-echo-response https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js - -^https?://boxjs.com/api url script-request-body https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js -^https?://boxjs.com(/home|/sub|/my|/app|/log|/revert)?($|\/) url script-echo-response https://gitee.com/chavyleung/scripts/raw/master/chavy.box.js \ No newline at end of file diff --git a/QuantumultX_AppStore_Local_Cookie.conf b/QuantumultX_AppStore_Local_Cookie.conf index a3d236b62..e45108b50 100644 --- a/QuantumultX_AppStore_Local_Cookie.conf +++ b/QuantumultX_AppStore_Local_Cookie.conf @@ -1,7 +1,7 @@ # 本配置适用于: QuanX 商店版 v1.0.6-build194 及之前版本 # 如果你是TF版, 请使用: QuantumultX_Local_Cookie.conf -hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, gdws.nsenz.com, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, mobwsa.ximalaya.com, *.you.163.com, *.rrys2019.com, ios.zmzapi.com +hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, gdws.nsenz.com, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, 113.96.156.178, *.ximalaya.com, *.you.163.com, *.rrys2020.com, ios.zmzapi.com # 电信营业厅 ^https:\/\/wapside.189.cn:9001\/api\/home\/sign url script-request-body chavyleung/10000/10000.cookie.js @@ -57,13 +57,13 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/access.video.qq.com\/user\/auth_refresh url script-request-header chavyleung/videoqq/videoqq.cookie.js # 喜马拉雅 -^https?:\/\/.*\/mobile\-user\/homePage\/.* url script-request-header chavyleung/ximalaya/ximalaya.cookie.js +^https?:\/\/.*\/mobile\-user\/(v1\/)?homePage\/.* url script-request-header chavyleung/ximalaya/ximalaya.cookie.js # 网易严选 # ^https:\/\/m\.you\.163\.com\/xhr\/points\/index\.json url script-request-header chavyleung/yanxuan/yanxuan.cookie.js # 字幕组 -^https?:\/\/(www\.)?rrys2019\.com\/?.? url script-request-header chavyleung/zimuzu/zimuzu.cookie.js +^https?:\/\/(www\.)?rrys2020\.com\/?.? url script-request-header chavyleung/zimuzu/zimuzu.cookie.js ^http:\/\/ios.zmzapi.com\/index.php.*a=(mobile_)?login url script-request-header chavyleung/zimuzu/zimuzu.cookie.js # 加油广东 @@ -82,8 +82,8 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) url script-request-header chavyleung/10010/10010.cookie.js # 中国移动 -^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header chavyleung/10086/10086.cookie.js -^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header chavyleung/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header chavyleung/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header chavyleung/10086/10086.cookie.js # 猫咪音乐网 https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url script-request-header chavyleung/maomicd/maomicd.cookie.js @@ -96,7 +96,7 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 url script-request-header chavyleung/everphoto/everphoto.cookie.js # 百词斩 -^https://group\.baicizhan\.com/group/rewards? url script-request-header chavyleung/bcz/bcz.cookie.js +# ^https://group\.baicizhan\.com/group/rewards? url script-request-header chavyleung/bcz/bcz.cookie.js # 叮咚买菜 ^https:\/\/maicai.api.ddxq.mobi\/point\/home url script-request-header chavyleung/mcdd/mcdd.cookie.js @@ -117,8 +117,8 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https://api\.dushu\.io/CheckIn url script-request-body chavyleung/fandeng/fandeng.cookie.js # 分期乐 -^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body chavyleung/fenqile/fenqile.cookie.js -^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body chavyleung/fenqile/fenqile.cookie.js +# ^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body chavyleung/fenqile/fenqile.cookie.js +# ^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body chavyleung/fenqile/fenqile.cookie.js # 美团 ^https:\/\/i.meituan.com\/evolve\/signin\/signpost\/ url script-request-body chavyleung/meituan/meituan.cookie.js @@ -140,14 +140,3 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/luckman.suning.com\/luck-web\/sign\/api\/clock_sign.do url script-request-header chavyleung/suning/suning.cookie.js ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do url script-request-header chavyleung/suning/suning.cookie.js ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) url script-request-header chavyleung/suning/suning.cookie.js - -# 豆瓣时间 -^https:\/\/fro\.douban\.com\/api\/v2\/niffler\/check_in\/status url script-request-header chavyleung/dbsj/dbsj.cookie.js - -# 趣头条 -^https:\/\/api\.1sapp\.com\/sign\/info? url script-request-header chavyleung/qtt/qtt.cookie.js -^https:\/\/api\.1sapp\.com\/content\/readV2? url script-request-header chavyleung/qtt/qtt.cookie.js -^https:\/\/api\.1sapp\.com\/x\/feed\/getReward? url script-request-header chavyleung/qtt/qtt.cookie.js - -# 米读 -^https:\/\/apiwz\.midukanshu\.com url script-request-body chavyleung/midu/midu.cookie.js \ No newline at end of file diff --git a/QuantumultX_Local_Cookie.conf b/QuantumultX_Local_Cookie.conf index b3547dbb9..69a5ef0d2 100644 --- a/QuantumultX_Local_Cookie.conf +++ b/QuantumultX_Local_Cookie.conf @@ -1,7 +1,7 @@ # 本配置适用于: QuanX TestFlight v1.0.6-build195 及以后版本 # 如果你是商店版, 请使用: QuantumultX_AppStore_Local_Cookie.conf -hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, m-bean.kaola.com, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, node.kg.qq.com, api.dushu.io, pm.m.fenqile.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, i.meituan.com, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, m.gdoil.cn, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, mobwsa.ximalaya.com, *.you.163.com, *.rrys2019.com, ios.zmzapi.com +hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, m-bean.kaola.com, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, node.kg.qq.com, api.dushu.io, pm.m.fenqile.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, i.meituan.com, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, m.gdoil.cn, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, 113.96.156.178, *.ximalaya.com, *.you.163.com, *.rrys2020.com, ios.zmzapi.com # 电信营业厅 ^https:\/\/wapside.189.cn:9001\/api\/home\/sign url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.cookie.js @@ -57,13 +57,13 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/access.video.qq.com\/user\/auth_refresh url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.cookie.js # 喜马拉雅 -^https?:\/\/.*\/mobile\-user\/homePage\/.* url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.cookie.js +^https?:\/\/.*\/mobile\-user\/(v1\/)?homePage\/.* url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.cookie.js # 网易严选 # ^https:\/\/m\.you\.163\.com\/xhr\/points\/index\.json url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/yanxuan/yanxuan.cookie.js # 字幕组 -^https?:\/\/(www\.)?rrys2019\.com\/?.? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js +^https?:\/\/(www\.)?rrys2020\.com\/?.? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js ^http:\/\/ios.zmzapi.com\/index.php.*a=(mobile_)?login url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js # 加油广东 @@ -81,8 +81,8 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js # 中国移动 -^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js -^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js # 猫咪音乐网 https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.cookie.js @@ -98,15 +98,11 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.cookie.js # 百词斩 -^https://group\.baicizhan\.com/group/rewards? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js +# ^https://group\.baicizhan\.com/group/rewards? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js # 叮咚买菜 ^https:\/\/maicai.api.ddxq.mobi\/point\/home url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.cookie.js -# 分期乐 -^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js -^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js - #樊登读书 ^https://api\.dushu\.io/CheckIn url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js @@ -136,14 +132,3 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/luckman.suning.com\/luck-web\/sign\/api\/clock_sign.do url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js - -# 豆瓣时间 -^https:\/\/fro\.douban\.com\/api\/v2\/niffler\/check_in\/status url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.cookie.js - -# 趣头条 -^https:\/\/api\.1sapp\.com\/sign\/info? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/qtt/qtt.cookie.js -^https:\/\/api\.1sapp\.com\/content\/readV2? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/qtt/qtt.cookie.js -^https:\/\/api\.1sapp\.com\/x\/feed\/getReward? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/qtt/qtt.cookie.js - -# 米读 -^https:\/\/apiwz\.midukanshu\.com url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/midu/midu.cookie.js \ No newline at end of file diff --git a/QuantumultX_Local_Task.conf b/QuantumultX_Local_Task.conf index 0a8514ca8..ceb023f13 100644 --- a/QuantumultX_Local_Task.conf +++ b/QuantumultX_Local_Task.conf @@ -55,20 +55,16 @@ 9 0 * * * chavyleung/10010/10010.js # 猫咪音乐网 2 0 * * * chavyleung/maomicd/maomicd.js -# 中国移动 -7 0 * * * chavyleung/10086/10086.js +# # 中国移动 +# 7 0 * * * chavyleung/10086/10086.js # 美团外卖 8 0 * * * chavyleung/wmmeituan/wmmeituan.js # 美团 7 0 * * * chavyleung/meituan/meituan.js # 时光相册 7 0 * * * chavyleung/everphoto/everphoto.js -# 百词斩 -50 23 * * * chavyleung/bcz/bcz.js # 叮咚买菜 7 0 * * * chavyleung/mcdd/mcdd.js -# 分期乐 -1 0 * * * chavyleung/fenqile/fenqile.js #樊登读书 1 0 * * * chavyleung/fandeng/fandeng.js #全民K歌 @@ -79,18 +75,9 @@ 1 0 * * * chavyleung/nio/nio.js #京东到家 1 0 * * * chavyleung/jddj/jddj.js -#网易考拉 -1 0 * * * chavyleung/wykl/wykl.js # WPS 0 9 * * * chavyleung/wps/wps.js #智行火车 1 0 * * * chavyleung/zxhc/zxhc.js # 苏宁易购 -7 0 * * * chavyleung/suning/suning.js -# 豆瓣时间 -1 0 * * * chavyleung/dbsj/dbsj.js -# 趣头条 -1 0 * * * chavyleung/qtt/qtt.js -# 米读 -*/1 * * * * chavyleung/midu/miduRead.js -1 0 * * * chavyleung/midu/miduSign.js \ No newline at end of file +7 0 * * * chavyleung/suning/suning.js \ No newline at end of file diff --git a/QuantumultX_Remote_Task.conf b/QuantumultX_Remote_Task.conf index e4ffd7a78..20e326307 100644 --- a/QuantumultX_Remote_Task.conf +++ b/QuantumultX_Remote_Task.conf @@ -75,7 +75,7 @@ # 6 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/yanxuan/yanxuan.js # 字幕组 -#网页:打开浏览器访问: http://www.rrys2019.com, App: 打开 APP 即可 +#网页:打开浏览器访问: http://www.rrys2020.com, App: 打开 APP 即可 7 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.js # QQ音乐 @@ -106,10 +106,6 @@ #打开 网站 `https://www.maomicd.com` 然后手动签到 1 次 9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.js -# 中国移动 -#打开 APP , 进入签到页面, 系统提示: `获取刷新链接: 成功`,然后手动签到 1 次 -9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js - # 美团外卖 #打开 APP , 进入签到页面, 系统提示: `获取刷新链接: 成功`,然后手动签到 1 次 9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.js @@ -122,18 +118,10 @@ #打开 APP 然后手动签到 1 次 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js -# 百词斩 -#打开 APP 手动签到一次: 访问下右下角 `我` > `我的铜板` > `加入百词斩小班` > `去查看` > `我的小班进去 领铜板` -0 8-20/4 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js - # 叮咚买菜 #打开 APP, 访问下`我的`>`积分` 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.js -# 分期乐 -#打开 APP 手动签到一次: 访问下右下角 `我的` > `乐星` > `签到` -10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.js - # 樊登读书 #打开 APP 手动签到一次: 访问下右下角 `我的` > `签到` 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js @@ -175,18 +163,3 @@ # 首页 > 签到有礼 # 首页 > 领取红包 7 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js - -# 豆瓣时间 -1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.js - -# 趣头条 -# 我的 > 右上角签到 -# 首页 > 金币奖励 -# 阅读文章或者播放视频 -1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/qtt/qtt.js - -# 米读 -# 书城 > 任意文章阅读 -# 我的 > 疯狂摇摇乐 -*/1 * * * * https://raw.githubusercontent.com/chavyleung/scripts/master/midu/miduRead.js -10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/midu/miduSign.js \ No newline at end of file diff --git a/README.md b/README.md index 4184ad183..0cea240e6 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,107 @@ # Chavy Scripts -![](https://img.shields.io/badge/license-MIT-blueviolet.svg) + +![](https://img.shields.io/badge/license-GPL-blueviolet.svg) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/chavyleung/scripts?color=%23c694ff) ![](https://badgen.net/github/stars/chavyleung/scripts) ![](https://tokei.rs/b1/github/chavyleung/scripts?category=code) ![GitHub contributors](https://img.shields.io/github/contributors/chavyleung/scripts) -# BoxJs + +Telegram讨论组:[Chavy Scripts Group](https://t.me/chavyscripts) + +--- + +- [Chavy Scripts](#chavy-scripts) +- [🧰BoxJs](#boxjs) + - [简介](#简介) + - [使用方式](#使用方式) + - [安装链接](#安装链接) + - [正式版](#正式版) + - [🧪测试版](#测试版) +- [🛠️Env.js](#️envjs) + - [调用方式](#调用方式) + - [功能列表](#功能列表) + - [HttpClient](#httpclient) + - [持久化数据](#持久化数据) + - [安装链接](#安装链接-1) + - [正式版](#正式版-1) +- [📃LICENSE](#license) + +--- + +# 🧰BoxJs + + +## 简介 A SPA Appliction be used for scripts utils -![Demo](https://github.com/chavyleung/scripts/blob/master/BoxJS.gif) +## 使用方式 +安装对应模块/插件后,浏览器访问: [boxjs.com](http://boxjs.com "BoxJs") + +## 安装链接 + * Shadowrocket: [boxjs.rewrite.surge.sgmodule](https://github.com/chavyleung/scripts/raw/master/box/rewrite/boxjs.rewrite.surge.sgmodule "BoxJs") + * Loon: [boxjs.rewrite.loon.plugin](https://github.com/chavyleung/scripts/raw/master/box/rewrite/boxjs.rewrite.loon.plugin "BoxJs") + * Quantumult X: [boxjs.rewrite.quanx.conf](https://github.com/chavyleung/scripts/raw/master/box/rewrite/boxjs.rewrite.quanx.conf "BoxJs") + * Surge: [boxjs.rewrite.surge.sgmodule](https://github.com/chavyleung/scripts/raw/master/box/rewrite/boxjs.rewrite.surge.sgmodule "BoxJs") + * Stash: [boxjs.rewrite.stash.stoverride](https://github.com/chavyleung/scripts/raw/master/box/rewrite/boxjs.rewrite.stash.stoverride "BoxJs") + +--- + +# 🛠️Env.js + +## 调用方式 + * Env.min.js放置于嵌入式脚本底端,然后头部调用功能 + ``` + const $ = new Env("你的脚本名称"); + ``` + +## 功能列表 +### HttpClient + + * 支持方法: get, post, put, delete, head, options, patch + ```javascript + let option = { + url: "http://www.example.com/", // URL,必须 + headers: { // 请求头,可选 + "Accept": "*/*", + "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Mobile/15E148 Safari/605.1.15", + "Content-Type": "application/json; charset=utf-8" + "" + }, + body: `auth_key=1234567&source_lang=EN&target_lang=ZH` // 请求体,POST等方法必须,字符串或对象 + } + let result = $.get(URL or options, callback(error, response, data)) // 不支持异步 + let result = $.post(URL or options, callback(error, response, data)) // 不支持异步 + …… + + let result = await $.http.get(URL or options).then(callback(response)) + let result = await $.http.post(URL or options).then(response => response.body) + let result = await $.http.put(URL or options).then(response => { + $.log(JSON.stringify(response.headers)); + return response.body + }) + …… + ``` + +### 持久化数据 + ```javascript + + $.getdata(‘chavy’) // 读取持久化数据 (string格式) + $.setdata(string, ‘chavy’) // 写入持久化数据 (string格式) + $.getjson(‘chavy’, default_value) // 读取持久化数据 (object格式),当读取失败后返回默认值 + $.setjson(object, ‘chavy’) // 写入持久化数据 (object格式) + + ``` + +## 安装链接 +### 正式版 + * 用于集成:[Env.min.js](./Env.min.js?raw=true "Env.min.js") + * 便于阅读:[Env.js](./Env.js?raw=true "Env.js") -[Scripts Vote](https://t.me/chavyscripts) +--- + +# 赞助 + +1. [CloudFlare](https://www.cloudflare.com/) -# LICENSE -Copyright © 2019-present chavyleung. This project is [GPL](https://github.com/chavyleung/scripts/blob/master/LICENSE) licensed. \ No newline at end of file +# 📃LICENSE +Copyright © 2019-present chavyleung. This project is [GPL](https://github.com/chavyleung/scripts/blob/master/LICENSE) licensed. diff --git a/acfun/acfun.js b/acfun/acfun.js index f294ccc4c..f5d55121a 100644 --- a/acfun/acfun.js +++ b/acfun/acfun.js @@ -27,7 +27,6 @@ function sign() { } chavy.log(`${cookieName}, data: ${data}`) }) - chavy.done() } function getinfo(signresult) { @@ -49,6 +48,7 @@ function getinfo(signresult) { detail = `共签: ${result.cumulativeDays}次, 连签: ${result.continuousDays}次, 说明: ${signresult.msg}` chavy.msg(title, subTitle, detail) chavy.log(`${cookieName}, data: ${data}`) + chavy.done() }) } diff --git a/10086/10086.cookie.js b/achived/10086/10086.cookie.js similarity index 100% rename from 10086/10086.cookie.js rename to achived/10086/10086.cookie.js diff --git a/achived/10086/10086.fee.cookie.js b/achived/10086/10086.fee.cookie.js new file mode 100644 index 000000000..13daf286f --- /dev/null +++ b/achived/10086/10086.fee.cookie.js @@ -0,0 +1,48 @@ +/** + * + * hostname = clientaccess.10086.cn + * + * # Surge + * Rewrite: CMCC = type=http-request,pattern=^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js,requires-body=true,debug=true + * Rewrite: CMCC = type=http-request,pattern=^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js,requires-body=true,debug=true + * Tasks: 10086-查话费 = type=cron,cronexp=10 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js,wake-system=true + * + * # QuanX + * ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js + * ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js + * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=10086-查话费 + * + * # Loon + * http-request ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true, tag=中国移动-查话费 + * http-request ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true, tag=中国移动-查话费 + * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js + * + */ + +const $ = new Env('中国移动') +$.KEY_autologin = 'chavy_autologin_cmcc' +$.KEY_getfee = 'chavy_getfee_cmcc' + +!(async () => { + const session = {} + session.url = $request.url + session.body = $request.body + session.headers = $request.headers + let key = '' + if (/autoLogin/.test(session.url)) { + key = $.KEY_autologin + } else if (/getRealFee/.test(session.url)) { + key = $.KEY_getfee + } + if ($.setdata(JSON.stringify(session), key)) { + $.subt = `获取会话: 成功! (${key})` + } else { + $.subt = `获取会话: 失败! (${key})` + } + $.msg($.name, $.subt, $.desc) +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +// prettier-ignore +function Env(t,e){class s{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,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,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("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}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 i=this.getdata(t);if(i)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,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(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 i=e.replace(/\[(\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)||(e=e.toString().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 e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(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),o=this.getval(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()?$persistentStore.read(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){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=(()=>{})){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})),$httpClient.get(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),this.got(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}=t;this.got.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){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).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"],s=t.mediaUrl||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=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(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("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} diff --git a/10086/10086.fee.js b/achived/10086/10086.fee.js similarity index 89% rename from 10086/10086.fee.js rename to achived/10086/10086.fee.js index d5085d10b..74afa8fe5 100644 --- a/10086/10086.fee.js +++ b/achived/10086/10086.fee.js @@ -121,4 +121,4 @@ function showmsg() { } // prettier-ignore -function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch{return{}}}}}writedata(){if(this.isNode){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),h=JSON.stringify(this.data);e?this.fs.writeFileSync(t,h):i?this.fs.writeFileSync(s,h):this.fs.writeFileSync(t,h)}}getdata(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setdata(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}get(t,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)):this.isNode()&&(this.got=this.got?this.got:require("got"),this.got(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t));else if(this.isNode()){this.got=this.got?this.got:require("got");const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t))}}msg(s=t,e="",i="",h){this.isSurge()||this.isLoon()?$notification.post(s,e,i):this.isQuanX()&&$notify(s,e,i),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t=null){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)} +function Env(t,e){class s{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,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,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("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}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 i=this.getdata(t);if(i)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,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(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 i=e.replace(/\[(\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)||(e=e.toString().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 e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(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),o=this.getval(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()?$persistentStore.read(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){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=(()=>{})){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})),$httpClient.get(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),this.got(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}=t;this.got.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){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).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"],s=t.mediaUrl||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=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(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("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} diff --git a/10086/10086.js b/achived/10086/10086.js similarity index 100% rename from 10086/10086.js rename to achived/10086/10086.js diff --git a/10086/README.md b/achived/10086/README.md similarity index 100% rename from 10086/README.md rename to achived/10086/README.md diff --git a/bcz/README.md b/achived/bcz/README.md similarity index 100% rename from bcz/README.md rename to achived/bcz/README.md diff --git a/bcz/bcz.cookie.js b/achived/bcz/bcz.cookie.js similarity index 100% rename from bcz/bcz.cookie.js rename to achived/bcz/bcz.cookie.js diff --git a/bcz/bcz.js b/achived/bcz/bcz.js similarity index 100% rename from bcz/bcz.js rename to achived/bcz/bcz.js diff --git a/dbsj/README.md b/achived/dbsj/README.md similarity index 100% rename from dbsj/README.md rename to achived/dbsj/README.md diff --git a/dbsj/dbsj.cookie.js b/achived/dbsj/dbsj.cookie.js similarity index 100% rename from dbsj/dbsj.cookie.js rename to achived/dbsj/dbsj.cookie.js diff --git a/dbsj/dbsj.js b/achived/dbsj/dbsj.js similarity index 100% rename from dbsj/dbsj.js rename to achived/dbsj/dbsj.js diff --git a/fenqile/README.md b/achived/fenqile/README.md similarity index 100% rename from fenqile/README.md rename to achived/fenqile/README.md diff --git a/fenqile/fenqile.cookie.js b/achived/fenqile/fenqile.cookie.js similarity index 100% rename from fenqile/fenqile.cookie.js rename to achived/fenqile/fenqile.cookie.js diff --git a/fenqile/fenqile.js b/achived/fenqile/fenqile.js similarity index 100% rename from fenqile/fenqile.js rename to achived/fenqile/fenqile.js diff --git a/bilibili/README.md b/bilibili/README.md index 5bb24aeee..01937b3c2 100644 --- a/bilibili/README.md +++ b/bilibili/README.md @@ -8,6 +8,7 @@ > 2020.3.16 添加银瓜子转硬币脚本 感谢[@lcandy2](https://github.com/lcandy2) PR +> 2022.7.7 添加粉丝牌升级任务 ## 配置 (Surge) ```properties @@ -16,9 +17,14 @@ [Script] http-request ^https:\/\/(www|live)\.bilibili\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js -cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js + +bilibili = type=cron,cronexp=10 0 0 * * *,wake-system=1,timeout=100,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js + # 如需银瓜子转硬币,添加以下内容 cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js + +# 如需抽直播红包,添加以下内容 +bilibili = type=cron,cronexp=10 10 0 * * *,wake-system=1,timeout=100,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/redpocket.js ``` ## 配置 (QuanX) @@ -49,6 +55,7 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr 4. 打开浏览器访问: https://www.bilibili.com 或 https://live.bilibili.com 5. 系统提示: `获取Cookie: 成功` 6. 最后就可以把第 1 条脚本注释掉了 +7. 请根据自己的粉丝牌数设置脚本超时时间,一个粉丝牌预计执行20s > 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. diff --git a/bilibili/bilibili.js b/bilibili/bilibili.js index fb3854602..439ab8831 100644 --- a/bilibili/bilibili.js +++ b/bilibili/bilibili.js @@ -1,108 +1,223 @@ -const cookieName = 'bilibili' -const cookieKey = 'chavy_cookie_bilibili' -const chavy = init() -const cookieVal = chavy.getdata(cookieKey) +const $ = new Env('B站直播') +$.bilibiliLive = 'chavy_cookie_bilibili' +const cookie = $.getdata($.bilibiliLive) +const csrf = cookie.match(/.*?bili_jct=(.*?);/)?.[1] -sign() +$.desc = [] -function sign() { - let url = { - url: `https://api.live.bilibili.com/sign/doSign`, - headers: { - Cookie: cookieVal +!(async () => { + await sign() + if ($.sign?.code == 1011040) { + await getSignInfo() + } + await getMedalList() + for (let i = 0; i < $.medalList.length; i++) { + const roomId = $.medalList[i].roomId + $.desc.push(`执行粉丝牌任务(${i+1}/${$.medalList.length}): ${$.medalList[i].nickname}`) + for (let index = 0; index < 5; index++) { + await like(roomId) + await $.wait(1600) + await share(roomId) + await $.wait(1600) } + await $.wait(1600) + await sendMsg(roomId) } - url.headers['Origin'] = 'api.live.bilibili.com' - url.headers['Referer'] = 'http://live.bilibili.com/' - url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01' - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' + await notify() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) - chavy.get(url, (error, response, data) => { - let result = JSON.parse(data) - let title = `${cookieName}` - // 签到成功 - if (result && result.code == 0) { - let subTitle = `签到结果: 成功` - let detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}` - chavy.msg(title, subTitle, detail) - } - // 签到重复 - else if (result && result.code == 1011040) { - getsigninfo() +function notify() { + return new Promise((resolve) => { + $.subt = `签到:${$.sign.message}` + $.msg($.name, $.subt, $.desc.join('\n')) + resolve() + }) +} + +function sign() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + } } - // 签到失败 - else { - let subTitle = `签到结果: 失败` - let detail = `说明: ${result.message}` - chavy.msg(title, subTitle, detail) + $.get(url, (err, resp, data) => { + try { + $.sign = JSON.parse(data) + const result = JSON.parse(data) + if (result?.code == 0) { + $.desc.push(`本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`) + } else if (result?.code == -101) { + $.desc.push('Cookie已过期, 请重新获取Cookie') + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function getSignInfo() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/sign/GetSignInfo', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15', + 'cookie': cookie + } } - chavy.log(`${cookieName}, data: ${data}`) + $.get(url, (err, resp, data) => { + try { + const result = JSON.parse(data) + if (result && result.code == 0) { + $.desc.push(`本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) }) +} - chavy.done() +function getMedalList() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/app-ucenter/v1/fansMedal/panel?page_size=50&page=1', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + } + } + $.get(url, (err, resp, data) => { + try { + const res = JSON.parse(data) + const items = [...res.data.list, ...res.data.special_list] + $.medalList = items.filter(e => e?.medal?.level < 21).map((e) => { + return { + roomId: e?.room_info?.room_id, + nickname: e?.medal?.medal_name, + } + }) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) } -function getsigninfo() { - let url = { - url: `https://api.live.bilibili.com/sign/GetSignInfo`, - headers: { - Cookie: cookieVal + +function sendMsg(roomId) { + return new Promise((resolve) => { + const body = { + bubble: 0, + msg: '打卡', + color: 16777215, + mode: 2, + fontsize: 25, + rnd: Math.round(new Date().getTime() / 1000).toString(), + roomid: roomId, + csrf: csrf, + csrf_token: csrf + } + const url = { + url: 'https://api.live.bilibili.com/msg/send', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data' + }, + body: $.queryStr(body) } - } - url.headers['Host'] = 'api.live.bilibili.com' - url.headers['Origin'] = 'http://live.bilibili.com' - url.headers['Referer'] = 'http://live.bilibili.com/' - url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01' - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' - chavy.get(url, (error, response, data) => { - let title = `${cookieName}` - let subTitle = `签到结果: 成功 (重复签到)` - let detail = `` - let result = JSON.parse(data) - if (result && result.code == 0) detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}` - chavy.msg(title, subTitle, detail) + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) }) } -function init() { - isSurge = () => { - return undefined === this.$httpClient ? false : true - } - isQuanX = () => { - return undefined === this.$task ? false : true - } - getdata = (key) => { - if (isSurge()) return $persistentStore.read(key) - if (isQuanX()) return $prefs.valueForKey(key) - } - setdata = (key, val) => { - if (isSurge()) return $persistentStore.write(key, val) - if (isQuanX()) return $prefs.setValueForKey(key, val) - } - msg = (title, subtitle, body) => { - if (isSurge()) $notification.post(title, subtitle, body) - if (isQuanX()) $notify(title, subtitle, body) - } - log = (message) => console.log(message) - get = (url, cb) => { - if (isSurge()) { - $httpClient.get(url, cb) + +function like(roomId) { + return new Promise((resolve) => { + const body = { + roomid: roomId, + csrf: csrf } - if (isQuanX()) { - url.method = 'GET' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + const url = { + url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/interact/likeInteract', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + }, + body: $.queryStr(body) } - } - post = (url, cb) => { - if (isSurge()) { - $httpClient.post(url, cb) + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function share(roomId) { + return new Promise((resolve) => { + const body = { + roomid: roomId, + csrf: csrf, + interact_type: 3 } - if (isQuanX()) { - url.method = 'POST' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + const url = { + url: 'https://api.live.bilibili.com/xlive/app-room/v1/index/TrigerInteract', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data', + 'sec-fetch-site': 'same-site', + 'origin': 'https://www.bilibili.com' + }, + body: $.queryStr(body) } - } - done = (value = {}) => { - $done(value) - } - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } + + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) } + +// pre-ignore +function Env(t,e){class s{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,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,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.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}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 i=this.getdata(t);if(i)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,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(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 i=e.replace(/\[(\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)||(e=e.toString().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 e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(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),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);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()?$persistentStore.read(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){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=(()=>{})){if(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})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(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&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(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:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";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[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,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&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}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),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}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"],s=t.mediaUrl||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,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}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=this.logs.concat(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):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file diff --git a/bilibili/redpocket.js b/bilibili/redpocket.js new file mode 100644 index 000000000..9136750b2 --- /dev/null +++ b/bilibili/redpocket.js @@ -0,0 +1,152 @@ +const $ = new Env('B站抽红包') +$.bilibiliLive = 'chavy_cookie_bilibili' +const cookie = $.getdata($.bilibiliLive) +const csrf = cookie.match(/.*?bili_jct=(.*?);/)?.[1] + +$.desc = [] + +!(async () => { + await getRedPocketList() + for (let i = 0; i < $.list.length; i++) { + const redPocket = $.list[i] + await getLotteryInfoWeb(redPocket.roomId, redPocket.runame) + await redPocketDraw(redPocket) + await sendMsg(redPocket.roomId) + await $.wait(1000) + } + await notify() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function notify() { + return new Promise((resolve) => { + $.subt = `红包主播列表` + $.msg($.name, $.subt, $.desc.join('\n')) + resolve() + }) +} + +function getRedPocketList() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/fuxi-interface/JuneRedPacket2022Controller/redPocketPlaying', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'sec-fetch-site': 'same-site', + "Referer": "https://live.bilibili.com/", + 'cookie': cookie + } + } + $.get(url, (err, resp, data) => { + try { + const { _ts_rpc_return_ } = JSON.parse(data) + $.list = _ts_rpc_return_?.data?.list.filter(e => e.countDown > 10) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function getLotteryInfoWeb(roomid, runame) { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfoWeb?roomid=' + roomid, + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15', + 'cookie': cookie + } + } + $.get(url, (err, resp, data) => { + try { + const result = JSON.parse(data) + if (result?.code == 0) { + const { popularity_red_pocket } = result?.data + const total_price = popularity_red_pocket?.[0]?.total_price / 1000 || 0 + $.desc.push(`${runame}: 电池价值${total_price}元`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + + +function redPocketDraw(redPocket) { + return new Promise((resolve) => { + const body = { + ruid: redPocket.ruid, + room_id: redPocket.roomId, + lot_id: redPocket.lotId, + csrf: csrf, + csrf_token: csrf, + } + const url = { + url: 'https://api.live.bilibili.com/xlive/lottery-interface/v1/popularityRedPocket/RedPocketDraw', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + }, + body: $.queryStr(body) + } + $.post(url, (err, resp, data) => { + try { + // nothing + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function sendMsg(roomId) { + return new Promise((resolve) => { + const body = { + bubble: 0, + msg: '老板大气!点点红包抽礼物!', + color: 16777215, + mode: 2, + fontsize: 25, + rnd: Math.round(new Date().getTime() / 1000).toString(), + roomid: roomId, + csrf: csrf, + csrf_token: csrf + } + const url = { + url: 'https://api.live.bilibili.com/msg/send', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data' + }, + body: $.queryStr(body) + } + + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +// pre-ignore +function Env(t,e){class s{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,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,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.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}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 i=this.getdata(t);if(i)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,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(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=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(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 i=e.replace(/\[(\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)||(e=e.toString().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 e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(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),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);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()?$persistentStore.read(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){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=(()=>{})){if(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})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(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&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(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:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";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[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,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&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}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),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}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"],s=t.mediaUrl||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,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}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=this.logs.concat(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):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 1c0884bd3..106c40bc5 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1,468 +1,543 @@ - - - BoxJs - - - - - - - - - - - - - -
-
- - - - - -