jd_scripts/jd_immortal_answer.js

479 lines
537 KiB
JavaScript
Raw Normal View History

/*
京东神仙书院答题
根据bing搜索结果答题常识题可对商品题不能保证胜率
活动时间:2021-1-27至2021-2-5
2021-01-27 18:28:35 +08:00
活动入口: 京东APP我的-神仙书院
活动地址https://h5.m.jd.com//babelDiy//Zeus//4XjemYYyPScjmGyjej78M6nsjZvj//index.html?babelChannel=ttt9
已支持IOS双京东账号,Node.js支持N个京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
============Quantumultx===============
[task_local]
#京东神仙书院答题
20 * * * * https://gitee.com/lxk0301/jd_scripts/raw/master/jd_immortal_answer.js, tag=京东神仙书院答题, img-url=https://raw.githubusercontent.com/Orz-3/task/master/jd.png, enabled=true
================Loon==============
[Script]
cron "20 * * * *" script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_immortal_answer.js,tag=京东神仙书院答题
===============Surge=================
京东神仙书院答题 = type=cron,cronexp="20 * * * *",wake-system=1,timeout=3600,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_immortal_answer.js
============小火箭=========
京东神仙书院答题 = type=cron,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_immortal_answer.js, cronexpr="20 * * * *", timeout=3600, enable=true
*/
const $ = new Env('京东神仙书院答题');
const notify = $.isNode() ? require('./sendNotify') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
let jdNotify = true;//是否关闭通知false打开通知推送true关闭通知推送
//IOS等用户直接用NobyDa的jd cookie
let cookiesArr = [], cookie = '', message;
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item])
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
} else {
let cookiesData = $.getdata('CookiesJD') || "[]";
cookiesData = jsonParse(cookiesData);
cookiesArr = cookiesData.map(item => item.cookie);
cookiesArr.reverse();
cookiesArr.push(...[$.getdata('CookieJD2'), $.getdata('CookieJD')]);
cookiesArr.reverse();
cookiesArr = cookiesArr.filter(item => item !== "" && item !== null && item !== undefined);
}
const JD_API_HOST = 'https://api.m.jd.com/client.action';
!(async () => {
if (!cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/bean/signIndex.action', {"open-url": "https://bean.m.jd.com/bean/signIndex.action"});
return;
}
// await requireTk()
2021-02-03 01:08:20 +08:00
$.tk = [{"questionId":"1901441674","questionIndex":"1","questionStem":"永乐宫位于山西哪个城市?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbNFBxCgQpCIXLkJ_WAKDLFdSw-A\",\"optionDesc\":\"运城市\"},{\"optionId\":\"Ks0Sx0BXjjgbNFBxCgQpChYv-iBINKeZnfm57Q\",\"optionDesc\":\"大同市\"},{\"optionId\":\"Ks0Sx0BXjjgbNFBxCgQpC0PrO6mXfvErnsQZkw\",\"optionDesc\":\"太原市\"}]","questionToken":"Ks0Sx0BXjjgbNFAjGUwyXaBp4FnRWXz9HV3vlG-r0AbqW0JofD5caaNEQRrh9w29L7dXXyJ1x5jxRzvj8WP7hQBiWb6eYw","correct":"{\"optionId\":\"Ks0Sx0BXjjgbNFBxCgQpCIXLkJ_WAKDLFdSw-A\",\"optionDesc\":\"运城市\"}","create_time":"27/1/2021 04:49:08","update_time":"27/1/2021 04:49:08","status":"1"},{"questionId":"1901441675","questionIndex":"2","questionStem":"永乐宫在什么时期进行了全面搬迁?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbNVBxCgQpCqVtOiEGdgT2rlgu\",\"optionDesc\":\"21世纪初\"},{\"optionId\":\"Ks0Sx0BXjjgbNVBxCgQpCJXg5g8cZbd_NrUF\",\"optionDesc\":\"20世纪五六十年代\"},{\"optionId\":\"Ks0Sx0BXjjgbNVBxCgQpC_dVlhsF1hkxDSRo\",\"optionDesc\":\"20世纪八九十年代\"}]","questionToken":"Ks0Sx0BXjjgbNVAgGUwyXWU5Z3N8SsLmAmlHnWPk8mu4qpLQ5BonaiQ48lq5_oPoCmxj6PygaxpHZfAQ8m0UnMkPoxHQpg","correct":"{\"optionId\":\"Ks0Sx0BXjjgbNVBxCgQpCJXg5g8cZbd_NrUF\",\"optionDesc\":\"20世纪五六十年代\"}","create_time":"27/1/2021 04:37:24","update_time":"27/1/2021 04:37:24","status":"1"},{"questionId":"1901441676","questionIndex":"1","questionStem":"永乐宫建筑群建造于哪个时期?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbNlBxCgQpCija4QWLFHMVZNeuuQ\",\"optionDesc\":\"明清时期\"},{\"optionId\":\"Ks0Sx0BXjjgbNlBxCgQpC-sybUji1HS_1mIxOg\",\"optionDesc\":\"隋唐时期\"},{\"optionId\":\"Ks0Sx0BXjjgbNlBxCgQpCERO6zuvt0b_lDV85g\",\"optionDesc\":\"宋元时期\"}]","questionToken":"Ks0Sx0BXjjgbNlAjGUwyXf6zlVwlZm9N0cMd1yq3R26R0FElCAVxswWUF7k6UqOKDARHvkc8js_CnGq7m9rw9Je3Ye7uwg","correct":"{\"optionId\":\"Ks0Sx0BXjjgbNlBxCgQpCERO6zuvt0b_lDV85g\",\"optionDesc\":\"宋元时期\"}","create_time":"27/1/2021 04:42:38","update_time":"27/1/2021 04:42:38","status":"1"},{"questionId":"1901441677","questionIndex":"2","questionStem":"永乐宫屋顶正脊两侧的怪兽叫?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbN1BxCgQpCLdI9W7sOrVFbyo2_w\",\"optionDesc\":\"鸱吻\"},{\"optionId\":\"Ks0Sx0BXjjgbN1BxCgQpC8bJ8XseaV3o3WvQZw\",\"optionDesc\":\"赑屃\"},{\"optionId\":\"Ks0Sx0BXjjgbN1BxCgQpCiTLo1O3Fskj9ysIVw\",\"optionDesc\":\"狮子\"}]","questionToken":"Ks0Sx0BXjjgbN1AgGUwyWtwFYOBcQhTDcAYij64yM9ULBJ-9xlCSyjOp-oPdSbAyrvbKYUBNbWNYjjmKIgNgO_yoJjPedg","correct":"{\"optionId\":\"Ks0Sx0BXjjgbN1BxCgQpCLdI9W7sOrVFbyo2_w\",\"optionDesc\":\"鸱吻\"}","create_time":"27/1/2021 04:35:45","update_time":"27/1/2021 04:35:45","status":"1"},{"questionId":"1901441678","questionIndex":"2","questionStem":"永乐宫鸱吻的原料是?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbOFBxCgQpCLIiGL-i9xgxxciXKA\",\"optionDesc\":\"琉璃\"},{\"optionId\":\"Ks0Sx0BXjjgbOFBxCgQpChqA80NEftULPnc5pQ\",\"optionDesc\":\"木雕\"},{\"optionId\":\"Ks0Sx0BXjjgbOFBxCgQpCxZRsqUCnaaa1McPtg\",\"optionDesc\":\"金银\"}]","questionToken":"Ks0Sx0BXjjgbOFAgGUwyXaz-RSO4SdlUVwxRDJLcmSKPyxL2yVbqPuCvt5zrMdBYxvzzKQq5firE3VKN-dZIAgFMWXPBhA","correct":"{\"optionId\":\"Ks0Sx0BXjjgbOFBxCgQpCLIiGL-i9xgxxciXKA\",\"optionDesc\":\"琉璃\"}","create_time":"27/1/2021 04:47:23","update_time":"27/1/2021 04:47:23","status":"1"},{"questionId":"1901441679","questionIndex":"4","questionStem":"永乐宫建筑的布局是?","options":"[{\"optionId\":\"Ks0Sx0BXjjgbOVBxCgQpC8_r_0V5j_2iit4\",\"optionDesc\":\"三点布局\"},{\"optionId\":\"Ks0Sx0BXjjgbOVBxCgQpCAtpkpOXFIsGw_Y\",\"optionDesc\":\"中轴线布局\"},{\"optionId\":\"Ks0Sx0BXjjgbOVBxCgQpCnZ3QHwZxxvqbvU\",\"optionDesc\":\"对角线布局\"}]","questionToken":"Ks0Sx0BXjjgbOVAmGUwyWsIJPvpXj3gmQ0NPuTKUw1XdjYI4-a5pl-7g5NfIGYSC54-XuwqBqBzyo4gBnd4MPW08Pslijw","correct":"{\"optionId\":\"Ks0Sx0BXjjgbOVBxCgQpCAtpkpOXFIsGw_Y\",\"optionDesc\":\"中轴线布局\"}","create_time":"27/1/2021 04:36:17","update_time":"27/1/2021 04:36:17","status":"1"},{"questi
for (let i = 0; i < cookiesArr.length; i++) {
if (cookiesArr[i]) {
cookie = cookiesArr[i];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=(.+?);/) && cookie.match(/pt_pin=(.+?);/)[1])
$.index = i + 1;
$.isLogin = true;
$.nickName = '';
message = '';
$.stopAnswer = false;
await TotalBean();
console.log(`\n******开始【京东账号${$.index}${$.nickName || $.UserName}*********\n`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, {"open-url": "https://bean.m.jd.com/bean/signIndex.action"});
if ($.isNode()) {
await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
}
continue
}
await jdImmortalAnswer()
}
}
})()
.catch((e) => {
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
async function jdImmortalAnswer() {
try {
$.risk = false
$.earn = 0
await getHomeData()
if ($.risk) return
if ($.isNode()) {
//一天答题上限是15次
for (let i = 0; i < 15; i++) {
$.log(`\n开始第 ${i + 1}次答题\n`);
await getQuestions()
await $.wait(2000)
if ($.stopAnswer) break
}
} else {
await getQuestions()
}
await showMsg()
} catch (e) {
$.logErr(e)
}
}
function getHomeData(info = false) {
return new Promise((resolve) => {
$.post(taskPostUrl('mcxhd_brandcity_homePage'), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
data = JSON.parse(data);
if (data && data['retCode'] === "200") {
const {userCoinNum} = data.result
if (info) {
$.earn = userCoinNum - $.coin
} else {
console.log(`当前用户金币${userCoinNum}`)
}
$.coin = userCoinNum
} else {
$.risk = true
console.log(`账号被风控,无法参与活动`)
message += `账号被风控,无法参与活动\n`
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
function showMsg() {
return new Promise(resolve => {
message += `本次运行获得${$.earn}积分`
if (!jdNotify) {
$.msg($.name, '', `${message}`);
} else {
$.log(`京东账号${$.index}${$.nickName}\n${message}`);
}
resolve()
})
}
function getQuestions() {
return new Promise((resolve) => {
$.get(taskUrl('mcxhd_brandcity_getQuestions'), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
data = JSON.parse(data);
if (data && data['retCode'] === "200") {
console.log(`答题开启成功`)
let i = 0, questionList = []
for (let vo of data.result.questionList) {
$.question = vo
2021-01-27 13:16:29 +08:00
let option = null, hasFound = false
console.log(`去查询第${++i}题:【${vo.questionStem}`)
2021-01-27 13:16:29 +08:00
let ques = $.tk.filter(qo => qo.questionId === vo.questionId)
if (ques.length) {
ques = ques[0]
let ans = JSON.parse(ques.correct)
let opt = vo.options.filter(bo => bo.optionDesc === ans.optionDesc)
if (opt.length) {
console.log(`在脚本内置题库中找到题啦~`)
2021-01-27 13:16:29 +08:00
option = opt[0]
hasFound = true
} else {
console.log(`在脚本内置题库中 未找到答案,去线上题库寻找~`);
2021-01-29 09:38:36 +08:00
ques = await getQues(vo.questionId)
if (ques) {
let ans = JSON.parse(ques.correct)
let opt = vo.options.filter(bo => bo.optionDesc === ans.optionDesc)
if (opt.length) {
console.log(`在线上题库中找到题啦~`)
option = opt[0]
hasFound = true
}
}
}
}
2021-01-27 13:16:29 +08:00
if (!option) {
2021-01-27 13:16:29 +08:00
console.log(`在题库中未找到题`)
let ans = -1
for (let opt of vo.options) {
let str = vo.questionStem + opt.optionDesc
console.log(`去搜索${str}`)
let res = await bing(str)
if (res > ans) {
option = opt
ans = res
}
await $.wait(2 * 1000)
}
if (!option) {
option = vo.options[1]
console.log(`未找到答案都选B【${option.optionDesc}\n`)
} else {
console.log(`选择搜索返回结果最多的一项【${option.optionDesc}\n`)
}
}
2021-01-27 13:16:29 +08:00
let b = {
"questionToken": vo.questionToken,
"optionId": option.optionId
}
$.option = option
await answer(b)
2021-01-27 13:16:29 +08:00
if (!hasFound) questionList.push($.question)
if (i < data.result.questionList.length) {
if (hasFound)
await $.wait(2 * 1000)
else
await $.wait(5 * 1000)
}
}
for (let vo of questionList) {
$.question = vo
await submitQues({
...$.question,
options: JSON.stringify($.question.options),
correct: JSON.stringify($.question.correct),
})
}
} else if (data && data['retCode'] === '325') {
console.log(`答题开启失败,${data['retMessage']}`);
$.stopAnswer = true;//答题已到上限
} else if (data && data['retCode'] === '326') {
console.log(`答题开启失败,${data['retMessage']}`);
$.stopAnswer = true;//答题已到上限
} else {
console.log(JSON.stringify(data))
console.log(`答题开启失败`)
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
function submitQues(question) {
return new Promise(resolve => {
$.post({
'url': 'http://qa.turinglabs.net:8081/api/v1/question',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify(question),
}, (err, resp, data) => {
try {
data = JSON.parse(data)
if (data.status === 200) {
console.log(`提交成功`)
} else {
console.log(`提交失败`)
}
resolve()
} catch (e) {
console.log(e)
} finally {
resolve()
}
})
})
}
2021-01-29 09:38:36 +08:00
function getQues(questionId) {
return new Promise(resolve => {
$.get({
'url': `http://qa.turinglabs.net:8081/api/v1/question/${questionId}/`,
'headers': {
'Content-Type': 'application/json'
}
}, (err, resp, data) => {
try {
data = JSON.parse(data)
if (data.status === 200) {
resolve(data.data)
} else {
resolve(null)
}
} catch (e) {
console.log(e)
} finally {
resolve()
}
})
})
}
function answer(body = {}) {
return new Promise((resolve) => {
$.get(taskUrl('mcxhd_brandcity_answerQuestion', {"costTime": 1, ...body}), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
data = JSON.parse(data);
// console.log(data)
if (data && data['retCode'] === "200") {
if (data.result.isCorrect) {
console.log(`您选对啦!获得积分${data.result.score},本次答题共计获得${data.result.totalScore}`)
$.earn += parseInt(data.result.score)
$.question = {
...$.question,
correct: $.option
}
} else {
let correct = $.question.options.filter(vo => vo.optionId === data.result.correctOptionId)[0]
console.log(`您选错啦~正确答案是:${correct.optionDesc}`)
$.question = {
...$.question,
correct: correct
}
}
if (data.result.isLastQuestion) {
console.log(`答题完成`)
}
} else {
console.log(`答题失败`)
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
function bing(str) {
return new Promise(resolve => {
$.ckjar = null;
$.get({
url: `https://www.bing.com/search?q=${str}`,
headers: {
'Connection': 'Keep-Alive',
'Accept': 'text/html, application/xhtml+xml, */*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4371.0 Safari/537.36'
}
}, (err, resp, data) => {
try {
let num = parseInt(data.match(/="sb_count">(.*) 条结果<\/span>/)[1].split(',').join(''))
console.log(`找到结果${num}`)
resolve(num)
} catch (e) {
console.log(e)
} finally {
resolve()
}
})
})
}
function taskUrl(function_id, body = {}, function_id2) {
body = {"token": 'jd17919499fb7031e5', ...body}
return {
url: `${JD_API_HOST}?functionId=${function_id}&body=${escape(JSON.stringify(body))}&client=wh5&clientVersion=1.0.0&appid=publicUseApi&t=${new Date().getTime()}&sid=&uuid=&area=&networkType=wifi`,
headers: {
"Cookie": cookie,
'Accept': "application/json, text/plain, */*",
'Accept-Language': 'zh-cn',
"origin": "https://h5.m.jd.com",
"referer": "https://h5.m.jd.com/babelDiy/Zeus/4XjemYYyPScjmGyjej78M6nsjZvj/index.html",
'Content-Type': 'application/x-www-form-urlencoded',
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
}
}
function taskPostUrl(function_id, body = {}, function_id2) {
let url = `${JD_API_HOST}`;
if (function_id2) {
url += `?functionId=${function_id2}`;
}
body = {...body, "token": 'jd17919499fb7031e5'}
return {
url,
body: `functionId=${function_id}&body=${escape(JSON.stringify(body))}&client=wh5&clientVersion=1.0.0&appid=publicUseApi`,
headers: {
"Cookie": cookie,
"origin": "https://h5.m.jd.com",
"referer": "https://h5.m.jd.com/",
'Content-Type': 'application/x-www-form-urlencoded',
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
}
}
function TotalBean() {
return new Promise(async resolve => {
const options = {
"url": `https://wq.jd.com/user/info/QueryJDUserInfo?sceneval=2`,
"headers": {
"Accept": "application/json,text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
if (data) {
data = JSON.parse(data);
if (data['retcode'] === 13) {
$.isLogin = false; //cookie过期
return
}
$.nickName = data['base'].nickname;
} else {
console.log(`京东服务器返回空数据`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
2021-01-27 13:16:29 +08:00
function safeGet(data) {
try {
if (typeof JSON.parse(data) == "object") {
return true;
}
} catch (e) {
console.log(e);
console.log(`京东服务器访问数据为空,请检查自身设备网络情况`);
return false;
}
}
function jsonParse(str) {
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
console.log(e);
$.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie')
return [];
}
}
}
// 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"])