hostloc自动签到【脚本猫专用】
// ==UserScript==
// @name hostloc自动签到【脚本猫专用】
// @namespace https://bbs.tampermonkey.net.cn/
// @description 支持检测是否登录和PushCat消息推送
// @version 1.1.1-beta
// @author Qixing
// @crontab * * once * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_updateNotification
// @grant GM_openInTab
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_log
// @grant GM_cookie
// @connect hostloc.com
// @homepage https://scriptcat.org/zh-CN/script-show-page/1365/
// @supportURL https://t.me/qixing_chat
// @require https://scriptcat.org/lib/946/%5E1.0.1/PushCat.js
// @exportValue PushCat.AccessKey
// @background
// ==/UserScript==
/* ==UserConfig==
Config:
signInInterval:
title: 每次访问空间间隔
description: 单位为ms,如5000则为每5秒访问一次
default: 5000
type: number
min: 1000
signInTimes:
title: 访问空间总次数
description: 理论只需要10次就够了,但为了避免无效,建议多一点
default: 12
type: number
min: 10
PushCat:
AccessKey:
title: 消息推送key
description: 消息推送key https://sct.icodef.com/
type: text
==/UserConfig== */
// 参考自 https://scriptcat.org/scripts/code/1060/必应积分商城每日签到.user.js
// 用户配置类
let accessKey = GM_getValue("PushCat.AccessKey");
if (accessKey == "") {
// 由于脚本猫v0.13的UserConfig有bug,如果你需要消息推送服务的话,请在此手动设置
GM_setValue("PushCat.AccessKey", "");
accessKey = GM_getValue("PushCat.AccessKey");
}
// 消息推送: https://sct.icodef.com/
const push = new PushCat({
accessKey,
});
const signInInterval = GM_getValue("Config.signInInterval");
const signInTimes = GM_getValue("Config.signInTimes");
// 网站类
const WEBSITE_NAME = 'HOSTLoc '
const WEBSITE_PROTOCOL = 'https://'
const WEBSITE_DOMAIN = 'hostloc.com'
const SCRIPT_NAME = WEBSITE_NAME + '自动签到【脚本猫专用】'
// Message类
const NO_LOGIN = '未登录'
const NO_SIGNIN_TIME = '没到签到时间'
// 存储值类
const LAST_SIGNIN_TIME_VALUE = 'lastSignInTime'
const LAST_SIGNIN_STATUS_VALUE = 'lastSignInStatus'
function pushSend(content, title = SCRIPT_NAME) {
GM_log("推送消息", "info", { title, content });
return new Promise(async (resolve, reject) => {
if (accessKey) {
await push.send(title, content);
}
let notificationDetail = {
title: title,
text: WEBSITE_NAME + content,
}
if (content === NO_LOGIN) {
notificationDetail['buttons'] = [{
title: '点我去登录!'
}]
notificationDetail['onclick'] = (event) => {
GM_openInTab(WEBSITE_PROTOCOL + WEBSITE_DOMAIN + '/member.php?mod=logging&action=login')
}
// } else if (content === NO_SIGNIN_TIME) {
// notificationDetail['buttons'] = [{
// title: '我就要签到!'
// }]
// notificationDetail['onclick'] = async (event) => {
// // todo:修复代码执行异常结束的问题
// GM_deleteValue(LAST_SIGNIN_TIME_VALUE)
// await autoSignIn()
// }
}
console.log(notificationDetail)
GM_notification(notificationDetail)
resolve()
})
}
function notification(status, message, resolve, reject) {
console.log(arguments.callee.name, status, message, resolve, reject)
pushSend(message);
message = WEBSITE_NAME + message
if (status) {
resolve(message);
} else {
reject(message);
}
}
function checkLogin() {
return new Promise((resolve, reject) => {
GM_cookie("list", {
domain: WEBSITE_DOMAIN
}, (cookies) => {
if (!cookies.some(obj => obj.name === "hkCM_2132_auth")) {
reject(NO_LOGIN);
} else {
resolve('已登录')
}
});
})
}
function checkIfSignInTime() {
return new Promise((resolve, reject) => {
let timeNow = new Date().getFullYear() + "/" + (new Date().getMonth() + 1) + "/" + new Date().getDate(),
timeOld = GM_getValue(LAST_SIGNIN_TIME_VALUE);
if (!timeOld || timeOld != timeNow) { // 是新的一天
GM_setValue(LAST_SIGNIN_TIME_VALUE, timeNow); // 写入签到时间以供后续比较
resolve('是签到时间')
} else {
if (GM_getValue(LAST_SIGNIN_STATUS_VALUE)) {
reject(NO_SIGNIN_TIME)
} else {
notification(true, '上次签到失败,尝试补签', resolve, reject);
}
}
})
}
function signInProgress() {
return new Promise((resolve, reject) => {
try {
GM_notification({
title: SCRIPT_NAME,
text: '愿签到一切顺利🙏',
// 开启进度条模式
progress: 0,
oncreate: (id) => {
let url_list = [],
signInTime = 0;
for (let i = 0; i < signInTimes; i++) { url_list[i] = WEBSITE_PROTOCOL + WEBSITE_DOMAIN + "/space-uid-" + Math.floor(Math.random() * (50000 - 10000 + 1) + 10000) + ".html"; }
let signIn = setInterval(function () {
GM_xmlhttpRequest({
url: url_list[signInTime++],
method: 'GET',
timeout: 4000
});
console.log(`积分 +2 (${url_list[signInTime]})`)
GM_updateNotification(id, {
title: WEBSITE_NAME + '签到进度',
progress: Math.floor(signInTime / signInTimes * 100)
})
if (signInTime === signInTimes - 1) { // 次数够了就取消定时循环
clearInterval(signIn)
GM_updateNotification(id, {
title: WEBSITE_NAME + '签到完成!',
progress: 100
})
console.log('签到完成!')
GM_setValue(LAST_SIGNIN_STATUS_VALUE, true)
notification(true, '签到完成!积分 +22 ~', resolve, reject);
}
}, signInInterval);
}
})
} catch (error) {
console.log(error)
GM_setValue(LAST_SIGNIN_STATUS_VALUE, false)
reject(error)
}
})
}
// 参考自 https://greasyfork.org/zh-CN/scripts/414005-%E5%85%A8%E7%90%83%E4%B8%BB%E6%9C%BA%E4%BA%A4%E6%B5%81%E8%AE%BA%E5%9D%9B%E5%A2%9E%E5%BC%BA
// 自动签到(访问空间 10 次 = 20 积分 + 当天首次访问论坛 2 积分)
function autoSignIn() {
return new Promise(async (resolve, reject) => {
try {
console.log(await Promise.all([checkLogin(), checkIfSignInTime()]))
resolve(await signInProgress())
} catch (error) {
// 处理异常
console.log(arguments.callee.name, error);
notification(false, error, resolve, reject);
}
})
}
return new Promise(async (resolve, reject) => {
try {
resolve(await autoSignIn())
} catch (error) {
// 处理异常
console.log(arguments.callee.name + error);
reject(error)
}
})