新增 [标记仅自己可见的评论] 功能#600
Open
sakaiyuuji4 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能改动
评测结果
对加载速度的影响:几乎没有
MutationObserver、初次 rescan 一次,没有任何同步的重活。
是在另一条分离的异步链里处理,不会阻塞页面自己接收响应。
持续开销:小,但“不为零”(唯一需要注意的点
observer.observe(document, {childList:true, subtree:true}) 在所有页面常驻,刷信息流时每次插入都会触发回调。
→ 但这个脚本本身就已经在跑 6~10 个同类的全文档监听器(blockKeywords/blockUsers/blockType/closeFloatingComments
等),我加的这个跟它们完全同类,不是新增的瓶颈。
回调会找 people/...>img.Avatar,但头像在评论之外(信息流作者、悬浮卡片等)也有。每次都试着
node.querySelector('.CommentContent'),是 null 就立即返回,单次几十微秒的空转,和脚本里现有的评论监听行为一样。
会跑一次
document.querySelectorAll(...),但评论接口只在用户操作时才请求(展开评论、加载更多),就几次而已。每次复杂度是
O(页面头像数),几百个元素也就几毫秒;已标记的有 dataset.zhihuEVis 守卫会直接跳过。
内存方面,只缓存 is_visible_only_to_myself === true 的评论(也就是你自己不可见的那些),数量极小。