油猴bbs签到脚本
// ==UserScript==
// @name 油猴bbs签到脚本
// @namespace tanyu
// @version 1.0.0
// @author tanyu
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @crontab * * once * *
// @description 油猴bbs签到脚本
// ==/UserScript==
function getHash() {
return new Promise((resolve, reject) => {
var options = {
url: "https://bbs.tampermonkey.net.cn/dsu_paulsign-sign.html",
onload: function (response) {
const xmlText = response.responseText;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, "text/html");
resolve(
xmlDoc.querySelectorAll(".comiis_user_info a")[2].href.split("=")[3]
);
},
onerror: function (error) {
console.error("GM_xmlhttpRequest failed:", error);
},
};
GM_xmlhttpRequest(options);
});
}
async function task1() {
let formhash = await getHash();
return new Promise((resolve, reject) => {
var options = {
method: "POST",
url: "https://bbs.tampermonkey.net.cn/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1&inajax=1",
headers: {
"content-type": "application/x-www-form-urlencoded",
},
data:
"formhash=" +
formhash +
"&qdxq=kx&qdmode=1&todaysay=签到签到&fastreply=0",
onload: function (response) {
const xmlText = response.responseText;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, "text/xml");
const cdataContent =
xmlDoc.getElementsByTagName("root")[0].childNodes[0].nodeValue;
// console.log(cdataContent)
const regex = /<div class="c">(.*?)<\/div>/s;
const match = cdataContent.match(regex);
if (match) {
GM_notification({
title: "签到",
text: match[1].trim(),
});
resolve("task1"); // 执行成功
} else {
console.log("No match found");
}
},
onerror: function (error) {
console.error("GM_xmlhttpRequest failed:", error);
},
};
GM_xmlhttpRequest(options);
});
}
return new Promise((resolve, reject) => {
return Promise.all([task1()]).then((res) => {
console.log("完成", res);
resolve(res);
});
});