// ==UserScript==
// @name 2026最新广东干部培训网络学院自动学习助手
// @namespace http://tampermonkey.net/
// @version 3.1
// @description 定时关闭,带动态水印,自动播放,自动换课
// @author LEEMO2023
// @match https://gbpx.gd.gov.cn/*
// @match https://wcs1.shawcoder.xyz/*
// @match https://cs1.gdgbpx.com/*
// @match *://*gzqinghui.com.cn/*
// @grant window.close
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 激活系统配置
var ACTIVATION_CONFIG = {
trialMinutes: 20, // 试用分钟数
contactInfo: "如需激活码,请联系作者微信: leemo2023"
};
// 简单的状态变量
var bofangwan = false;
var currentUrl = window.location.href;
var isActivated = false;
var trialTimeUsed = 0; // 已使用的试用时间(分钟)
var deviceId = null;
// 动态水印相关变量
var dynamicWatermark = null;
var watermarkInterval = null;
// 初始化激活系统
initActivationSystem();
// 主逻辑
if (currentUrl.includes("gbpx.gd.gov.cn/gdceportal/Study/LearningCourse.aspx")) {
// 课程列表页面
setTimeout(function() {
handleCourseListPage();
}, 3000);
} else if (currentUrl.includes("gbpx.gd.gov.cn/gdceportal/study/StudyCenter.aspx")) {
// 学习中心页面
setTimeout(function() {
handleStudyCenterPage();
}, 3000);
} else if (currentUrl.includes("play_pc") || currentUrl.includes("CourseWare")) {
// 视频播放页面
setTimeout(function() {
handleVideoPage();
}, 2000);
} else if (currentUrl === "https://wcs1.shawcoder.xyz/gdcecw/play_pc/playdo_pc.html") {
// 播放完成页面
setTimeout(function() {
handleCompletionPage();
}, 2000);
} else {
// 其他页面
console.log("学习助手:等待处理");
}
// ==================== 激活系统函数 ====================
function initActivationSystem() {
// 生成设备ID(持久化存储)
deviceId = getOrCreateDeviceId();
console.log("设备ID: " + deviceId);
// 检查是否已激活
var activationData = GM_getValue("activation_data", null);
if (activationData) {
// 检查激活码是否匹配当前设备
if (activationData.deviceId === deviceId) {
// 检查激活是否过期(激活码永久有效)
if (activationData.activatedAt && activationData.code) {
isActivated = true;
console.log("学习助手:已激活");
return;
}
} else {
// 设备ID不匹配,清除旧的激活数据
console.log("学习助手:设备ID不匹配,清除旧激活数据");
GM_deleteValue("activation_data");
}
}
// 如果未激活,检查试用时间
if (!isActivated) {
// 获取试用开始时间
var trialStartTime = GM_getValue("trial_start_time", 0);
if (trialStartTime === 0) {
// 第一次使用,记录开始时间
GM_setValue("trial_start_time", Date.now());
trialTimeUsed = 0;
console.log("学习助手:开始试用计时");
} else {
// 计算已使用的试用时间(秒转分钟)
var now = Date.now();
var timeDiff = now - trialStartTime;
trialTimeUsed = Math.floor(timeDiff / (1000 * 60));
// 保存已使用的试用时间(防止刷新页面重新计时)
GM_setValue("trial_time_used", trialTimeUsed);
}
console.log("学习助手:已使用 " + trialTimeUsed + " 分钟试用时间");
// 如果试用时间超过20分钟,显示激活弹窗
if (trialTimeUsed >= ACTIVATION_CONFIG.trialMinutes) {
console.log("学习助手:试用时间结束,需要激活");
// 延迟显示弹窗
setTimeout(showActivationPopup, 2000);
}
}
}
function getOrCreateDeviceId() {
// 尝试从存储中获取设备ID
var savedDeviceId = GM_getValue("device_id", null);
if (!savedDeviceId) {
// 生成新的设备ID
var timestamp = Date.now().toString(36).toUpperCase();
var random = Math.random().toString(36).substring(2, 8).toUpperCase();
savedDeviceId = "GD-" + timestamp.substring(0, 4) + "-" + random;
// 保存设备ID
GM_setValue("device_id", savedDeviceId);
console.log("学习助手:生成新设备ID: " + savedDeviceId);
}
return savedDeviceId;
}
function generateActivationCode(deviceId) {
// 生成激活码的算法
var hash = 0;
for (var i = 0; i < deviceId.length; i++) {
var char = deviceId.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // 转换为32位整数
}
// 生成唯一激活码
var codeBase = Math.abs(hash).toString(36).toUpperCase();
var part1 = codeBase.substring(0, 5).padEnd(5, 'X');
var part2 = codeBase.substring(5, 10).padEnd(5, 'Y');
return "GD-" + part1 + "-" + part2;
}
function showActivationPopup() {
// 避免重复弹窗
if (document.getElementById("gbpx-activation-popup")) return;
console.log("学习助手:显示激活弹窗");
// 获取真实激活码
var realActivationCode = generateActivationCode(deviceId);
// 创建激活弹窗
var popup = document.createElement("div");
popup.id = "gbpx-activation-popup";
popup.innerHTML = `
学习助手激活系统
⚠️ 试用期已结束
您已使用 ${trialTimeUsed} 分钟,超过 ${ACTIVATION_CONFIG.trialMinutes} 分钟试用限制
激活步骤:
2. 获取激活码:
微信联系: leemo2023
发送设备ID获取激活码
注意:每个激活码只能使用一次,激活后永久有效
`;
document.body.appendChild(popup);
// 添加事件监听
document.getElementById("gbpx-activation-close").onclick = function() {
popup.remove();
};
// 复制设备ID按钮
document.getElementById("gbpx-copy-device-id").onclick = function() {
var deviceIdText = document.getElementById("gbpx-device-id").textContent;
navigator.clipboard.writeText(deviceIdText).then(function() {
var btn = document.getElementById("gbpx-copy-device-id");
var originalText = btn.textContent;
btn.textContent = "✓ 已复制";
btn.style.background = "#28a745";
setTimeout(function() {
btn.textContent = originalText;
btn.style.background = "#4a6fa5";
}, 2000);
});
};
// 复制联系方式按钮
document.getElementById("gbpx-copy-contact").onclick = function() {
var contactText = "leemo2023";
navigator.clipboard.writeText(contactText).then(function() {
var btn = document.getElementById("gbpx-copy-contact");
var originalText = btn.textContent;
btn.textContent = "✓ 已复制";
btn.style.background = "#28a745";
setTimeout(function() {
btn.textContent = originalText;
btn.style.background = "#4a6fa5";
}, 2000);
});
};
document.getElementById("gbpx-activate-btn").onclick = function() {
var activationCode = document.getElementById("gbpx-activation-code").value.trim().toUpperCase();
// 检查激活码格式
if (!activationCode) {
showActivationMessage("请输入激活码", "error");
return;
}
var codePattern = /^GD-[A-Z0-9]{5}-[A-Z0-9]{5}$/;
if (!codePattern.test(activationCode)) {
showActivationMessage("激活码格式错误,应为:GD-XXXXX-XXXXX", "error");
return;
}
// 验证激活码 - 使用算法验证
var expectedCode = generateActivationCode(deviceId);
if (activationCode === expectedCode) {
// 激活成功 - 保存到本地存储
var activationData = {
code: activationCode,
deviceId: deviceId,
activatedAt: Date.now(),
activatedDate: new Date().toLocaleString()
};
// 保存激活数据
GM_setValue("activation_data", activationData);
// 清除试用时间记录
GM_deleteValue("trial_start_time");
GM_deleteValue("trial_time_used");
// 标记为已激活
isActivated = true;
showActivationMessage("✅ 激活成功!助手已解锁全部功能", "success");
setTimeout(function() {
popup.remove();
// 刷新页面以应用激活状态
location.reload();
}, 1500);
} else {
showActivationMessage("❌ 激活码无效,请检查后重试", "error");
}
};
document.getElementById("gbpx-exit-btn").onclick = function() {
if (confirm("确定要退出使用吗?")) {
location.reload();
}
};
function showActivationMessage(text, type) {
var messageEl = document.getElementById("gbpx-activation-message");
messageEl.innerHTML = type === "success" ?
`${text}` :
`${text}`;
}
}
// ==================== 动态水印函数 ====================
function createDynamicWatermark() {
// 移除旧的水印
removeDynamicWatermark();
// 创建水印元素
dynamicWatermark = document.createElement("div");
dynamicWatermark.id = "gbpx-dynamic-watermark";
dynamicWatermark.textContent = "视频自动播放中";
dynamicWatermark.style.cssText = `
position: fixed;
z-index: 9999;
pointer-events: none;
background: rgba(0, 0, 0, 0.7);
color: #4CAF50;
padding: 12px 25px;
border-radius: 30px;
font-size: 16px;
font-weight: bold;
border: 3px solid #4CAF50;
box-shadow: 0 0 25px rgba(76, 175, 80, 0.6);
white-space: nowrap;
user-select: none;
backdrop-filter: blur(3px);
animation: watermarkPulse 2s infinite;
font-family: Arial, sans-serif;
`;
// 添加动画样式
var style = document.createElement('style');
style.textContent = `
@keyframes watermarkPulse {
0% {
transform: scale(1);
box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
opacity: 0.9;
}
50% {
transform: scale(1.05);
box-shadow: 0 0 35px rgba(76, 175, 80, 0.9);
opacity: 1;
}
100% {
transform: scale(1);
box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
opacity: 0.9;
}
}
`;
document.head.appendChild(style);
// 随机初始位置
var maxX = window.innerWidth - 220;
var maxY = window.innerHeight - 60;
var posX = Math.floor(Math.random() * maxX);
var posY = Math.floor(Math.random() * maxY);
// 初始速度
var velocityX = (Math.random() > 0.5 ? 1 : -1) * (1.5 + Math.random() * 1.5);
var velocityY = (Math.random() > 0.5 ? 1 : -1) * (1 + Math.random() * 1);
// 应用初始位置
dynamicWatermark.style.left = posX + "px";
dynamicWatermark.style.top = posY + "px";
document.body.appendChild(dynamicWatermark);
console.log("学习助手:动态水印已创建");
// 启动水印移动动画
watermarkInterval = setInterval(function() {
if (!dynamicWatermark) return;
// 获取当前边界
var rect = dynamicWatermark.getBoundingClientRect();
var currentX = parseInt(dynamicWatermark.style.left) || 0;
var currentY = parseInt(dynamicWatermark.style.top) || 0;
// 更新位置
currentX += velocityX;
currentY += velocityY;
// 边界碰撞检测和反弹
var bounced = false;
if (currentX <= 10) {
currentX = 10;
velocityX = Math.abs(velocityX);
bounced = true;
} else if (currentX >= maxX) {
currentX = maxX;
velocityX = -Math.abs(velocityX);
bounced = true;
}
if (currentY <= 10) {
currentY = 10;
velocityY = Math.abs(velocityY);
bounced = true;
} else if (currentY >= maxY) {
currentY = maxY;
velocityY = -Math.abs(velocityY);
bounced = true;
}
// 更新边界
maxX = window.innerWidth - rect.width - 10;
maxY = window.innerHeight - rect.height - 10;
// 确保在边界内
if (currentX > maxX) currentX = maxX;
if (currentY > maxY) currentY = maxY;
// 随机改变方向(只有未反弹时才改变)
if (!bounced && Math.random() < 0.01) {
velocityX += (Math.random() - 0.5) * 1.5;
velocityY += (Math.random() - 0.5) * 1.5;
// 限制最大速度
var maxSpeed = 4;
velocityX = Math.max(-maxSpeed, Math.min(maxSpeed, velocityX));
velocityY = Math.max(-maxSpeed, Math.min(maxSpeed, velocityY));
}
// 应用新位置
dynamicWatermark.style.left = currentX + "px";
dynamicWatermark.style.top = currentY + "px";
// 轻微旋转效果
var rotation = Math.sin(Date.now() / 800) * 2;
dynamicWatermark.style.transform = `rotate(${rotation}deg) scale(1.05)`;
}, 40); // 每秒更新25次
}
function removeDynamicWatermark() {
if (dynamicWatermark) {
dynamicWatermark.remove();
dynamicWatermark = null;
}
if (watermarkInterval) {
clearInterval(watermarkInterval);
watermarkInterval = null;
}
}
// ==================== 主逻辑函数 ====================
function handleCourseListPage() {
// 检查是否已激活
if (!isActivated && trialTimeUsed >= ACTIVATION_CONFIG.trialMinutes) {
// 等待激活弹窗
return;
}
console.log("学习助手:处理课程列表");
// 等待页面完全加载
setTimeout(function() {
var alla = document.querySelectorAll("a.courseware-list-reed");
if (alla.length === 0) {
// 尝试通过ID模式查找
alla = document.querySelectorAll("a[id^='gvList_ctl']");
}
if (alla.length > 0) {
// 查找第一个未完成课程
var unfinishedCourse = null;
for (var i = 0; i < alla.length; i++) {
var course = alla[i];
var title = course.title || course.textContent || "";
var progress = getCourseProgress(title);
if (progress < 95) {
unfinishedCourse = {
element: course,
index: i + 1,
total: alla.length,
progress: progress
};
break;
}
}
if (unfinishedCourse) {
console.log("学习助手:开始学习第" + unfinishedCourse.index + "个课程");
// 点击课程
setTimeout(function() {
unfinishedCourse.element.click();
}, 2000);
} else {
console.log("学习助手:所有课程已完成");
}
} else {
console.log("学习助手:未找到课程链接");
}
}, 1000);
}
function handleStudyCenterPage() {
// 检查是否已激活
if (!isActivated && trialTimeUsed >= ACTIVATION_CONFIG.trialMinutes) {
return;
}
console.log("学习助手:检测学习进度");
// 等待页面加载
setTimeout(function() {
// 查找课程进度元素
var progress = getCurrentProgress();
console.log("学习助手:当前课程进度: " + progress + "%");
if (progress >= 95) {
// 课程已完成,继续下一个
console.log("学习助手:课程已完成,继续下一个");
setTimeout(function() {
window.location.href = "https://gbpx.gd.gov.cn/gdceportal/Study/LearningCourse.aspx";
}, 3000);
} else {
// 课程未完成,重新学习
console.log("学习助手:课程未完成,重新学习");
setTimeout(function() {
findAndClickCourse();
}, 3000);
}
}, 2000);
}
function handleVideoPage() {
// 检查是否已激活
if (!isActivated && trialTimeUsed >= ACTIVATION_CONFIG.trialMinutes) {
// 在视频页面也显示激活弹窗
setTimeout(showActivationPopup, 3000);
return;
}
console.log("学习助手:处理视频页面");
// 创建动态水印
createDynamicWatermark();
// 设置定时器:5分钟后关闭窗口
var minutes = 5;
console.log("学习助手:设置" + minutes + "分钟定时关闭");
// 启动5分钟定时器
var timer = setTimeout(function() {
console.log("学习助手:" + minutes + "分钟到,关闭窗口");
closeVideoAndCheckProgress();
}, minutes * 60 * 1000);
// 保存定时器以便清理
window.videoTimer = timer;
// 延迟后开始尝试播放
setTimeout(function() {
startVideoPlayback();
}, 2000);
}
function startVideoPlayback() {
console.log("学习助手:开始尝试播放视频...");
// 增加播放尝试次数
var playAttempts = 0;
var maxAttempts = 10;
// 立即尝试第一次播放
tryToPlayVideo();
// 设置定期重试
var playInterval = setInterval(function() {
playAttempts++;
console.log("学习助手:播放尝试 " + playAttempts + "/" + maxAttempts);
if (playAttempts >= maxAttempts) {
clearInterval(playInterval);
console.log("学习助手:达到最大尝试次数,停止尝试播放");
return;
}
// 检查视频是否已经在播放
if (isVideoPlaying()) {
clearInterval(playInterval);
console.log("学习助手:视频已在播放中,停止重试");
return;
}
// 再次尝试播放
tryToPlayVideo();
}, 3000); // 每3秒尝试一次
// 保存定时器以便清理
window.playInterval = playInterval;
}
// ==================== 工具函数 ====================
function isVideoPlaying() {
try {
var videos = document.querySelectorAll("video");
if (videos.length > 0) {
var video = videos[0];
return !video.paused && !video.ended;
}
var progressElements = document.querySelectorAll(".vjs-play-progress");
if (progressElements.length > 0) {
var progress = progressElements[0].style.width;
if (progress && progress !== "0%" && progress !== "0px") {
return true;
}
}
} catch (e) {
// 忽略错误
}
return false;
}
function tryToPlayVideo() {
console.log("学习助手:尝试播放视频...");
tryDirectVideoPlay();
setTimeout(function() {
tryClickPlayButtons();
}, 500);
setTimeout(function() {
tryClickPageCenter();
}, 1000);
}
function tryDirectVideoPlay() {
try {
var videos = document.querySelectorAll("video");
if (videos.length > 0) {
var video = videos[0];
video.volume = 0;
video.muted = true;
video.play().then(function() {
console.log("学习助手:直接播放video元素成功");
}).catch(function(error) {
console.log("学习助手:直接播放失败: " + error.message);
});
}
} catch (e) {
// 忽略错误
}
}
function tryClickPlayButtons() {
var playSelectors = [
'.vjs-big-play-button', '.vjs-play-control', '.vjs-play-button',
'.video-js .vjs-big-play-button', 'button[title*="播放"]',
'button[title*="play"]', 'button[aria-label*="播放"]',
'button[aria-label*="play"]', '.play-btn', '.video-play',
'.play-button', '.start-play', '.vjs-fullscreen-control',
'.fullscreen-btn', '.start-button', '.begin-btn',
'video', '.video-js', '.vjs-poster', '.video-poster'
];
for (var i = 0; i < playSelectors.length; i++) {
try {
var elements = document.querySelectorAll(playSelectors[i]);
if (elements.length > 0) {
for (var j = 0; j < elements.length; j++) {
var element = elements[j];
if (isElementVisible(element)) {
console.log("学习助手:点击播放按钮: " + playSelectors[i]);
element.click();
if (playSelectors[i] === 'video' || playSelectors[i] === '.video-js') {
setTimeout(function() {
tryDirectVideoPlay();
}, 100);
}
}
}
}
} catch (e) {
console.log("学习助手:点击" + playSelectors[i] + "失败");
}
}
}
function tryClickPageCenter() {
try {
var x = window.innerWidth / 2;
var y = window.innerHeight / 2;
var element = document.elementFromPoint(x, y);
if (element) {
console.log("学习助手:点击页面中心元素: " + element.tagName);
var clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
clientX: x,
clientY: y
});
element.dispatchEvent(clickEvent);
}
} catch (e) {
console.log("学习助手:点击页面中心失败");
}
}
function isElementVisible(element) {
if (!element) return false;
var rect = element.getBoundingClientRect();
return rect.width > 0 && rect.height > 0 &&
rect.top >= 0 && rect.left >= 0 &&
rect.bottom <= window.innerHeight && rect.right <= window.innerWidth;
}
function closeVideoAndCheckProgress() {
console.log("学习助手:视频播放完成");
// 清理水印
removeDynamicWatermark();
if (window.videoTimer) clearTimeout(window.videoTimer);
if (window.playInterval) clearInterval(window.playInterval);
try {
if (window.opener && !window.opener.closed) {
sendMultipleRefreshMessages();
}
} catch (e) {
console.log("学习助手:无法向主窗口发送消息");
}
setTimeout(function() {
try {
window.close();
console.log("学习助手:成功关闭窗口");
} catch (e) {
console.log("学习助手:无法关闭窗口,跳转到学习中心");
window.location.href = "https://gbpx.gd.gov.cn/gdceportal/study/StudyCenter.aspx";
}
}, 2000);
}
function sendMultipleRefreshMessages() {
var refreshCount = 3;
var currentCount = 0;
console.log("学习助手:将发送" + refreshCount + "次刷新消息");
function sendNextRefresh() {
if (currentCount < refreshCount) {
currentCount++;
console.log("学习助手:发送第" + currentCount + "次刷新消息");
window.opener.postMessage({
type: 'refreshPage',
source: 'videoWindow',
timestamp: Date.now(),
refreshCount: currentCount,
totalRefreshes: refreshCount
}, '*');
if (currentCount < refreshCount) {
setTimeout(sendNextRefresh, 5000);
} else {
console.log("学习助手:已发送所有" + refreshCount + "次刷新消息");
}
}
}
setTimeout(sendNextRefresh, 1000);
}
function handleCompletionPage() {
console.log("学习助手:播放完成页面");
setTimeout(function() {
try {
var closeButtons = document.querySelectorAll("button.instructions-close");
if (closeButtons.length > 0) {
closeButtons[0].click();
console.log("学习助手:点击了关闭按钮");
}
} catch (e) {
console.log("学习助手:关闭按钮点击失败");
}
setTimeout(function() {
try {
window.close();
} catch (e) {
window.location.href = "https://gbpx.gd.gov.cn/gdceportal/study/StudyCenter.aspx";
}
}, 1000);
}, 2000);
}
function getCurrentProgress() {
var allDivs = document.querySelectorAll("div");
for (var i = 0; i < allDivs.length; i++) {
var div = allDivs[i];
var text = div.textContent || div.innerText || "";
var match = text.match(/([\d.]+)%/);
if (match) {
var progress = parseFloat(match[1]);
if (!isNaN(progress)) return progress;
}
}
var styledDivs = document.querySelectorAll("div[style*='width: 50px']");
for (var j = 0; j < styledDivs.length; j++) {
var styledDiv = styledDivs[j];
var text = styledDiv.textContent || styledDiv.innerText || "";
var match = text.trim().match(/([\d.]+)/);
if (match) {
var progress = parseFloat(match[1]);
if (!isNaN(progress)) return progress;
}
}
return 0;
}
function findAndClickCourse() {
var alla = document.querySelectorAll("a.courseware-list-reed");
if (alla.length === 0) {
alla = document.querySelectorAll("a[id^='gvList_ctl']");
}
if (alla.length > 0) {
console.log("学习助手:点击课程继续学习");
alla[0].click();
} else {
console.log("学习助手:未找到课程,返回课程列表");
setTimeout(function() {
window.location.href = "https://gbpx.gd.gov.cn/gdceportal/Study/LearningCourse.aspx";
}, 3000);
}
}
function getCourseProgress(title) {
var progress = 0;
var match = title.match(/已学习\s*([\d.]+)[%%]/);
if (match && match[1]) {
progress = parseFloat(match[1]);
}
return progress;
}
// 添加主窗口消息监听器
if (window.location.href.includes("gbpx.gd.gov.cn/gdceportal/Study/LearningCourse.aspx")) {
window.addEventListener('message', function(event) {
if (event.data && event.data.type === 'refreshPage') {
console.log("学习助手:收到刷新消息,刷新页面");
setTimeout(function() {
window.location.reload();
}, 2000);
}
if (event.data && event.data.type === 'multipleRefresh') {
console.log("学习助手:收到多次刷新消息");
setTimeout(function() {
window.location.reload();
}, 2000);
}
});
setInterval(function() {
if (window.videoWindow && window.videoWindow.closed) {
console.log("学习助手:检测到视频窗口已关闭,刷新页面");
var refreshCount = 3;
var currentCount = 0;
function doRefresh() {
if (currentCount < refreshCount) {
currentCount++;
console.log("学习助手:刷新第" + currentCount + "次,共" + refreshCount + "次");
if (currentCount < refreshCount) {
window.location.reload();
} else {
console.log("学习助手:刷新完成,等待检测进度...");
setTimeout(function() {
window.location.reload();
}, 3000);
}
}
}
setTimeout(doRefresh, 2000);
}
}, 30000);
}
})();