// ==UserScript==
// @name PT时间每日定时签到【脚本猫专用】
// @version 0.1.0
// @description 定时脚本,每日1次,需要先登陆https://www.pttime.org/index.php
// @author shay
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @connect pttime
// @crontab 1-59 once *
// ==/UserScript==
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url: "https://www.pttime.org/attendance.php",
onload: xhr => {
console.log(xhr)
try {
resolve(xhr.responseText.match(/dynamicurl|\/(.+?)|/)[1])
} catch {
let text = "PT时间定时签到成功(我也不知道为啥就成功了)-重复签到"
GM_notification(text)
reject(text)
}
},
onerror: xhr => {
console.log(xhr)
let text = "PT时间定时签到失败-网络错误或重复签到"
GM_notification(text)
reject(text)
}
})
}).then(url => {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url: "https://www.pttime.org" + url + "attendance.php",
onload: xhr => {
console.log(xhr)
let text
if (xhr.responseText.includes("任务已完成")) {
text = "PT时间定时签到成功"
GM_notification(text)
resolve(text)
} else if (xhr.responseText.includes("本期您已申请过此任务")) {
text = "PT时间定时签到失败 - 重复签到"
GM_notification(text)
resolve(text)
} else {
text = "PT时间定时签到失败-未知错误-详见调试"
GM_notification(text)
reject(text)
}
},
onerror: xhr => {
console.log(xhr)
let text = "PT时间定时签到失败-网络错误"
GM_notification(text)
reject(text)
}
})
})
})
上面是具体代码,是以前ptt签到的代码,后来不知道怎么就失效了,然后我自己改了改。每天0点开始运行,也不知道为啥就成功了,但失败后不会再次执行。希望大神能帮忙看看,顺便改善一下代码,使得弹出信息能显示签到后,获得了多少魔力值,还有多少魔力值。谢谢