// ==UserScript== // @name leo-imerry // @namespace http://tampermonkey.net/ // @version 1.1 // @description 复习检查答案专用 // @author You // @match http://59.69.103.147/Reports/* // @match http://59.69.101.153/lab/Reports/* // @grant none // ==/UserScript== (function() { 'use strict'; const options = ['A', 'B', 'C', 'D']; const inputIds = [ "result_refer_pre0", "result_refer_pre1", "result_refer_pre2", "result_refer_pre3", "result_refer_pre4" ]; // 创建可拖动的输出框、获取答案按钮和关闭按钮 const outputBox = document.createElement('div'); const getAnswerButton = document.createElement('button'); const closeButton = document.createElement('span'); const adText = document.createElement('p'); // 设置输出框的样式 outputBox.style.position = 'fixed'; outputBox.style.top = '10px'; outputBox.style.right = '10px'; outputBox.style.width = '300px'; outputBox.style.padding = '10px'; outputBox.style.backgroundColor = '#f9f9f9'; outputBox.style.border = '1px solid #ddd'; outputBox.style.borderRadius = '8px'; outputBox.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)'; outputBox.style.fontFamily = 'Arial, sans-serif'; outputBox.style.cursor = 'move'; // 设置关闭按钮的样式和功能 closeButton.textContent = '✖'; closeButton.style.position = 'absolute'; closeButton.style.top = '5px'; closeButton.style.right = '5px'; closeButton.style.cursor = 'pointer'; closeButton.style.fontWeight = 'bold'; closeButton.style.color = '#888'; closeButton.addEventListener('click', () => { outputBox.style.display = 'none'; }); // 设置获取答案按钮的样式和功能 getAnswerButton.textContent = '获取答案'; getAnswerButton.style.display = 'block'; getAnswerButton.style.marginBottom = '10px'; getAnswerButton.style.padding = '5px 10px'; getAnswerButton.style.backgroundColor = '#4CAF50'; getAnswerButton.style.color = 'white'; getAnswerButton.style.border = 'none'; getAnswerButton.style.borderRadius = '4px'; getAnswerButton.style.cursor = 'pointer'; getAnswerButton.addEventListener('click', () => { updateAnswerDisplay(); // 点击后重新获取并更新显示答案 }); // 设置广告文本和链接 adText.innerHTML = `如有各类网课需求可以前往 https://leo.imerryi.top`; adText.style.fontSize = '12px'; adText.style.color = '#555'; adText.style.marginBottom = '10px'; // 添加关闭按钮、广告、获取答案按钮和答案显示框到页面 outputBox.appendChild(closeButton); outputBox.appendChild(getAnswerButton); outputBox.appendChild(adText); document.body.appendChild(outputBox); // 初始化并显示答案 function updateAnswerDisplay() { // 清空现有内容,重新添加按钮和广告 outputBox.innerHTML = ''; outputBox.appendChild(closeButton); outputBox.appendChild(getAnswerButton); outputBox.appendChild(adText); // 添加答案显示内容 inputIds.forEach((id, index) => { const value = document.getElementById(id).value; const answerText = document.createElement('p'); answerText.style.margin = '5px 0'; answerText.style.padding = '5px'; answerText.style.backgroundColor = '#eef'; answerText.style.borderRadius = '4px'; answerText.style.fontWeight = 'bold'; answerText.textContent = `题目 ${index + 1}: 选项 ${getSelectedOptions(value)}`; outputBox.appendChild(answerText); }); } // 获取选中的选项 function getSelectedOptions(value) { return value.split('').map((v, i) => (v === '1' ? options[i] : '')).filter(Boolean).join(', '); } // 页面加载时自动显示答案 updateAnswerDisplay(); // 实现拖动功能 let isDragging = false; let offsetX, offsetY; outputBox.addEventListener('mousedown', (e) => { isDragging = true; offsetX = e.clientX - outputBox.getBoundingClientRect().left; offsetY = e.clientY - outputBox.getBoundingClientRect().top; }); document.addEventListener('mousemove', (e) => { if (isDragging) { outputBox.style.left = `${e.clientX - offsetX}px`; outputBox.style.top = `${e.clientY - offsetY}px`; } }); document.addEventListener('mouseup', () => { isDragging = false; }); })();