彩虹文本编辑器
添加新文本框
编程
python
目录 3
于慧
中综
单词新
省考
记忆
命名
修改目录名称
选择要修改的目录
编程
python
目录 3
于慧
中综
单词新
省考
记忆
新显示名称
提示:仅允许中文、字母、数字、下划线、空格,长度1-10
取消
确认修改
// ==UserScript== // @name 知乎一键展开阅读全文(自动展开+固定间隔滚动) // @namespace https://github.com/yourname/zhihu-scripts // @version 2.3 // @description 基于"阅读全文"文本匹配,一键展开+实时计数+5秒固定间隔滚动(400px/次,每10次滑到底部并自动展开,60次失败自动停止) // @author 自定义名称 // @match *://*.zhihu.com/* // @icon https://static.zhihu.com/heifetz/favicon.ico // @grant none // @run-at document-end // @noframes // @license MIT // ==/UserScript== (function() { 'use strict'; // ===================== 全局状态与配置 ===================== const EXPAND_TEXT_KEYWORDS = ['阅读全文', '展开全文', '展开', '查看更多', '显示全部']; // 展开相关状态 let isAutoMode = false; let autoCheckTimer = null; const clickedButtonCache = new Set(); let totalExpandCount = 0; // 滚动相关状态(核心调整) let isAutoScroll = false; // 自动滚动开关 let autoScrollTimer = null; // 自动滚动定时器 const SCROLL_DELAY = 5; // 固定滚动间隔(秒) const SCROLL_STEP = 400; // 单次滚动像素(400px/次) const MAX_FAILED_ATTEMPTS = 60;// 最大连续失败次数 let failedAttempts = 0; // 连续失败计数 let scrollAttempts = 0; // 累计单次滚动次数(每10次滑到底部) const SCROLL_TO_BOTTOM_AFTER = 10; // 每N次单次滚动后滑到底部 // ===================== 工具函数 ===================== // 检查元素是否可见 function isElementVisible(el) { if (!el || el.nodeType !== 1) return false; const style = window.getComputedStyle(el); return ( style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0' && el.offsetParent !== null && el.clientWidth > 0 && el.clientHeight > 0 ); } // 模拟真人点击 function simulateRealClick(el) { if (!el || !isElementVisible(el)) return false; el.scrollIntoView({ behavior: 'instant', block: 'nearest' }); const mouseEvents = [ new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window, button: 0, buttons: 1 }), new MouseEvent('mouseup', { bubbles: true, cancelable: true, view: window, button: 0, buttons: 0 }), new MouseEvent('click', { bubbles: true, cancelable: true, view: window, button: 0 }) ]; try { mouseEvents.forEach(event => el.dispatchEvent(event)); return true; } catch (e) { return false; } } // 根据文本查找所有未点击的展开按钮 function findNewExpandButtons() { const newButtons = []; const xpathBase = "//*[self::button or self::div or self::span][@role='button' or @class][not(@disabled)]"; EXPAND_TEXT_KEYWORDS.forEach(keyword => { const xpath = `${xpathBase}[contains(text(), '${keyword}') or contains(@aria-label, '${keyword}')]`; const nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (let i = 0; i < nodes.snapshotLength; i++) { const el = nodes.snapshotItem(i); if (isElementVisible(el) && !clickedButtonCache.has(el)) { newButtons.push(el); } } }); return newButtons; } // 滑到页面底部并自动展开全文(核心新增) function scrollToBottomAndExpand() { // 1. 滑到页面底部(instant=立即,smooth=平滑) window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' }); console.log(`✅ 累计${SCROLL_TO_BOTTOM_AFTER}次单次滚动,已自动滑到页面底部`); // 2. 延迟500ms执行展开(等待新内容加载) setTimeout(() => { const expandCount = batchExpand(); if (expandCount > 0) { console.log(`✅ 滑到底部后自动展开:本次展开${expandCount}个内容,累计展开${totalExpandCount}个`); // 可选:桌面通知(需授权) if (Notification.permission === 'granted') { new Notification('知乎自动展开', { body: `滑到底部后自动展开${expandCount}个新内容,累计展开${totalExpandCount}个` }); } } else { console.log(`ℹ️ 滑到底部后自动展开:暂无新的「阅读全文」按钮`); } }, 500); } // ===================== 展开计数显示 ===================== function updateExpandCountDisplay() { const countBadge = document.getElementById('zhihu-expand-count-badge'); const expandBtn = document.getElementById('zhihu-expand-all-btn'); if (!countBadge || !expandBtn) return; if (totalExpandCount > 0) { countBadge.textContent = totalExpandCount; countBadge.style.display = 'flex'; expandBtn.title = isAutoMode ? `当前:自动展开模式(累计展开${totalExpandCount}个),再次点击关闭` : `点击展开所有含「阅读全文」的内容(累计展开${totalExpandCount}个),点击后开启自动模式`; } else { countBadge.textContent = ''; countBadge.style.display = 'none'; expandBtn.title = isAutoMode ? '当前:自动展开模式(暂无展开),再次点击关闭' : '点击展开所有含「阅读全文」的内容,点击后开启自动模式'; } } function resetExpandCount() { totalExpandCount = 0; clickedButtonCache.clear(); updateExpandCountDisplay(); } // ===================== 核心展开逻辑 ===================== function batchExpand() { let expandCount = 0; const newButtons = findNewExpandButtons(); newButtons.forEach(btn => { const success = simulateRealClick(btn); if (success) { expandCount++; clickedButtonCache.add(btn); } }); if (expandCount > 0) { totalExpandCount += expandCount; updateExpandCountDisplay(); console.log(`✅ 本次展开${expandCount}个,累计展开${totalExpandCount}个`); } return expandCount; } function autoCheckAndExpand() { const newCount = batchExpand(); if (newCount > 0 && Notification.permission === 'granted') { new Notification('知乎自动展开', { body: `自动展开${newCount}个新内容,累计展开${totalExpandCount}个` }); } } function toggleAutoMode() { const expandBtn = document.getElementById('zhihu-expand-all-btn'); if (!expandBtn) return; if (!isAutoMode) { isAutoMode = true; expandBtn.textContent = '自动'; expandBtn.style.background = '#00cc88 !important'; const firstCount = batchExpand(); const firstTip = firstCount === 0 ? `✅ 已开启自动展开模式\n当前无新的「阅读全文」按钮(累计展开${totalExpandCount}个)` : `✅ 已开启自动展开模式\n首次展开${firstCount}个,累计${totalExpandCount}个,后续会自动监测新内容`; alert(firstTip); autoCheckTimer = setInterval(autoCheckAndExpand, 2000); } else { isAutoMode = false; expandBtn.textContent = '展开'; expandBtn.style.background = '#0084ff !important'; clearInterval(autoCheckTimer); autoCheckTimer = null; alert(`✅ 已关闭自动展开模式\n本次会话累计展开${totalExpandCount}个内容`); updateExpandCountDisplay(); } } // ===================== 核心调整:固定间隔自动滚动(滑底后自动展开) ===================== // 检测滚动是否成功(核心判断) function isScrollSuccess() { // 滚动前位置 const prevScrollY = window.scrollY; // 执行单次向下滚动(400px) window.scrollBy(0, SCROLL_STEP); // 立即检测滚动后位置(scrollBy是同步操作) const currScrollY = window.scrollY; // 滚动成功:位置发生变化(说明能向下滚动) return currScrollY > prevScrollY; } // 自动滚动核心执行函数(递归设置定时器) function autoScrollExecute() { if (!isAutoScroll) return; // 已关闭则终止 // 执行单次滚动并判断结果 const scrollSuccess = isScrollSuccess(); if (scrollSuccess) { // 滚动成功:重置连续失败计数 failedAttempts = 0; console.log(`✅ 滚动成功(400px),下次间隔${SCROLL_DELAY}秒`); } else { // 滚动失败:累计失败次数 failedAttempts++; console.log(`❌ 滚动失败,连续失败${failedAttempts}/${MAX_FAILED_ATTEMPTS}次,下次间隔${SCROLL_DELAY}秒重试`); // 检查是否达到最大失败次数 if (failedAttempts >= MAX_FAILED_ATTEMPTS) { // 60次失败,彻底停止 toggleAutoScroll(); // 关闭自动滚动 alert(`❌ 连续${MAX_FAILED_ATTEMPTS}次滚动失败,已达到最大重试次数,自动停止滚动`); return; } } // 累计单次滚动次数,每10次滑到底部并展开 scrollAttempts++; if (scrollAttempts >= SCROLL_TO_BOTTOM_AFTER) { scrollToBottomAndExpand(); // 替换为滑底+展开函数 scrollAttempts = 0; // 重置计数 } // 更新滚动按钮提示(显示失败次数+累计滚动次数) updateScrollBtnTip(); // 设置下一次滚动定时器(固定5秒间隔) autoScrollTimer = setTimeout(autoScrollExecute, SCROLL_DELAY * 1000); } // 更新滚动按钮提示文字 function updateScrollBtnTip() { const scrollBtn = document.getElementById('zhihu-scroll-btn'); if (!scrollBtn) return; if (isAutoScroll) { scrollBtn.title = `当前:自动滚动中(5秒/次,400px/次),连续失败${failedAttempts}/${MAX_FAILED_ATTEMPTS}次,已滚动${scrollAttempts}/${SCROLL_TO_BOTTOM_AFTER}次(满10次滑到底部并自动展开)(点击停止)`; } else { scrollBtn.title = '点击开启自动向下滚动(5秒/次,400px/次,每10次滑到底部并自动展开,60次失败自动停止)'; } } // 切换自动滚动模式(调整:重置滚动次数计数) function toggleAutoScroll() { const scrollBtn = document.getElementById('zhihu-scroll-btn'); if (!scrollBtn) return; if (!isAutoScroll) { // 开启自动滚动:重置所有计数 isAutoScroll = true; failedAttempts = 0; scrollAttempts = 0; // 重置单次滚动计数 scrollBtn.textContent = '停止'; scrollBtn.style.background = '#ff7a45 !important'; updateScrollBtnTip(); // 立即执行第一次滚动,然后启动递归定时器 autoScrollExecute(); } else { // 停止自动滚动 isAutoScroll = false; scrollBtn.textContent = '滚动'; scrollBtn.style.background = '#ff9500 !important'; updateScrollBtnTip(); // 清除定时器 clearTimeout(autoScrollTimer); autoScrollTimer = null; alert(`✅ 已手动停止自动滚动(本次连续失败${failedAttempts}次,累计滚动${scrollAttempts}次)`); } } // 强制停止自动滚动(用于URL变化/页面卸载) function stopAutoScroll() { if (isAutoScroll) { clearTimeout(autoScrollTimer); isAutoScroll = false; failedAttempts = 0; // 重置失败计数 scrollAttempts = 0; // 重置单次滚动计数 const scrollBtn = document.getElementById('zhihu-scroll-btn'); if (scrollBtn) { scrollBtn.textContent = '滚动'; scrollBtn.style.background = '#ff9500 !important'; updateScrollBtnTip(); } } } // ===================== 悬浮按钮创建 ===================== function createExpandButton() { const existingBtn = document.getElementById('zhihu-expand-all-btn'); if (existingBtn) { existingBtn.style.display = 'block'; if (isAutoMode) { existingBtn.textContent = '自动'; existingBtn.style.background = '#00cc88 !important'; } else { existingBtn.textContent = '展开'; existingBtn.style.background = '#0084ff !important'; } updateExpandCountDisplay(); return; } // 1. 创建展开主按钮 const expandBtn = document.createElement('button'); expandBtn.id = 'zhihu-expand-all-btn'; expandBtn.style.cssText = ` position: fixed !important; right: 20px !important; bottom: 20px !important; width: 50px !important; height: 50px !important; border-radius: 50% !important; background: #0084ff !important; color: #ffffff !important; border: none !important; outline: none !important; font-size: 14px !important; cursor: pointer !important; z-index: 99999 !important; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15) !important; transition: background-color 0.2s ease !important; opacity: 1 !important; visibility: visible !important; display: flex !important; align-items: center !important; justify-content: center !important; `; expandBtn.textContent = '展开'; expandBtn.title = '点击展开所有含「阅读全文」的内容,点击后开启自动模式'; // 展开计数徽章 const countBadge = document.createElement('span'); countBadge.id = 'zhihu-expand-count-badge'; countBadge.style.cssText = ` position: absolute !important; top: -5px !important; right: -5px !important; width: 20px !important; height: 20px !important; border-radius: 50% !important; background: #ff3b30 !important; color: #ffffff !important; font-size: 12px !important; font-weight: bold !important; display: none !important; align-items: center !important; justify-content: center !important; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) !important; `; expandBtn.appendChild(countBadge); // 展开按钮hover效果 expandBtn.addEventListener('mouseover', () => { if (isAutoMode) { expandBtn.style.background = '#00aa77 !important'; } else { expandBtn.style.background = '#0066cc !important'; } }); expandBtn.addEventListener('mouseout', () => { if (isAutoMode) { expandBtn.style.background = '#00cc88 !important'; } else { expandBtn.style.background = '#0084ff !important'; } }); expandBtn.addEventListener('click', toggleAutoMode); document.body.appendChild(expandBtn); updateExpandCountDisplay(); } // 创建自动滚动按钮 function createScrollButton() { const existingBtn = document.getElementById('zhihu-scroll-btn'); if (existingBtn) { existingBtn.style.display = 'block'; if (isAutoScroll) { existingBtn.textContent = '停止'; existingBtn.style.background = '#ff7a45 !important'; } else { existingBtn.textContent = '滚动'; existingBtn.style.background = '#ff9500 !important'; } updateScrollBtnTip(); return; } // 创建滚动按钮(位于展开按钮上方80px处) const scrollBtn = document.createElement('button'); scrollBtn.id = 'zhihu-scroll-btn'; scrollBtn.style.cssText = ` position: fixed !important; right: 20px !important; bottom: 80px !important; /* 与展开按钮间距60px */ width: 50px !important; height: 50px !important; border-radius: 50% !important; background: #ff9500 !important; /* 橙色主题 */ color: #ffffff !important; border: none !important; outline: none !important; font-size: 14px !important; cursor: pointer !important; z-index: 99999 !important; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15) !important; transition: background-color 0.2s ease !important; opacity: 1 !important; visibility: visible !important; display: flex !important; align-items: center !important; justify-content: center !important; `; scrollBtn.textContent = '滚动'; updateScrollBtnTip(); // 滚动按钮hover效果 scrollBtn.addEventListener('mouseover', () => { if (isAutoScroll) { scrollBtn.style.background = '#ff6a30 !important'; } else { scrollBtn.style.background = '#e68a00 !important'; } }); scrollBtn.addEventListener('mouseout', () => { if (isAutoScroll) { scrollBtn.style.background = '#ff7a45 !important'; } else { scrollBtn.style.background = '#ff9500 !important'; } }); // 绑定滚动模式切换 scrollBtn.addEventListener('click', toggleAutoScroll); document.body.appendChild(scrollBtn); } // ===================== 页面监听与初始化 ===================== function monitorPageChanges() { let lastUrl = window.location.href; // 监听URL变化(知乎单页应用) setInterval(() => { if (window.location.href !== lastUrl) { lastUrl = window.location.href; // 切换页面:重置所有状态 if (isAutoMode) { clearInterval(autoCheckTimer); isAutoMode = false; } stopAutoScroll(); // 停止自动滚动 resetExpandCount(); createExpandButton(); createScrollButton(); } }, 800); // 滚动时确保按钮存在 let scrollTimer = null; window.addEventListener('scroll', () => { clearTimeout(scrollTimer); scrollTimer = setTimeout(() => { const expandBtn = document.getElementById('zhihu-expand-all-btn'); const scrollBtn = document.getElementById('zhihu-scroll-btn'); if (!expandBtn) createExpandButton(); if (!scrollBtn) createScrollButton(); }, 500); }); } // 初始化桌面通知权限 function initNotificationPermission() { if (Notification.permission !== 'granted' && Notification.permission !== 'denied') { Notification.requestPermission(); } } function init() { initNotificationPermission(); // 初始化两个按钮 const initHandler = () => { createExpandButton(); createScrollButton(); monitorPageChanges(); }; if (document.readyState === 'complete' || document.readyState === 'interactive') { initHandler(); } else { document.addEventListener('DOMContentLoaded', initHandler); } window.addEventListener('load', initHandler); setTimeout(initHandler, 1500); // 页面卸载时清理所有定时器 window.addEventListener('beforeunload', () => { clearInterval(autoCheckTimer); clearTimeout(autoScrollTimer); }); } init(); })();
字数: 20984
最后保存于 2026-03-16 16:36:27
接下来我会发送代码给你,请你记住并分析其功能,并且介绍其前端显示效果和具体操作逻辑。
字数: 324
最后保存于 2025-12-23 16:44:24
请基于PHP5.6实现以下功能,并且优先在一个PHP文件实现以下功能,
字数: 87
最后保存于 2025-12-23 16:57:27
编写一个数字记忆网页程序,可选20,40,60,80,100,数字记忆。点击可分别选取本次记忆数字,选取后显示数字,之后可点击开始按钮开始计时,用户之后点击暂停后记录记忆时间,显示的数字消失,用户通过下方按钮进行回答,页面下方分为两列按钮,上方为1到5,下方为6到0,用户每点击一个数字上方显示一个数字并判断是否正确(正确在数字外显示绿色外框,错误红色)。并实时计算正确率。用户全部完成后将要本次数据保留在data.csv文件中。
字数: 599
最后保存于 2025-12-24 14:50:22
生成100个常见名词,如,苹果、西瓜
字数: 48
最后保存于 2025-12-24 15:13:31