// ==UserScript== // @name DGUT优学院自动阅读器 // @namespace http://tampermonkey.net/ // @version 0.7.1 // @description 自动启读+本地保存秒数设置,刷新不用重开 // @author 豆包、uhys // @match *://*/* // @grant none // @run-at document-idle // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/572461/DGUT%E4%BC%98%E5%AD%A6%E9%99%A2%E8%87%AA%E5%8A%A8%E9%98%85%E8%AF%BB%E5%99%A8.user.js // @updateURL https://update.greasyfork.icu/scripts/572461/DGUT%E4%BC%98%E5%AD%A6%E9%99%A2%E8%87%AA%E5%8A%A8%E9%98%85%E8%AF%BB%E5%99%A8.meta.js // ==/UserScript== (function() { 'use strict'; // 仅阅读器iframe生效 const isTargetIframe = !!document.querySelector('#nextBtn'); if (!isTargetIframe) return; if (window.__AUTO_READER_INITED__) return; window.__AUTO_READER_INITED__ = true; // 读取本地储存 / 默认30秒 let saveSec = localStorage.getItem("autoReaderSaveSec"); let CLICK_INTERVAL = saveSec ? Number(saveSec) * 1000 : 30000; const DEFAULT_SEC = saveSec || 30; const NEXT_BTN_SELECTOR = '#nextBtn'; let timer = null; let dragOffsetX = 0, dragOffsetY = 0; let startBtnEl = null; let inputEle = null; // 自动翻页 function clickNextBtn() { const btn = document.querySelector(NEXT_BTN_SELECTOR); if (btn) btn.click(); } // 开始阅读 function startAuto() { if (timer) return; timer = setInterval(clickNextBtn, CLICK_INTERVAL); if(startBtnEl){ startBtnEl.innerText = "正在翻动书本"; startBtnEl.style.background = "#28a745"; } } // 停止阅读 function stopAuto() { if (!timer) return; clearInterval(timer); timer = null; if(startBtnEl){ startBtnEl.innerText = "开始阅读"; startBtnEl.style.background = "#007bff"; } } // 修改+保存秒数 function updateSec(sec) { if (!sec || isNaN(sec) || sec <= 0) { alert('请输入大于0的有效数字'); return; } // 保存到本地 localStorage.setItem("autoReaderSaveSec", sec); CLICK_INTERVAL = sec * 1000; // 重启计时 if (timer) { stopAuto(); startAuto(); } alert(`已保存:每 ${sec} 秒翻动书本,下次刷新保留设置`); } // 创建可拖动面板 function addDragPanel() { if (document.getElementById('autoReaderPanel')) return; const panel = document.createElement('div'); panel.id = 'autoReaderPanel'; panel.style.cssText = ` position: absolute; top: 60px; right: 10px; z-index: 999999; background: #fff; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); font-size: 14px; padding: 10px; user-select: none; width: 220px; `; // 拖动标题栏 const dragHead = document.createElement('div'); dragHead.innerText = '📖 自动阅读器(按住拖动)'; dragHead.style.cssText = ` background: #007bff; color: #fff; padding: 6px; border-radius: 6px; text-align: center; cursor: move; margin: -10px -10px 10px -10px; `; // 秒数输入行 const descLine = document.createElement('div'); descLine.style.cssText = `display:flex;align-items:center;gap:6px;margin-bottom:8px;`; descLine.innerHTML = ` 秒翻动书本`; // 按钮区 const btnLine = document.createElement('div'); btnLine.style.cssText = `display:flex;gap:6px;flex-wrap:wrap;`; const changeBtn = document.createElement('button'); changeBtn.innerText = '更改秒数'; changeBtn.style.cssText = `padding:4px 8px;background:#28a745;color:#fff;border:none;border-radius:4px;cursor:pointer;`; changeBtn.onclick = ()=>{ const val = document.getElementById('secInput').value.trim(); updateSec(Number(val)); }; startBtnEl = document.createElement('button'); startBtnEl.innerText = "开始阅读"; startBtnEl.style.cssText = `padding:4px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;`; startBtnEl.onclick = startAuto; const stopBtn = document.createElement('button'); stopBtn.innerText = "停止"; stopBtn.style.cssText = `padding:4px 8px;background:#6c757d;color:#fff;border:none;border-radius:4px;cursor:pointer;`; stopBtn.onclick = stopAuto; btnLine.append(changeBtn, startBtnEl, stopBtn); panel.append(dragHead, descLine, btnLine); // 挂载页面 const container = document.querySelector('#recordDiv')?.parentElement || document.body; container.appendChild(panel); // 拖拽逻辑 dragHead.addEventListener('mousedown', e=>{ dragOffsetX = e.clientX - panel.offsetLeft; dragOffsetY = e.clientY - panel.offsetTop; document.addEventListener('mousemove', move); document.addEventListener('mouseup', endDrag); }); function move(e){ panel.style.left = (e.clientX - dragOffsetX) + 'px'; panel.style.top = (e.clientY - dragOffsetY) + 'px'; panel.style.right = 'auto'; } function endDrag(){ document.removeEventListener('mousemove', move); document.removeEventListener('mouseup', endDrag); } } // 页面加载:自动加载面板 + 自动启动阅读 window.addEventListener('load', ()=>{ setTimeout(()=>{ addDragPanel(); startAuto(); // 刷新/进课本 直接自动读 }, 1200); }); })();