智慧职教自动签到
// ==UserScript==
// @name 智慧职教自动签到
// @namespace https://me.rsr.asia/
// @version 0.1
// @description 实现智慧职教自动签到
// @author 任尚仁
// @match *://*.icve.com.cn/*
// @icon https://spoc-classroom.icve.com.cn/classroom/favicon.ico
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 创建操作日志记录元素和标题元素
var logDiv = document.createElement('div');
logDiv.id = 'log-div';
// 添加滚动条样式
logDiv.style.overflow = 'auto';
logDiv.style.position = 'fixed';
logDiv.style.top = '150px';
logDiv.style.right = '5%';
logDiv.style.transform = 'translateX(-50%)';
logDiv.style.height = "150px";
logDiv.style.width = "150px";
logDiv.style.padding = '10px';
logDiv.style.backgroundColor = '#ffffff';
logDiv.style.border = '1px solid #cccccc';
logDiv.style.boxShadow = '0px 2px 4px rgba(0, 0, 0, 0.1)';
logDiv.style.zIndex = '9999';
var titleElement = document.createElement('h3');
titleElement.innerText = "日志";
titleElement.style.textAlign = 'center';
// 将标题和日志记录元素添加到页面中
logDiv.appendChild(titleElement);
document.body.appendChild(logDiv);
function logAction(message) {
var logItem = document.createElement('p');
var timestamp = new Date().toLocaleTimeString();
logItem.innerText = "[" + timestamp + "] " + message;
logDiv.appendChild(logItem);
}
window.addEventListener('load', function() {
var enterButton = document.getElementById('userCenterUrl');
if (enterButton) {
enterButton.click();
}
});
function clickCalendar() {
// 点击教学日历
var linkElements = document.getElementsByClassName("tabs-link");
for (var i = 0; i < linkElements.length; i++) {
var linkElement = linkElements[i];
if (linkElement.innerText === "教学日历") {
linkElement.click();
logAction("已点击教学日历按钮");
break;
}
}
// 点击进入课堂按钮后更新日志记录内容
function clickEnterClassroom() {
var btnElements = document.getElementsByClassName("btn-hollow-danger");
for (var i = 0; i < btnElements.length; i++) {
var btnElement = btnElements[i];
if (btnElement.getAttribute("onclick").includes("openStuClassroom")) {
btnElement.click();
logAction("已点击进入课堂按钮");
}
}
}
// 在页面加载完成后执行操作
window.addEventListener('load', function() {
setTimeout(clickEnterClassroom, 2000); // 延迟2秒后执行点击进入课堂按钮
});
}
function clickCheckinButton() {
// 查找签到按钮
var checkinButton = document.querySelector('div.participate-in');
if (checkinButton && checkinButton.innerText === '签到') {
// 点击签到按钮
checkinButton.click();
logAction("已点击签到按钮");
} else {
logAction("未找到签到按钮");
}
}
if (window.location.href.match(/^https:\/\/spoc-classroom\.icve\.com\.cn\/.*$/)) {
// 延迟10秒后关闭当前页面
setTimeout(function() {
window.close();
}, 10000);
}
// 调用clickCalendar和clickCheckinButton函数
clickCalendar();
// 延迟5秒后执行自动化点击签到按钮的操作
setTimeout(clickCheckinButton, 5000);
setInterval(function() {
location.reload(true); // 使用location.reload(true)来强制刷新页面
}, 60000); // 每60秒刷新一次
})();