Glados机场每日签到
// ==UserScript==
// @name Glados机场每日签到
// @namespace https://bbs.tampermonkey.net.cn/
// @version 1.0.3
// @description 每天glados机场自动签到领流量,必须使用脚本猫,请勿使用油猴
// @author Chasays
// @match https://docs.scriptcat.org/dev/background.html#promise
// @icon https://glados.rocks/favicon.ico
// @crontab * * once * *
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_notification
// @connect glados.rocks
// @license GNU GPLv3
// ==/UserScript==
return new Promise((resolve, reject) => {
let i = 0;
let j = 0;
GM_xmlhttpRequest({
method: "GET",
url: "https://glados.rocks/api/user/status",
onload: (xhr) => {
if (xhr.code == -2) {
GM_notification({
title: "Glados未登录!",
text: xhr.message,
onclick: (id) => {
GM_openInTab("https://glados.rocks/login");
GM_closeNotification(id);
},
timeout: 10000,
});
clearInterval(scan);
reject("未登录");
}
},
});
function main() {
setTimeout(() => {
GM_xmlhttpRequest({
method: "POST",
url: "https://glados.rocks/api/user/checkin",
responseType: "json",
timeout: 5000,
data: JSON.stringify({"token": "glados.network"}),
headers : {'authorization': "please replace your-key",
'origin': 'https://glados.rocks',
'content-type': 'application/json;charset=UTF-8',
},
onload: (xhr) => {
let msg = xhr.response.message;
if (xhr.status == 200) {
if (xhr.code != 0) {
GM_log(xhr.message,'error');
} else {
clearInterval(scan);
resolve(msg);
GM_log(msg,'info');
}
} else {
GM_log("请求失败,再试一次。", "info");
++i;
main();
}
},
ontimeout: () => {
GM_log("请求超时,再试一次。", "info");
++i;
main();
},
onabort: () => {
GM_log("请求终止,再试一次。", "info");
++i;
main();
},
onerror: () => {
GM_log("请求错误,再试一次。", "info");
++i;
main();
},
});
}, 1000 + Math.random() * 4000);
}
let scan = setInterval(() => {
++j;
if (i >= 7) {
GM_notification({
title: "出错超过七次,已退出脚本。",
text: "请检查问题并重新运行脚本。",
});
clearInterval(scan);
reject("出错超过七次,已退出脚本。");
} else if (j >= 32) {
reject("脚本运行超时");
}
}, 3000);
main();
});