安装油猴插件
首页 | Tampermonkey
复制添加下面的脚本
// ==UserScript==
// @name 自动订场-羽毛球
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 东校园自动订场
// @author xy3
// @match https://gym.sysu.edu.cn/*
// @grant none
// ==/UserScript==
(function () {
"use strict";
function load_js(url) {
let script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.src = url;
document.documentElement.appendChild(script);
}
// 加载Layer.js
load_js(
"https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/layer/3.5.1/layer.js"
);
// 加载抢场脚本
load_js("https://blog.skyw.cc/tools/gym.js");
// 创建浮动窗口
const floatingWindow = document.createElement("div");
floatingWindow.style.position = "fixed";
floatingWindow.style.bottom = "20px";
floatingWindow.style.right = "20px";
floatingWindow.style.zIndex = "1000";
floatingWindow.innerHTML = `
<button id="configButton">配置</button>
<button id="monitorButton">开始监控</button>
<style>
#configButton, #monitorButton {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 12px;
transition: background-color 0.3s ease;
}
#configButton:hover, #monitorButton:hover {
background-color: #45a049;
}
</style>
`;
document.body.appendChild(floatingWindow);
// 从localStorage获取配置
const getConfig = (key, defaultValue) => {
const value = localStorage.getItem(key);
return value ? value.split(",") : defaultValue;
};
let priority = getConfig("priority", [
"3",
"8",
"2",
"7",
"4",
"9",
"1",
"6",
"5",
"10",
]);
let time1 = getConfig("time1", ["16:01-17:00", "17:01-18:00"]);
let time2 = getConfig("time2", ["19:01-20:00", "20:01-21:00"]);
// 设置配置
const setConfig = (key, value) => {
localStorage.setItem(key, value.join(","));
};
// 显示配置弹窗
const showConfigDialog = () => {
const dateType = localStorage.getItem("dateType") || "0"; // 默认值为0(明天)
const configHtml = `
<div style="padding: 20px;">
<div>
<label>场地优先级 (逗号分隔):</label><br>
<input type="text" id="priorityInput" value="${priority.join(
","
)}" style="width: 100%;"><br>
</div>
<div>
<label>期望时间段 1 (最多两个, 逗号分隔):</label><br>
<input type="text" id="time1Input" value="${time1.join(
","
)}" style="width: 100%;"><br>
</div>
<div>
<label>期望时间段 2 (最多两个, 逗号分隔):</label><br>
<input type="text" id="time2Input" value="${time2.join(
","
)}" style="width: 100%;"><br>
</div>
<div>
<label>选择日期:</label><br>
<select id="dateTypeSelect" style="width: 100%;">
<option value="0" ${dateType === "0" ? "selected" : ""}>明天</option>
<option value="1" ${dateType === "1" ? "selected" : ""}>后天</option>
</select><br>
</div>
<button id="saveConfigButton" style="margin-top: 10px;">保存</button>
</div>
`;
layer.open({
type: 1,
title: "配置设置",
area: ["400px", "300px"],
content: configHtml,
});
document
.getElementById("saveConfigButton")
.addEventListener("click", function () {
// 保存配置到localStorage
priority = document.getElementById("priorityInput").value.split(",");
time1 = document.getElementById("time1Input").value.split(",");
time2 = document.getElementById("time2Input").value.split(",");
const dateType = document.getElementById("dateTypeSelect").value;
setConfig("priority", priority);
setConfig("time1", time1);
setConfig("time2", time2);
localStorage.setItem("dateType", dateType);
layer.closeAll();
layer.msg("配置已保存!");
});
};
// 添加事件监听器到配置按钮
document
.getElementById("configButton")
.addEventListener("click", showConfigDialog);
// 监控功能的变量和函数
let monitoring = false;
let monitorInterval;
const toggleMonitoring = () => {
monitoring = !monitoring;
document.getElementById("monitorButton").textContent = monitoring
? "暂停监控"
: "开始监控";
if (monitoring) {
startMonitoring();
} else {
stopMonitoring();
}
};
const startMonitoring = () => {
const monitorInterval = setInterval(() => {
const now = new Date();
const currentHour = now.getHours();
const currentMinute = now.getMinutes();
const currentSecond = now.getSeconds();
const dateType = localStorage.getItem("dateType") || "0"; // 从localStorage获取日期类型
if (currentHour >= 0 && currentHour < 2) {
console.log(
`当前时间是:${now.toLocaleDateString()} ${currentHour}点${currentMinute}分${currentSecond}秒,开始预定`
);
book(time1, time2, priority, parseInt(dateType)); // 使用用户选择的日期类型
clearInterval(monitorInterval); // 预定后停止循环
} else {
console.log(
`当前时间是:${now.toLocaleDateString()} ${currentHour}点${currentMinute}分${currentSecond}秒,不在预定时间内`
);
}
}, 100); // 每100毫秒检查一次
};
const stopMonitoring = () => {
clearInterval(monitorInterval);
console.log("监控已暂停");
};
// 添加事件监听器到监控按钮
document
.getElementById("monitorButton")
.addEventListener("click", toggleMonitoring);
})();
在场地信息- (sysu.edu.cn)点击配置选择合适的时间段
点击开始监控,则会等到0点开抢