This commit is contained in:
wisz2021
2021-05-11 14:45:59 +08:00
parent af61bde228
commit fa18faaa57

View File

@@ -38,10 +38,9 @@ if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => { Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item]) cookiesArr.push(jdCookieNode[item])
}) })
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
}; if (JSON.stringify(process.env).indexOf('GITHUB') > -1) process.exit(0)
if(JSON.stringify(process.env).indexOf('GITHUB')>-1) process.exit(0) } else {
}else {
cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
} }
const JD_API_HOST = 'https://api.m.jd.com/api'; const JD_API_HOST = 'https://api.m.jd.com/api';
@@ -55,17 +54,17 @@ const JD_API_HOST = 'https://api.m.jd.com/api';
let nowTs = new Date().getTime() let nowTs = new Date().getTime()
if (!($.st <= nowTs && nowTs < $.ed)) { if (!($.st <= nowTs && nowTs < $.ed)) {
$.log(`\n远程红包雨配置获取错误,从本地读取配置`) $.log(`\n远程红包雨配置获取错误,尝试从本地读取配置`)
let hour = (new Date().getUTCHours() + 8) %24 let hour = (new Date().getUTCHours() + 8) % 24
if (ids[hour]){ if (ids[hour]) {
$.activityId = ids[hour] $.activityId = ids[hour]
$.log(`本地红包雨配置获取成功ID为${$.activityId}\n`) $.log(`本地红包雨配置获取成功ID为${$.activityId}\n`)
} else{ } else {
$.log(`无法从本地读取配置,请检查运行时间(注:非红包雨时间执行出现此提示请忽略!!!!!!!!!!!)`) $.log(`无法从本地读取配置,请检查运行时间(注:非红包雨时间执行出现此提示请忽略!!!!!!!!!!!)`)
$.log(`非红包雨期间出现上面提示请忽略。红包雨期间会正常此脚本提issue打死)`) $.log(`非红包雨期间出现上面提示请忽略。红包雨期间会正常此脚本提issue打死)`)
return return
} }
} else{ } else {
$.log(`远程红包雨配置获取成功`) $.log(`远程红包雨配置获取成功`)
} }
for (let i = 0; i < cookiesArr.length; i++) { for (let i = 0; i < cookiesArr.length; i++) {
@@ -97,12 +96,12 @@ const JD_API_HOST = 'https://api.m.jd.com/api';
$.msg($.name, '', allMessage); $.msg($.name, '', allMessage);
} }
})() })()
.catch((e) => { .catch((e) => {
$.log('', `${$.name}, 失败! 原因: ${e}!`, '') $.log('', `${$.name}, 失败! 原因: ${e}!`, '')
}) })
.finally(() => { .finally(() => {
$.done(); $.done();
}) })
function showMsg() { function showMsg() {
return new Promise(resolve => { return new Promise(resolve => {
@@ -113,9 +112,9 @@ function showMsg() {
function getRedRain() { function getRedRain() {
let body let body
if(bodyList.hasOwnProperty(new Date().getDate())) { if (bodyList.hasOwnProperty(new Date().getDate())) {
body = bodyList[new Date().getDate()] body = bodyList[new Date().getDate()]
}else{ } else {
return return
} }
return new Promise(resolve => { return new Promise(resolve => {
@@ -128,9 +127,8 @@ function getRedRain() {
if (safeGet(data)) { if (safeGet(data)) {
data = JSON.parse(data); data = JSON.parse(data);
if (data.data && data.data.iconArea) { if (data.data && data.data.iconArea) {
console.log(data.data.iconArea.filter(vo=>vo['type']==='anchor_darw_lottery').length && // console.log(data.data.iconArea.filter(vo => vo['type'] === 'anchor_darw_lottery').length && data.data.iconArea.filter(vo => vo['type'] === 'anchor_darw_lottery')[0].data.lotteryId)
data.data.iconArea.filter(vo=>vo['type']==='anchor_darw_lottery')[0].data.lotteryId) let act = data.data.iconArea.filter(vo => vo['type'] === "platform_red_packege_rain")[0]
let act = data.data.iconArea.filter(vo=>vo['type']==="platform_red_packege_rain")[0]
if (act) { if (act) {
let url = act.data.activityUrl let url = act.data.activityUrl
$.activityId = url.substr(url.indexOf("id=") + 3) $.activityId = url.substr(url.indexOf("id=") + 3)
@@ -141,10 +139,10 @@ function getRedRain() {
console.log(`下一场红包雨开始时间:${new Date($.st)}`) console.log(`下一场红包雨开始时间:${new Date($.st)}`)
console.log(`下一场红包雨结束时间:${new Date($.ed)}`) console.log(`下一场红包雨结束时间:${new Date($.ed)}`)
} else { } else {
console.log(`暂无红包雨`) console.log(`\n暂无超级直播间红包雨`)
} }
} else { } else {
console.log(`暂无红包雨`) console.log(`\n暂无超级直播间红包雨`)
} }
} }
} }
@@ -189,10 +187,11 @@ function receiveRedRain() {
}) })
}) })
} }
function taskGetUrl(url, body) { function taskGetUrl(url, body) {
return { return {
url: url, url: url,
body:body, body: body,
headers: { headers: {
"Accept": "*/*", "Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br", "Accept-Encoding": "gzip, deflate, br",