You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
592 lines
25 KiB
592 lines
25 KiB
/*
|
|
|
|
zqmain1.json格式如下
|
|
{
|
|
"user":"jammy",
|
|
"zqcookie":"",
|
|
|
|
"shareurl":[
|
|
"",
|
|
"",
|
|
""
|
|
],
|
|
"qdbodys":[
|
|
"",
|
|
"",
|
|
""
|
|
],
|
|
"boxbodys":[
|
|
"",
|
|
"",
|
|
""
|
|
]
|
|
}
|
|
变量说明:
|
|
zqcookie地址https://kandian.wkandian.com/v17/NewTask/getTaskList.json url后面全部
|
|
shareurl 火爆分享链接
|
|
qdbodys 签到宝箱 2个,签到和幸运奖励
|
|
boxbodys 任务完成奖励和宝箱 7个,100-150-200-500 188-288-368
|
|
*/
|
|
|
|
const $ = new Env('中青看点-基本任务');
|
|
const notify = $.isNode() ? require('./sendNotify') : '';
|
|
|
|
const hour = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000).getHours();
|
|
const minute = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000).getMinutes();
|
|
|
|
const TS = Math.round((new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000) / 1000);
|
|
let i = '',m = '',n = '',s = '';
|
|
|
|
const basicurl="https://kandian.wkandian.com/";
|
|
const YOUTH_HOST = "https://kd.youth.cn/WebApi/";
|
|
const basicApi = 'CommonReward/toGetReward.json';
|
|
|
|
let usernmae="";
|
|
let tsxx=""; //推送信息
|
|
let ts=true; //推送开关
|
|
let otherts=false; //重要信息会自动打开推送,初始化状态是关闭
|
|
|
|
let zqtoken="",zqcookie="",zquid="",zqsign="",zquuid="",rewardbody="",scBody="",cookie="",cookie_id="",syhburl="",fxbody="";
|
|
let urlArr=[],qdArr=[],boxArr=[];
|
|
let rotaryscore=0, rotarytimes=0,doublerotary=0,total=0;
|
|
|
|
//json文件,改成你的名字
|
|
const zqbody = require("./zqqtrw-esjc.json");
|
|
|
|
console.log(`您使用的是json文件模式\n`)
|
|
zqcookie = zqbody.zqcookie;
|
|
|
|
|
|
//cookie参数处理
|
|
username=zqbody.user;
|
|
var params =UrlParamHash(zqcookie);
|
|
zquid=params["uid"];
|
|
zqkey=params["zqkey"];
|
|
zqkey_id=params["zqkey_id"];
|
|
zquuid=params["uuid"];
|
|
zqtoken = params["zqtoken"];
|
|
cookie=zqkey;
|
|
cookie_id=zqkey_id;
|
|
|
|
//时间戳
|
|
var time1 = Date.parse( new Date() ).toString();
|
|
time1 = time1.substr(0,10);
|
|
|
|
//cookie,翻倍,签到会用到,不然提示未登录
|
|
let rotarbody = "cookie="+ cookie + '&cookie_id=' + cookie_id;
|
|
//看看赚宝箱body
|
|
let boxbody='access=WIFI&app-version=3.5.5&app_version=3.5.5&channel=c1002&cookie='+ zqkey + '&cookie_id=' + zqkey_id+'&zqkey='+zqkey+'&zqkey_id='+zqkey_id+'&device_brand=xfdg&device_id=cc7dgdsgfsz83e&device_model=1gx&device_platform=android&device_type=android&inner_version=202107261526&mi=0&openudid=cc7dgdsgfsz83e&os_api=27&os_version=bdftgsdfga&phone_network=WIFI&phone_sim=1'+'&request_time=' + time1 +'&time=' + time1
|
|
|
|
//可选功能,火爆分享,签到,收奖励宝箱
|
|
//火爆分享链接
|
|
urlArr=zqbody.shareurl;
|
|
//签到的宝箱
|
|
qdArr=zqbody.qdbodys;
|
|
//其他宝箱
|
|
boxArr=zqbody.boxbodys;
|
|
|
|
var week = new Date().getDay();
|
|
|
|
!(async () => {
|
|
|
|
|
|
if ($.isNode()){
|
|
tsxx+="【"+username+"】本次任务记录:\n";
|
|
await taskall();
|
|
}else {
|
|
console.log(`暂不支持v2p变量,请使用json文件\n`);
|
|
}
|
|
})()
|
|
.catch((e) => {
|
|
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
|
|
})
|
|
.finally(() => {
|
|
$.done();
|
|
})
|
|
|
|
function UrlParamHash(url) {
|
|
var params = [], h;
|
|
//var hash = url.slice(url.indexOf("?") + 1).split('&');
|
|
|
|
var hash = url.split('&');
|
|
for (var i = 0; i < hash.length; i++) {
|
|
h = hash[i].split("=");
|
|
params.push(h[0]);
|
|
params[h[0]] = h[1];
|
|
}
|
|
return params;
|
|
}
|
|
|
|
|
|
async function taskall(){
|
|
//八点之后开启报名打开
|
|
|
|
if (minute < 30) {//设置每小时只执行一次
|
|
|
|
await $.wait(1000);
|
|
//开签到宝箱
|
|
if (hour == 5){
|
|
await do_openbox(qdArr,"签到奖励");
|
|
if (week==1){ //周一申请阅读翻倍
|
|
do_readdouble();
|
|
}
|
|
}
|
|
if (hour == 17 ) {
|
|
rewardtype=5;
|
|
await do_sc_prize2(rewardtype); //领5分钟60分钟阅读奖励50+400
|
|
rewardtype=60;
|
|
await do_sc_prize2(rewardtype); //领5分钟60分钟阅读奖励50+400
|
|
}
|
|
await $.wait(1000);
|
|
|
|
//收看看赚任务完成宝箱,看看赚 12:30-14:50
|
|
if (hour == 20 ) {
|
|
await checklookbox();
|
|
}
|
|
|
|
//收每日任务宝箱
|
|
if (hour == 20){
|
|
await do_openbox(boxArr,"收任务奖励");
|
|
}
|
|
}
|
|
|
|
await do_userdata();
|
|
|
|
//火爆分享放到最后
|
|
if (minute < 30) {
|
|
|
|
//分享文章,被好友阅读后每篇500
|
|
if (hour == 8 || hour == 12 || hour == 18 || hour == 20) {
|
|
await do_hbfx();
|
|
}
|
|
|
|
//推送信息
|
|
if (ts){
|
|
if ((hour == 12) || (hour == 20)){
|
|
if ($.isNode()){await notify.sendNotify($.name, tsxx );}
|
|
}else if (otherts){
|
|
if ($.isNode()){
|
|
await notify.sendNotify($.name, tsxx );
|
|
otherts=false; //推送完成,重置为初始化状态
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
//批量开宝箱
|
|
async function do_openbox(bodyArr,msg) {
|
|
let num=bodyArr.length;
|
|
if ( num > 0) {
|
|
console.log(`共${num}个奖励body`)
|
|
for (let k = 0; k < num; k++) {
|
|
//let boxVal = bodyArr[k];
|
|
console.log(`--------开始收取第 ${k + 1} 次奖励`);
|
|
do_toGetReward(bodyArr[k],msg);
|
|
await $.wait(1000);
|
|
}
|
|
}
|
|
}
|
|
//检测宝箱状态 https://kd.youth.cn/WebApi/Nameless/getBoxRewardConf?
|
|
//{"status":1,"data":{"list":[{"id":0,"status":0,"score":50,"num":3},{"id":1,"status":0,"score":100,"num":8},{"id":2,"status":0,"score":200,"num":15}],"num":0}}
|
|
function checklookbox() {
|
|
let qdscore=0;
|
|
return new Promise((resolve, reject) => {
|
|
const url = {
|
|
url: `https://kd.youth.cn/WebApi/Nameless/getBoxRewardConf?id=`+boxbody,
|
|
headers : {
|
|
'Host': 'kd.youth.cn',
|
|
'Referer':'https://kd.youth.cn/h5/20190527watchMoney/?'+boxbody+'&request_time=' + time1+'&time=' + time1,
|
|
}
|
|
}
|
|
$.get(url, async (error, response, data) => {
|
|
const result = JSON.parse(data);
|
|
console.log(`${JSON.stringify(result)}`);
|
|
if(result.status == 1){
|
|
console.log(`已完成任务数${result.data.num}`);
|
|
//tsxx += `已完成任务数${result.data.num}\n`;
|
|
for (let k=0;k<3;k++){
|
|
qdscore=result.data.list[k].score;
|
|
if (result.data.list[k].status==1){
|
|
console.log(`🏠宝箱${k+1}:${qdscore}青豆未领取,尝试领取宝箱${k+1}`);
|
|
await openlookbox(k.toString());
|
|
await $.wait(30000);
|
|
}else if (result.data.list[k].status==2){
|
|
console.log(`🏠宝箱${k+1}:${qdscore}青豆已领取,跳过。`);
|
|
}else if (result.data.list[k].status==0){
|
|
console.log(`开启宝箱需完成任务:${result.data.list[k].num} 次未达成,跳过。`);
|
|
tsxx += `宝箱${k+1}开启未达成,跳过。\n`;
|
|
}
|
|
}
|
|
}else{
|
|
console.log(`${result}`);
|
|
}
|
|
resolve();
|
|
})
|
|
})
|
|
}
|
|
/*
|
|
//看看赚完成任务宝箱
|
|
async function do_openlookbox() {
|
|
|
|
console.log(`--------收取看看赚任务完成奖励`);
|
|
for(let k = 0; k < 3; k++){
|
|
await openlookbox(k.toString());
|
|
await $.wait(30000);
|
|
}
|
|
}
|
|
*/
|
|
//开看看赚任务宝箱
|
|
function openlookbox(id) {
|
|
return new Promise((resolve, reject) => {
|
|
//const time = new Date().getTime();
|
|
const url = {
|
|
url: `${basicurl}WebApi/Nameless/getBoxReward?id=`+id+'&'+boxbody,
|
|
headers : {
|
|
'Host': 'kandian.wkandian.com',
|
|
'Referer':'https://kandian.wkandian.com/h5/20190527watchMoney/?keyword_wyq=woyaoq.com&access=WIFI&app-version=3.6.0&app_version=3.6.0&carrier=%E4%B8%AD%E5%9B%BD%E7%A7%BB%E5%8A%A8&channel=c1005&'+boxbody,
|
|
}
|
|
}
|
|
$.get(url, (error, response, data) => {
|
|
const result = JSON.parse(data)
|
|
if(result.status == 1){
|
|
console.log(`🏠获取:${result.data}青豆`);
|
|
}else{
|
|
console.log(result)
|
|
}
|
|
resolve();
|
|
})
|
|
})
|
|
}
|
|
|
|
|
|
//火爆分享
|
|
async function do_hbfx() {
|
|
let times=randomNum(2,4);
|
|
console.log("本次随机助力次数:" + times);
|
|
tsxx += `【火爆分享】${hour}点${minute}分开始分享助力${times}次\n`;
|
|
//otherts=true;
|
|
|
|
$.log(`您共提供${urlArr.length}条分享链接`)
|
|
for(let i=0;i<times;i++){
|
|
let waittime = randomNum(50000,200000);
|
|
console.log(`随机延迟${waittime/1000}秒`);
|
|
//console.log(`分享第${i+1}次`);
|
|
let num=urlArr.length;
|
|
if ( num > 0) {
|
|
let m = Math.floor(Math.random()*(num));
|
|
$thisurl=urlArr[m];
|
|
$.log(`-------------------------\n本次使用第${m+1}条分享链接`)
|
|
}
|
|
|
|
if($thisurl.indexOf("script.baertt.com/count2/callback") > -1) {
|
|
var url = $thisurl;
|
|
var s_si = url.match(/si=(.*?)&/)[1];
|
|
//开始分享
|
|
await postShareInfoa(url,s_si, i)
|
|
await $.wait(waittime);
|
|
} else {
|
|
console.log("️url链接错误");
|
|
}
|
|
}
|
|
}
|
|
//分享
|
|
async function postShareInfoa(o_url,o_si, num) {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
var desclist = ["㊙️这是秘密分享~", "😁不能外传哦~", "☺️猜猜我是谁~","😆别点击太猛,容易feng","适当分享哈哈哈~","🈶广告位招租~","🔍开天眼查会员找木白姐姐~","🎈TG https://t.me/topstyle996","☎️TG频道 https://t.me/TopStyle2021","😆差不多得了,要黑号了~"];
|
|
var n_si = randomsi();
|
|
var iosV = parseInt(Math.random() * (14 - 11 + 1) + 11, 10);
|
|
var n_url = o_url.replace(o_si, n_si);
|
|
var header = {
|
|
'Accept-Encoding': `gzip, deflate, br`,
|
|
'Accept': `*/*`,
|
|
'Connection': `keep-alive`,
|
|
'Referer': `https://focus.youth.cn/`,
|
|
'Host': `script.baertt.com`,
|
|
'User-Agent': `Mozilla/5.0 (iPhone; CPU iPhone OS ${iosV}_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.7(0x18000730) NetType/WIFI Language/zh_CN`,
|
|
'Accept-Language': `zh-cn`
|
|
};
|
|
|
|
let url = {
|
|
url: n_url,
|
|
headers: header,
|
|
};
|
|
$.get(url, async (err, resp, data) => {
|
|
try {
|
|
console.log(`【分享阅读】第${num}次\n ${desclist[num]}`);
|
|
//$.msg(`【中青】分享阅读${num}\n`, "", desclist[num-1]);
|
|
console.log(data)
|
|
} catch (e) {
|
|
$.logErr(e, resp);
|
|
} finally {
|
|
resolve()
|
|
}
|
|
});
|
|
|
|
return 0;
|
|
}, 3000)
|
|
|
|
})
|
|
|
|
}
|
|
function formatDateTime(inputTime) {
|
|
var date = new Date(inputTime);
|
|
var y = date.getFullYear();
|
|
var m = date.getMonth() + 1;
|
|
m = m < 10 ? ('0' + m) : m;
|
|
var d = date.getDate();
|
|
d = d < 10 ? ('0' + d) : d;
|
|
var h = date.getHours();
|
|
h = h < 10 ? ('0' + h) : h;
|
|
var minute = date.getMinutes();
|
|
var second = date.getSeconds();
|
|
minute = minute < 10 ? ('0' + minute) : minute;
|
|
second = second < 10 ? ('0' + second) : second;
|
|
return y + '-' + m + '-' + d;
|
|
};
|
|
|
|
|
|
//用户信息
|
|
function do_userdata() {
|
|
return new Promise(resolve => {
|
|
|
|
url=`${basicurl}v15/user/userdata.json?`+zqcookie;
|
|
$.get(userdata(url), async(err, resp, data) => {
|
|
try {
|
|
if (err) {
|
|
console.log(`${JSON.stringify(err)}`)
|
|
console.log(resp)
|
|
console.log(`${$.name} API请求失败,请检查网路重试`)
|
|
} else {
|
|
if (safeGet(data)) {
|
|
const result = JSON.parse(unescape(data));
|
|
//console.log(`userdata:${JSON.stringify(result)}\n`)
|
|
if (result.success == true) {
|
|
console.log(`==========================`)
|
|
tsxx += `==========================\n`;
|
|
console.log(`用户名:${zqbody.user} `);
|
|
tsxx += `用户名:${zqbody.user} \n`;
|
|
console.log(`青豆总数:${result.items.score} `);
|
|
tsxx += `青豆总数:${result.items.score} \n`;
|
|
//自动提现
|
|
console.log(`今日获得青豆:${result.items.today_score} \n明日签到青豆:${result.items.sign_reward_score}`)
|
|
tsxx += `今日获得青豆:${result.items.today_score} \n明日签到青豆:${result.items.sign_reward_score}\n`;
|
|
if (result.items.sign_status == 0) {
|
|
console.log(`今日签到状态:未签到。去执行签到 ---`)
|
|
//await do_sign();
|
|
} else if (result.items.sign_status == 1) {
|
|
console.log(`今日签到状态:已签到`);
|
|
tsxx += `今日签到状态:已签到\n`;
|
|
}
|
|
if (result.items.is_login==1){
|
|
console.log(`登入状态:已登入`);
|
|
tsxx += `登入状态:已登入\n`;
|
|
}
|
|
console.log(`账户余额:${result.items.money_str}`);
|
|
//tsxx += `账户余额:${result.items.money_str}\n`;
|
|
} else {
|
|
console.log(`个人信息获取失败:${JSON.stringify(result)}\n`)
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
$.logErr(e, resp)
|
|
} finally {
|
|
resolve();
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
//通用函数,领取宝箱和奖励
|
|
function do_toGetReward(rewardbody,msg) {
|
|
//console.log(`body:${rewardbody}`)
|
|
return new Promise(resolve => {
|
|
let url = {
|
|
url : 'https://kandian.wkandian.com/v5/CommonReward/toGetReward.json',
|
|
headers : {
|
|
'device-platform': 'android',
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'Content-Length': rewardbody.length.toString(),
|
|
'Host': 'kandian.wkandian.com',
|
|
},
|
|
body : rewardbody,
|
|
}
|
|
$.post(url, async (err, resp, data) => {
|
|
try {
|
|
if (err) {
|
|
console.log(`${JSON.stringify(err)}`)
|
|
console.log(resp)
|
|
console.log(`${$.name} API请求失败,请检查网路重试`)
|
|
} else {
|
|
if (safeGet(data)) {
|
|
const result = JSON.parse(data);
|
|
//console.log(`结果:${JSON.stringify(result)}\n`)
|
|
if (!msg){msg='开启宝箱';}
|
|
if (result.success == true) {
|
|
console.log(`【${msg}-成功】获得 ${result.items.score} 青豆!`);
|
|
tsxx += `【${msg}-成功】获得 ${result.items.score} 青豆\n`;
|
|
} else {
|
|
console.log(`【${msg}-失败】:${JSON.stringify(result)}`);
|
|
tsxx += `【${msg}-失败】:${result.message}\n`;
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
$.logErr(e, resp)
|
|
} finally {
|
|
resolve();
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
//领取5分钟时长奖励
|
|
function do_sc_prize2(rewardtype) {
|
|
data =getFormData( {'request_time': TS, 'reward_type': rewardtype, 'token': zqtoken, 'uid': zquid});
|
|
//$.log(`${data}`);
|
|
return new Promise(resolve => {
|
|
let options = {
|
|
url: `${basicurl}v17/Ad/getReward.json`,
|
|
headers: {
|
|
'Token': zqtoken,
|
|
'Content-Type': `application/x-www-form-urlencoded`,
|
|
'Host': `kandian.wkandian.com`,
|
|
'Connection': `Keep-Alive`,
|
|
'Accept-Encoding': `gzip`,
|
|
'User-Agent': `okhttp/3.12.2`
|
|
},
|
|
body: data
|
|
};
|
|
$.post(options, async(err, resp, data) => {
|
|
try {
|
|
if (err) {
|
|
console.log(`${JSON.stringify(err)}`)
|
|
console.log(resp)
|
|
console.log(`${$.name} API请求失败,请检查网路重试`)
|
|
} else {
|
|
if (safeGet(data)) {
|
|
const result = JSON.parse(data);
|
|
//console.log(`领取5分钟时长奖励结果:${JSON.stringify(result)}\n`)
|
|
if (result.success == true) {
|
|
console.log(`领取${rewardtype}分钟时长奖励成功,获得 ${result.items.score} 青豆!`)
|
|
} else {
|
|
console.log(`领取${rewardtype}分钟时长奖励失败:${JSON.stringify(result)}\n`)
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
$.logErr(e, resp)
|
|
} finally {
|
|
resolve();
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
//阅读翻倍,周一申请
|
|
function do_readdouble() {
|
|
console.log(weekstr);
|
|
console.log("尝试申请阅读翻倍");
|
|
let doublebody= 'zqkey='+zqkey+'&zqkey_id='+zqkey_id+'&uid='+zquid+'&request_time=' + time1;
|
|
return new Promise((resolve) => {
|
|
let url = {
|
|
url : 'https://kandian.wkandian.com/v17/NewTask/setJoinTaskPromotion.json?'+ doublebody,
|
|
headers : {
|
|
'Host': 'kandian.wkandian.com'
|
|
},
|
|
}
|
|
$.get(url, (error, response, data) => {
|
|
const result = JSON.parse(data)
|
|
if(result.success == true){
|
|
console.log('阅读翻倍:'+result.message);
|
|
tsxx += `✅${result.message}\n`;
|
|
otherts=true;
|
|
}else{
|
|
console.log('翻倍失败:'+result.message);
|
|
tsxx += `⛔️${result.message}\n`;
|
|
}
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
|
|
//basic
|
|
function basic(api,body) {
|
|
return {
|
|
url: `${basicurl}v5/`+api,
|
|
headers: {
|
|
'Accept-Encoding': `gzip`,
|
|
'Connection': `keep-alive`,
|
|
'Host': `kandian.wkandian.com`,
|
|
'User-Agent': `okhttp/3.12.2`,
|
|
},
|
|
body: body
|
|
}
|
|
}
|
|
|
|
|
|
//userdata
|
|
function userdata(url) {
|
|
|
|
return {
|
|
url: url,
|
|
headers: {
|
|
'Host': `kandian.wkandian.com`,
|
|
'Connection': `Keep-Alive`,
|
|
'Accept-Encoding': `gzip`,
|
|
'User-Agent': `okhttp/3.12.2`
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function safeGet(data) {
|
|
try {
|
|
if (typeof JSON.parse(data) == "object") {
|
|
return true;
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
console.log(`服务器访问数据为空,请检查自身设备网络情况`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function randomNum(minNum, maxNum) {
|
|
switch (arguments.length) {
|
|
case 1:
|
|
return parseInt(Math.random() * minNum + 1, 10);
|
|
break;
|
|
case 2:
|
|
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
|
|
break;
|
|
default:
|
|
return 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//随机udid 小写
|
|
function randomsi() {
|
|
function S4() {
|
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
}
|
|
return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
|
|
}
|
|
|
|
|
|
function getFormData(element,key,list){
|
|
var list = list || [];
|
|
if(typeof(element)=='object'){
|
|
for (var idx in element)
|
|
getFormData(element[idx],key?key+'['+idx+']':idx,list);
|
|
} else {
|
|
list.push(key+'='+encodeURIComponent(element));
|
|
}
|
|
return list.join('&');
|
|
}
|
|
// prettier-ignore
|
|
function Env(t,e){"undefined"!=typeof process&&JSON.stringify(process.env).indexOf("GITHUB")>-1&&process.exit(0);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("",`🔔${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}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("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=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,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}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=["","==============📣系统通知📣=============="];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)}}(t,e)}
|