Skip to content

Instantly share code, notes, and snippets.

@lyc8503
Last active November 3, 2023 10:28
Show Gist options
  • Save lyc8503/9f6f3e8ac0229a070e246ba8a6a65746 to your computer and use it in GitHub Desktop.
Save lyc8503/9f6f3e8ac0229a070e246ba8a6a65746 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 签到脚本lite
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 自动签到插件
// @author lyc8503
// @match *
// @connect *
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @run-at document-start
// ==/UserScript==
(async function() {
'use strict';
async function doSign() {
GM_notification({
text: "请暂时不要关闭当前标签页",
title: "签到脚本开始运行"
})
// 辅助请求函数
function request(data) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
...data,
onload: function(response) {
console.log("[DEBUG] request ok: " + data.url + ", " + response.responseText)
resolve(response);
},
onerror: function(error) {
reject(error);
}
})
})
}
// 签到脚本主体
const signTargets = {
"晋江": async () => {
let res = (await request({
method: "GET",
url: "https://my.jjwxc.net/backend/signin.php?action=signIn"
})).responseText
if (res.includes("login.php")) throw "未登陆"
if (res === "70003") throw "重复签到"
try {
return JSON.parse(res).message
} catch(err) {
throw res
}
},
"猫耳": async () => {
let res = await request({
method: "GET",
url: "https://www.missevan.com/member/getcatears"
})
if (res.finalUrl.includes("login")) throw "未登陆"
res = JSON.parse(res.responseText)
if (!res.success) throw res.info
return res.info.message
},
"Bilibili": async () => {
let res = JSON.parse((await request({
method: "GET",
url: "https://api.live.bilibili.com/sign/doSign"
})).responseText)
if (res.code != 0) throw res.message
return res.data.text
},
"V2EX": async () => {
let res = (await request({
method: "GET",
url: "https://www.v2ex.com/mission/daily"
})).responseText
if (res.includes("你要查看的页面需要先登录")) throw "需要登录"
if (res.includes("每日登录奖励已领取")) throw "每日登录奖励已领取"
const once = res.match(/\/mission\/daily\/redeem\?once=(\d*)/)
if (once === null) throw "未匹配到签到链接"
res = (await request({
method: "GET",
url: "https://www.v2ex.com/mission/daily/redeem?once=" + once[1]
})).responseText
if (res.includes("已成功领取每日登录奖励")) return "签到成功"
throw "未知错误"
},
"52pojie": async () => {
let res = (await request({
method: "GET",
url: "https://www.52pojie.cn/"
})).responseText
if (res.includes("自动登录")) throw "需要登录"
if (res.includes("wbs.png")) throw "已经签到"
const tab = await GM_openInTab("https://www.52pojie.cn/home.php?mod=task&do=apply&id=2&referer=%2F")
let success = false
for (let i = 0; i < 5; i++) {
await new Promise((resolve) => setTimeout(resolve, 2000));
if ((await request({
method: "GET",
url: "https://www.52pojie.cn/"
})).responseText.includes("wbs.png")) {
success = true
break
}
}
tab.close()
if (success) {
return "签到成功"
} else {
throw "签到失败, 签到状态未改变"
}
}
}
let notificationText = ""
let successCounter = 0
let failureCounter = 0
for (let site of Object.keys(signTargets)) {
console.log(site)
try {
let result = await signTargets[site]()
console.log(site + " 签到成功: " + JSON.stringify(result))
notificationText += "✔️" + site + "签到成功: " + JSON.stringify(result) + "\n"
successCounter += 1
} catch(err) {
console.log(">>> " + site + "签到出错")
console.log(err)
notificationText += "❌" + site + "签到失败: " + JSON.stringify(err) + "\n"
failureCounter += 1
}
}
notificationText = "💬签到情况摘要: 成功 " + successCounter + "/" + (successCounter + failureCounter) + "\n" + notificationText
GM_notification({
text: notificationText,
title: "今日签到情况",
onclick: () => alert(notificationText)
})
}
GM_registerMenuCommand("手动运行签到", function(event) {
GM_setValue("last_sign", currentDate)
doSign();
});
const currentDate = new Date().toLocaleDateString()
const lastSignDate = GM_getValue("last_sign")
// 部分网站签到不是按照晚上 0 点计算新的一天
const skip = currentDate === lastSignDate || new Date().getHours() < 8
console.log("签到脚本: 上次运行时间 " + lastSignDate + ", 当前时间 " + currentDate + (skip ? " >>> 跳过签到操作": ""))
if (skip) {
return
}
GM_setValue("last_sign", currentDate)
doSign();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment