// ==UserScript== // @name 无用之脚本,没有任何作用 // @version 3.2 // @description 自动填入答案、自动提交、自动翻页,全流程自动化(带悬浮面板+倒计时) // @author Claude Code With DeepSeek-v4 // @match https://welearn.sflep.com/student/* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; // ============================================================ // 默认配置 // ============================================================ const DEFAULTS = { pageDelay: 3, submitDelay: 1.5, noAnswerDelay: 1.5, betweenCycleDelay: 2, }; function loadConfig() { try { var saved = localStorage.getItem('autofill_config'); if (saved) return JSON.parse(saved); } catch (e) {} return Object.assign({}, DEFAULTS); } function saveConfig(cfg) { try { localStorage.setItem('autofill_config', JSON.stringify(cfg)); } catch (e) {} } var CONFIG = loadConfig(); // ============================================================ // 运行时状态 // ============================================================ var STATE = 'idle'; var currentCycle = 0; var stopRequested = false; // ============================================================ // 工具函数 // ============================================================ function sleep(ms) { return new Promise(function(resolve) { setTimeout(resolve, ms); }); } function cleanAnswer(raw) { if (!raw) return ''; return raw.replace(/\s+/g, ' ').trim(); } function getIframeDoc(iframe) { try { return iframe.contentDocument || iframe.contentWindow.document; } catch (e) { return null; } } function waitForIframeLoad(iframe) { return new Promise(function(resolve) { var doc = getIframeDoc(iframe); if (doc && doc.readyState === 'complete') { var body = doc.querySelector('body'); if (body && body.innerHTML.trim().length > 0) { resolve(); return; } } iframe.addEventListener('load', function handler() { iframe.removeEventListener('load', handler); resolve(); }); }); } function hasAnswers(doc) { if (!doc) return false; return doc.querySelectorAll( 'input[data-solution], textarea[data-solution], [data-controltype="choice"] li[data-solution]' ).length > 0; } function setupAutoConfirm(iframe) { try { var win = iframe.contentWindow; if (win) { win['CONFIRM_AUTO_CALL'] = [ { title: '您确定现在提交吗?', action: true }, { title: '习题答案只能提交一次', action: true }, { title: '确认继续提交?', action: true }, ]; } } catch (e) {} } /** * 带倒计时显示的等待 * @param {number} seconds - 等待秒数 * @param {string} icon - 图标 * @param {string} prefix - 文字前缀 * @param {string} badge - 角标文字 */ async function waitWithCountdown(seconds, icon, prefix, badge) { var step = (seconds % 1 === 0) ? 1 : 0.5; for (var remaining = seconds; remaining > 0; remaining -= step) { if (remaining < step) remaining = step; // 防止最后一步变成负数 updateUI(icon, prefix + remaining.toFixed(1).replace(/\.0$/, '') + 's', badge); await sleep(step * 1000); if (stopRequested) break; } } // ============================================================ // 填答案函数 // ============================================================ function clickOption(li) { var span = li.querySelector('span'); if (span) { span.click(); } else { li.click(); } li.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); li.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); } function fillInputs(doc) { var inputs = doc.querySelectorAll('input[data-solution]'); var count = 0; inputs.forEach(function(inp) { var cleaned = cleanAnswer(inp.getAttribute('data-solution')); if (cleaned) { inp.value = cleaned; inp.dispatchEvent(new Event('input', { bubbles: true })); inp.dispatchEvent(new Event('change', { bubbles: true })); count++; } }); return count; } function fillTextareas(doc) { var textareas = doc.querySelectorAll('textarea[data-solution]'); var count = 0; textareas.forEach(function(ta) { var cleaned = cleanAnswer(ta.getAttribute('data-solution')); if (cleaned) { ta.value = cleaned; ta.dispatchEvent(new Event('input', { bubbles: true })); ta.dispatchEvent(new Event('change', { bubbles: true })); count++; } }); return count; } function fillChoices(doc) { var choices = doc.querySelectorAll('[data-controltype="choice"]'); var count = 0; choices.forEach(function(choice) { var targetLi = choice.querySelector('li[data-solution]'); if (targetLi) { clickOption(targetLi); count++; } else { var firstLi = choice.querySelector('ul[data-itemtype="options"] li:first-child'); if (firstLi) { clickOption(firstLi); count++; } } }); return count; } function fillAllAnswers(doc) { return fillInputs(doc) + fillTextareas(doc) + fillChoices(doc); } function clickSubmit(doc) { var submitBtn = doc.querySelector('[data-controltype="submit"]'); if (submitBtn) { submitBtn.click(); return true; } return false; } // ============================================================ // 悬浮面板 UI // ============================================================ var ui = {}; function injectUI() { var style = document.createElement('style'); style.textContent = [ '#autofill-float {', ' position: fixed; bottom: 16px; right: 16px; z-index: 2147483647;', ' font-family: "Microsoft YaHei", "PingFang SC", sans-serif; font-size: 13px;', ' background: rgba(30,30,30,0.92); color: #e0e0e0;', ' border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.45);', ' min-width: 200px; max-width: 280px;', ' user-select: none; transition: background 0.3s;', '}', '#autofill-bar {', ' display: flex; align-items: center; justify-content: space-between;', ' padding: 8px 12px; cursor: pointer; border-radius: 10px;', '}', '#autofill-bar:hover { background: rgba(255,255,255,0.06); }', '#autofill-icon { font-size: 16px; margin-right: 6px; }', '#autofill-msg { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }', '#autofill-badge {', ' background: #4caf50; color: #fff; font-size: 11px;', ' padding: 1px 7px; border-radius: 10px; margin-left: 8px;', ' display: none;', '}', '#autofill-panel {', ' display: none; padding: 4px 12px 12px 12px; border-top: 1px solid rgba(255,255,255,0.1);', '}', '#autofill-panel hr { border: none; border-top: 1px solid rgba(255,255,255,0.08); margin: 6px 0; }', '#autofill-panel .row {', ' display: flex; justify-content: space-between; align-items: center; padding: 5px 0;', '}', '#autofill-panel .row span.label { flex: 1; }', '#autofill-panel .row input[type=number] {', ' width: 52px; padding: 2px 4px; text-align: center;', ' border: 1px solid rgba(255,255,255,0.2); border-radius: 4px;', ' background: rgba(255,255,255,0.08); color: #81c784; font-size: 13px;', ' margin: 0 4px;', '}', '#autofill-panel .row input[type=number]:focus {', ' outline: none; border-color: #4caf50;', '}', '#autofill-panel .row span.unit { color: #999; font-size: 12px; }', '#autofill-panel button {', ' width: 100%; padding: 7px 0; margin-top: 4px; border: none; border-radius: 6px;', ' font-size: 13px; cursor: pointer; font-weight: bold;', '}', '#autofill-btn-start { background: #4caf50; color: #fff; }', '#autofill-btn-start:hover { background: #43a047; }', '#autofill-btn-stop { background: #f44336; color: #fff; }', '#autofill-btn-stop:hover { background: #e53935; }', ].join('\n'); document.head.appendChild(style); var keys = ['pageDelay', 'submitDelay', 'noAnswerDelay', 'betweenCycleDelay']; var labels = ['填答案前等待', '提交后等待', '无答案页等待', '翻页后等待']; var rows = ''; for (var i = 0; i < keys.length; i++) { rows += [ '