Skip to content

Commit

Permalink
签到搞定
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Jan 10, 2020
1 parent 956a081 commit be6e845
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions all_in/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const config = {
},
iqiyi: {
cookie: 'CookieQY',
name: '爱奇艺Cookie-App',
name: '爱奇艺',
provider: {
url: 'https://tc.vip.iqiyi.com/taskCenter/task/queryUserTask?autoSign=yes&P00001='
},
Expand Down Expand Up @@ -267,8 +267,7 @@ function sign_baidu_tieba() {
let process = config.baidu_tieba.data;
let checkIsAllProcessed = () => {
if (process.total > process.result.length) return;
let totalNotify = `
${config.baidu_tieba.name}】签到结果`;
let totalNotify = `【${config.baidu_tieba.name}】签到结果`;
for (const res of process.result) {
if (res.errorCode == -1) {
totalNotify += `
Expand All @@ -280,7 +279,7 @@ function sign_baidu_tieba() {
}
record(totalNotify);

process.notify = `[${config.baidu_tieba.name}] 总签到${process.result.length}个,成功${process.result.filter(it=>{return it.errorCode==-1||it.errorCode==0}).length}个,失败${process.result.filter(it=>{return it.errorCode==998||it.errorCode==999}).length}`
process.notify = `${config.baidu_tieba.name} 总签到${process.result.length}个,成功${process.result.filter(it=>{return it.errorCode==-1||it.errorCode==0}).length}个,失败${process.result.filter(it=>{return it.errorCode>=1}).length}`
finalNotify("baidu_tieba");
}
let signBars = (bars, tbs, index) => {
Expand Down Expand Up @@ -399,8 +398,8 @@ function sign_iqiyi() {
record(config.iqiyi.data.notify)
} else {
// console.log("failure response: \n" + response.body);
config.iqiyi.data.notify = `【${config.iqiyi.name}签到失败⚠️`;
record(`${config.iqiyi.data.notify}${obj.data.signInfo.msg}}`);
config.iqiyi.data.notify = `【${config.iqiyi.name}${obj.data.signInfo.msg}⚠️`;
record(`${config.iqiyi.data.notify}${obj.data.signInfo.msg}`);
}
} else {
config.iqiyi.data.notify = `【${config.iqiyi.name}】签到失败⚠️`;
Expand All @@ -425,46 +424,53 @@ function sign_netease_music() {
}
let cookieVal = $prefs.valueForKey(config.netease_music.cookie);
if (!cookieVal) {
global.netease_music.data.notify = `【${config.netease_music.name}】未获取到Cookie`;
record(global.netease_music.data.notify);
config.netease_music.data.notify = `【${config.netease_music.name}】未获取到Cookie`;
record(config.netease_music.data.notify);
finalNotify('netease_music');
return;
}
let sign = (url, type) => {
$task.fetch(url).then(response => {
let sign = (type) => {
record(`网易云-sign-${type}`)
config.netease_music.provider[type].headers.Cookie = cookieVal;
$task.fetch(config.netease_music.provider[type]).then(response => {
let result = JSON.parse(response.body);
combain(result, type);
}, reason => {
var signInfo = {};
signInfo.resultCode = 999;
signInfo.code = 999;
signInfo.msg = reason.error;
combain(signInfo, type);
});
}
let combain = (result, type) => {
if (result.code == 200) {
//success
config.netease_music.data[type] = '签到成功';
} else if (result.code == -2) {
//signed
config.netease_music.data[type] = '重复签到';
} else {
//failed
config.netease_music.data[type] = '未知错误';
record(`网易云-combain-${type}-${JSON.stringify(result)}`)
try {
if (result.code == 200) {
//success
config.netease_music.data[type] = '签到成功';
} else if (result.code == -2) {
//signed
config.netease_music.data[type] = '重复签到';
} else {
//failed
config.netease_music.data[type] = '未知错误';
}
checkIsAllProcessed();
} catch (e) {
record(`网易云报错-${JSON.stringify(e)}`);
}
checkIsAllProcessed();

}
let checkIsAllProcessed = () => {
record(`网易云-check-${config.netease_music.data.pc}-${config.netease_music.data.app}`)
if (config.netease_music.data.pc && config.netease_music.data.app) {
config.netease_music.data.notify = `【${config.netease_music.name}】 APP端-${config.netease_music.data.app} PC端-${config.netease_music.data.pc}`;
finalNotify('iqiyi');
finalNotify('netease_music');
}
}

config.netease_music.provider.app.headers.Cookie = cookieVal;
config.netease_music.provider.pc.headers.Cookie = cookieVal;
sign(config.netease_music.provider.app, 'app');
sign(config.netease_music.provider.pc, 'pc');
sign('app');
sign('pc');
}

//#endregion
Expand Down Expand Up @@ -529,6 +535,7 @@ function sign_v2ex() {
let data = response.body;
if (data.indexOf('每日登录奖励已领取') >= 0) {
config.v2ex.data.notify = `【${config.v2ex.name}】重复签到🎉`
record(config.v2ex.data.notify);
finalNotify("v2ex");
} else {
let regex = /<input[^>]*\/mission\/daily\/redeem\?once=(\d+)[^>]*>/g;
Expand All @@ -545,10 +552,11 @@ function sign_v2ex() {
let signMission = code => {
config.v2ex.provider.sign.headers.Cookie = cookieVal;
config.v2ex.provider.sign.url = `https://www.v2ex.com/mission/daily/redeem?once=${code}`;
$task.fetch(url).then(response => {
$task.fetch(config.v2ex.provider.sign).then(response => {
let data = response.body;
if (data.indexOf('每日登录奖励已领取') >= 0) {
config.v2ex.data.notify = `【${config.v2ex.name}】签到成功🎉`
record(config.v2ex.data.notify);
finalNotify("v2ex");
} else {
config.v2ex.data.notify = `【${config.v2ex.name}】签到失败⚠️`
Expand Down Expand Up @@ -590,19 +598,23 @@ function finalNotify(type) {
`;
if (isAllProcessed) {
for (var item in global.sign) {
if (global[item]) {
sign_detail += `${sign_detail||breakLine}${config[item].data.notify}`;
// record(`提醒消息-${item}-${global.sign[item]}`)
if (global.sign[item]) {
// record(`提醒消息-${config[item].data.notify}`)
sign_detail += `${sign_detail?breakLine:''}${config[item].data.notify}`;
}
}
$notify("All In One", "详细签到信息可见日志", sign_detail);
}
$notify("All In One", "详细签到信息可见日志", sign_detail);
}

function record(content) {
if (global.log == 1) {
console.log(content);
console.log(`
${content}`);
} else if (global.log == 2) {
console.log(content.splice(0, 60));
console.log(`
${content.splice(0, 60)}`);
}
}

Expand Down

0 comments on commit be6e845

Please sign in to comment.