hdsay自动获取金币
// ==UserScript==
// @name hdsay自动获取金币
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.1
// @description 实现了hdsay高清乐园自动签到和每日访问,每天可以获得10金币。
// @author 冷山哥哥
// @background
// @connect www.showki.net
// @grant GM_log
// @grant GM_cookie
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_getValue
// @crontab * * once * *
// ==/UserScript==
return new Promise(async (resolve, reject) => {
async function login(user, pass) {
function gotoLogin() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: "https://www.showki.net/account/loginsubmit",
method: "POST",
headers: {
"Content-Type": "application/json",
},
data: JSON.stringify({
OriginalUrl: "https://www.showki.net/",
RememberMe: "false",
UsernameOrEmailAddress: user,
Password: pass,
}),
onload: function (data) {
if (data.status == 200) {
const result = JSON.parse(data.response);
if (result.result == null) {
GM_log("hdsay用户" + user + "登录成功");
resolve(true);
return;
} else {
GM_log("hdsay用户名或者密码错误");
GM_notification("hdsay用户名或者密码错误")
}
} else if (data.status == 500) {
GM_log("hdsay服务器后端错误,重新请求");
}
reject();
},
onerror: function (error) {
reject();
},
});
});
}
function gotoMain() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: "https://www.showki.net",
method: "GET",
onload: function (data) {
resolve(true);
},
onerror: function (error) {
reject();
},
});
});
}
try {
await gotoLogin();
await gotoMain();
} catch (error) {
return false;
}
return true;
}
async function getToken() {
return new Promise((resolve) => {
GM_cookie("list", { domain: "www.showki.net" }, (cookie, err) => {
for (let index = 0; index < cookie.length; index++) {
const item = cookie[index];
if (item.name === "XSRF-TOKEN") {
resolve(item.value);
return;
}
}
reject();
return;
});
});
}
async function delCookie() {
return new Promise((resolve) => {
GM_cookie("list", { domain: "www.showki.net" }, (cookie, err) => {
for (let index = 0; index < cookie.length; index++) {
const item = cookie[index];
GM_cookie("delete", {
url: "https://www.showki.net",
name: item.name
});
}
});
resolve(true)
});
}
async function sign(token, id) {
return new Promise((resolve) => {
GM_xmlhttpRequest(
{
url: "https://www.showki.net/api/services/app/ForumMemberSign/Create",
method: "Post",
headers: {
"Content-Type": "application/json",
"X-Xsrf-Token": token
},
data: JSON.stringify({
"isActive": true, "creatorUserName": null, "creationTime": new Date(),
"lastModifierUserName": null, "lastModificationTime": null, "moodName": "开心",
"inputModeName": "自己填写", "userId": id, "mood": 2,
"moodWords": "日出而作兮日入归,如彼草木兮雨露肥。",
"inputMode": "2", "description": null,
"version": 0,
"id": "00000000-0000-0000-0000-000000000000",
"__RequestVerificationToken": token
}),
onload: function (res) {
if (res.status == 200) {
data = JSON.parse(res.response)
GM_log("签到成功")
resolve("签到成功")
} else if (res.status == 500) {
GM_log("已经签到")
resolve("已经签到")
}
},
onerror: function (err) {
resolve("签到请求错误")
}
}
)
})
}
//获取个人信息
async function getDetails() {
return new Promise((resolve) => {
const t = new Date().getTime()
GM_xmlhttpRequest({
url: "https://www.showki.net/api/services/app/ForumMemberInfo/GetMemberSumView?_" + t,
method: "Get",
headers: {
"Content-Type": "application/json",
},
onload: function (res) {
if (res.status == 200) {
const data = JSON.parse(res.response)
resolve(data.result)
}
}
})
})
}
//完成每日访问任务
async function gotoView() {
return new Promise((resolve) => {
const t = new Date().getTime()
GM_xmlhttpRequest({
url: "https://www.showki.net/api/services/app/ForumGlobal/GetGlobalData?_=" + t,
method: "Get",
onload: function (res) {
if (res.status == 200) {
resolve(true)
} else {
resolve(false)
}
},
onerror: function (err) {
resolve(false)
}
})
})
}
async function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function main() {
// 通过GM_info新方法获取UserConfig对象
const rawUserConfig = GM_info.userConfig;
// 定义一个对象暂存读取到的UserConfig值
const userConfig = {};
// 解构遍历读取UserConfig并赋缺省值
Object.entries(rawUserConfig).forEach(([mainKey, configs]) => {
Object.entries(configs).forEach(([subKey, { default: defaultValue }]) => {
userConfig[`${mainKey}.${subKey}`] = GM_getValue(`${mainKey}.${subKey}`, defaultValue)
})
})
username=userConfig["账号密码.username"]
password=userConfig["账号密码.password"]
//删除cookie
const result = await delCookie()
if (result) {
GM_log("清除cookie成功了")
}
await sleep(1)
//登录获取token
const loginResult = await login(username, password);
const token = await getToken();
//获取个人信息,用户id,当前金币数量;完成每日访问任务
const user = await getDetails()
//开始签到请求
const signResult = await sign(token, user.id)
const view = await gotoView();
if (view) {
GM_log("每日访问任务完成成功")
} else {
GM_log("每日访问任务完成失败")
}
const detial = await getDetails()
if (signResult === "签到成功") {
GM_notification("hdsay任务成功,目前金币数量:" + detial.gold)
} else if (signResult === "已经签到") {
GM_notification("hdsay任务成功,目前金币数量:" + detial.gold)
} else if (signResult === "签到请求错误") {
GM_notification("hdsay任务完成失败")
}
}
main()
.catch((err) => {
console.log(err);
})
.finally(() => {
resolve("hdsay签到脚本运行完毕");
});
});
/* ==UserConfig==
账号密码:
username:
title: 用户名
type: textarea
default: 欢迎使用脚本猫,请在此输入你的用户名,此输入框只保留你的用户名
password:
title: 密码
type: textarea
default: 欢迎使用脚本猫,请在此输入你的密码,此输入框只保留你的密码
==/UserConfig== */