✨ 图标服务新增「禁用」档,彻底关闭 favicon 获取 - #1637
Merged
Merged
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.
Checklist / 检查清单
背景
打开脚本猫时会按脚本的
@match/@include域名逐个请求 favicon。@match多的脚本(issue 里举例的 Bypass All Shortlinks Debloated 有 500+)会一次性产生大量外部请求,触发安全软件拦截;NSFW / 重定向类脚本的域名被请求还有隐私与审计风险。#1268 之后用户只能在几个图标服务之间切换,没有真正关掉的选项——这正是 #1255 被重开的原因。
本次改动
按 @cyfung1031 的 UI 建议,不新增设置行,直接在「设置 → 界面 → 图标服务」下拉里加一档「禁用」:
FaviconService增加"none"(src/pkg/config/config.ts)loadScriptFavicons在none时直接返回:不读写 favicon 缓存,也不发起任何请求(src/pages/store/favicons.ts)favicon_service_none@connect域名图标同样遵守该开关(见「实现考虑」)默认值不变,仍是 ScriptCat 图标服务;老用户行为不受影响。
实现考虑
fetchIconByService也显式处理"none":该 switch 原本是case "local": default:,任何未处理的取值都会落到「直连目标站点抓 HTML 解析 icon」这条最重的路径上。只在上层拦截、不补这个 case,等于给后续调用者留了个反向默认值的坑。@connect图标是另一条直连路径:SubscribeList一直是<img src="https://<domain>/favicon.ico">直接打目标站,不走图标服务。不管它,「禁用」就名不副实,所以本次让它遵守none。由于配置是异步读出来的,
<img>一旦挂载请求就已经发出去了,撤下来也晚了——因此配置就绪前一律先渲染地球占位。FaviconDots无数据即返回null,列表不留空位。已知限制
@connect图标在非禁用档位下仍然直连站点,没有改走所选图标服务。这是既有行为,不在本次范围内。建议审查重点
loadScriptFavicons的提前返回是否漏掉了别的 favicon 入口(当前该函数是脚本列表侧唯一调用点)。docs/references/terminology-<locale>.md的 enable/disable 术语。验证
单测(先写失败用例再实现):
src/pages/store/favicons.test.ts—loadScriptFavicons(scripts, "none")零产出且不调用fetch;fetchIconByService(domain, "none")返回[]src/pages/options/routes/Setting/sections/InterfaceSection.test.tsx— 配置值为none时下拉回显「禁用」src/pages/options/routes/SubscribeList/components.test.tsx(新增)— 禁用时不渲染<img>,启用时正常渲染命令与结果:
真机验证(
e2e/scratch/一次性脚本驱动dist/ext,4 条@match的脚本,两个用例各用全新 profile;「禁用」用例先改设置再装脚本,排除命中既有缓存):favicon requests = [],列表正常渲染、不再显示站点图标。Screenshots / 截图
关联
Close #1255