您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
进入到学习界面点击
当前为
// ==UserScript== // @name 安培在线学习 // @namespace http://tampermonkey.net/ // @version 2024-10-23 // @description 进入到学习界面点击 // @author buhuixue // @match https://sctt.anpeiwang.com/courseStudyAction/toCourseStudyV2.action // @icon https://sctt.anpeiwang.com/courseStudyAction/toCourseStudyV2.action // @grant none // ==/UserScript== (function() { 'use strict'; // 使用严格模式 // 创建一个按钮 const button = document.createElement('button'); button.textContent = '开始学习'; // 按钮文本 button.style.position = 'fixed'; // 固定位置 button.style.top = '10px'; // 距离顶部10px button.style.right = '10px'; // 距离右边10px button.style.zIndex = 1000; // 确保在最上层 button.style.padding = '10px 15px'; // 添加内边距 button.style.backgroundColor = '#4CAF50'; // 背景色 button.style.color = 'white'; // 文本颜色 button.style.border = 'none'; // 去掉边框 button.style.borderRadius = '5px'; // 圆角 button.style.cursor = 'pointer'; // 鼠标悬停样式 // 将按钮添加到页面 document.body.appendChild(button); // 创建一个元素用来显示结果 const resultDisplay = document.createElement('div'); resultDisplay.style.position = 'fixed'; // 固定位置 resultDisplay.style.top = '50px'; // 距离顶部50px resultDisplay.style.right = '10px'; // 距离右边10px resultDisplay.style.zIndex = 1000; // 确保在最上层 resultDisplay.style.backgroundColor = 'rgba(255, 255, 255, 0.9)'; // 背景色 resultDisplay.style.border = '1px solid #ccc'; // 边框 resultDisplay.style.borderRadius = '5px'; // 圆角 resultDisplay.style.padding = '10px'; // 内边距 resultDisplay.style.display = 'none'; // 初始隐藏 document.body.appendChild(resultDisplay); // 按钮点击事件 button.addEventListener('click', function() { // 页面元素选择和类型判断 const isPDF = window.location.href.endsWith('.pdf') || document.querySelector('embed[type="application/pdf"], iframe[src*=".pdf"]') !== null; const isVideo = document.querySelector('video') !== null; // 声明用于请求的变量 const wareRecordId = window.wareRecordId; const courseRecordId = window.courseRecordId; const courseId = window.courseId; const userId = window.userId; const source = window.source; const relationId = window.relationId; const courseWareId = window.courseWareId; let pdfTotalPage; let videoTotalTime; // 根据页面类型设置totalTime或totalPages if (isPDF) { // 获取 PDF 的最大页数 const numPagesElement = document.querySelector('#numPages'); if (numPagesElement) { pdfTotalPage = parseInt(numPagesElement.textContent.trim().replace('/', '').trim()); console.log('PDF 总页数:', pdfTotalPage); resultDisplay.textContent = 'PDF 总页数: ' + pdfTotalPage; // 显示在页面上 resultDisplay.style.display = 'block'; // 显示结果框 } else { console.log('Page number element not found.'); resultDisplay.textContent = '未找到页数元素。'; // 显示在页面上 resultDisplay.style.display = 'block'; // 显示结果框 } } else if (isVideo) { // 获取视频的总时长 const durationElement = document.querySelector('.prism-time-display .duration'); if (durationElement) { videoTotalTime = durationElement.textContent; // 保持 mm:ss 格式 console.log('Video 总时长:', videoTotalTime); resultDisplay.textContent = '视频 总时长: ' + videoTotalTime; // 显示在页面上 resultDisplay.style.display = 'block'; // 显示结果框 } else { console.log('Duration element not found.'); resultDisplay.textContent = '未找到时长元素。'; // 显示在页面上 resultDisplay.style.display = 'block'; // 显示结果框 } } else { console.log('This page is neither a PDF nor a video.'); resultDisplay.textContent = '此页面既不是 PDF 也不是视频。'; // 显示在页面上 resultDisplay.style.display = 'block'; // 显示结果框 } // 动态生成请求的body内容 let bodyContent = ''; if (isPDF) { // 如果是PDF页面,使用totalPages和currPage const currPage = pdfTotalPage; // 假设当前页等于最大页 bodyContent = `wareRecordId=${wareRecordId}&courseRecordId=${courseRecordId}&courseId=${courseId}&userId=${userId}&totalPages=${pdfTotalPage}&currPage=${currPage}&source=${source}&relationId=${relationId}&courseWareId=${courseWareId}`; } else if (isVideo) { // 如果是视频页面,使用totalTime和currentTime const totalTimeInSeconds = convertTimeToSeconds(videoTotalTime); // 转换为秒 bodyContent = `wareRecordId=${wareRecordId}&courseRecordId=${courseRecordId}&courseId=${courseId}&userId=${userId}&totalTime=${totalTimeInSeconds}¤tTime=${totalTimeInSeconds}&source=${source}&relationId=${relationId}&courseWareId=${courseWareId}`; } // 发起POST请求 fetch("https://sctt.anpeiwang.com/courseStudyAction/recordVedioWareAfterLeavePage.action", { "headers": { "accept": "*/*", "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", "cache-control": "no-cache", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "pragma": "no-cache", "x-requested-with": "XMLHttpRequest" }, "referrer": "https://sctt.anpeiwang.com/courseStudyAction/toCourseStudyV2.action", "referrerPolicy": "strict-origin-when-cross-origin", "body": bodyContent, "method": "POST", "mode": "cors", "credentials": "include" }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } // 直接输出响应内容到控制台,并在页面上显示 return response.json() .then(data => { console.log('Success:', data); resultDisplay.textContent += '\nPOST 返回值: ' + JSON.stringify(data); // 显示在页面上 }) .catch(() => response.text().then(text => { console.log('Response text:', text); resultDisplay.textContent += '\nPOST 返回文本: ' + text; // 显示在页面上 })); }) .catch(error => { console.error('Error:', error); resultDisplay.textContent += '\n错误信息: ' + error; // 显示在页面上 }); }); // 将时间格式(mm:ss)转换为秒 function convertTimeToSeconds(time) { const parts = time.split(':'); let seconds = 0; if (parts.length === 2) { // 确保是 mm:ss 格式 seconds += parseInt(parts[0], 10) * 60; // 分钟转为秒 seconds += parseInt(parts[1], 10); // 秒 } return seconds; } })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址