// ==UserScript== // @name 知乎自动展开全文 // @namespace http://tampermonkey.net/ // @version 1.1.2 // @description 帮助自动去除点击链接时的弹窗和自动展开全文 // @author hukker // @match https://zhuanlan.zhihu.com/p/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== // 公开声明: // 本脚本旨在改善用户在知乎文章页面的浏览体验, // 自动删除调试代码遮挡的div标签,并防止点击链接时弹出登录窗口。 // 使用本脚本需遵循相关网站的使用条款, // 本人不对因使用本脚本而导致的任何问题负责。 (function() { 'use strict'; // 等待页面加载完成 window.addEventListener('load', function() { // 查找并删除具有特定类名格式的div标签 const debugDivs = document.querySelectorAll('div[class^="css-fxar"]'); // 匹配以css-fxar开头的类名 debugDivs.forEach(div => div.remove()); // 防止点击链接时弹出登录窗口 const links = document.querySelectorAll('a'); // 获取所有链接 links.forEach(link => { link.addEventListener('click', function(event) { // 检查链接是否需要登录 if (link.href.includes('login')) { // 根据实际情况修改条件 event.preventDefault(); // 阻止默认行为 alert('请先登录后访问该链接。'); // 提示用户 } }); }); // 自动去除登录窗口和其他元素 const removeElements = () => { const elementsToRemove = [ '.signFlowModal-container', '.Modal-backdrop', '.wucaiCommentIcon', '.Button.Modal-closeButton', '.Modal-wrapper.undefined.Modal-enter-done' // 新增的元素 ]; elementsToRemove.forEach(selector => { const element = document.querySelector(selector); if (element) { element.remove(); // 直接删除元素 } }); }; // 定时检查并移除指定元素 setInterval(removeElements, 500); // 每500毫秒检查一次,提升响应速度 // 自动展开全文 const expandContent = () => { const expandButton = document.querySelector('.Button--expand'); // 根据实际的展开按钮类名修改 if (expandButton) { expandButton.click(); // 点击展开按钮 } }; // 调用自动展开函数 expandContent(); }); })();