{rows.length === 0 ? (
diff --git a/src/pages/install/components/PermissionRow.test.tsx b/src/pages/install/components/PermissionRow.test.tsx
index 5fb316c8e..5dffa628b 100644
--- a/src/pages/install/components/PermissionRow.test.tsx
+++ b/src/pages/install/components/PermissionRow.test.tsx
@@ -77,7 +77,7 @@ describe("PermissionRow 更新差异态", () => {
risk: "danger" as const,
values: ["*", "api.a.com", "api.b.com"],
sensitive: [],
- diff: { added: ["*"], removed: ["old.a.com"] },
+ diff: { added: ["*"], removed: ["old.a.com"], updated: [] },
};
it("新增与移除的取值常驻可见,未变动的收进折叠桶", () => {
@@ -116,7 +116,13 @@ describe("PermissionRow 更新差异态", () => {
it("差异为空的行不渲染变动计数,取值全部按未变动呈现", () => {
render(
);
const row = screen.getByTestId("permission-row");
@@ -131,14 +137,14 @@ describe("PermissionRow 零变动行的取值折叠", () => {
risk: "normal" as const,
values: ["https://a.com/*", "https://b.com/*", "https://c.com/*", "https://d.com/*"],
sensitive: [],
- diff: { added: [], removed: [] },
+ diff: { added: [], removed: [], updated: [] },
};
it("没有可钉住的增删时,取值仍按 maxVisible 折叠为 +N", () => {
render(
);
const row = screen.getByTestId("permission-row");
- expect(within(row).getByText("https://a.com/*")).toBeInTheDocument();
- expect(within(row).queryByText("https://c.com/*")).not.toBeInTheDocument();
+ expect(within(row).getByTitle("https://a.com/*")).toBeInTheDocument();
+ expect(within(row).queryByTitle("https://c.com/*")).not.toBeInTheDocument();
expect(within(row).getByTestId("permission-more")).toHaveTextContent("+2");
});
@@ -146,7 +152,7 @@ describe("PermissionRow 零变动行的取值折叠", () => {
render(
);
const row = screen.getByTestId("permission-row");
fireEvent.click(within(row).getByTestId("permission-more"));
- expect(within(row).getByText("https://d.com/*")).toBeInTheDocument();
+ expect(within(row).getByTitle("https://d.com/*")).toBeInTheDocument();
expect(within(row).queryByTestId("permission-more")).not.toBeInTheDocument();
});
});
@@ -212,7 +218,7 @@ describe("PermissionRow 上的不生效标记", () => {
risk: "warn",
values: ["GM_setValue"],
sensitive: [],
- diff: { added: [], removed: ["GM_audio"] },
+ diff: { added: [], removed: ["GM_audio"], updated: [] },
}}
compat={compat({ grants: new Map([["GM_audio", 9]]) })}
/>
@@ -249,7 +255,7 @@ describe("PermissionRow 上的仅限脚本猫标记", () => {
risk: "warn",
values: ["GM_setValue"],
sensitive: [],
- diff: { added: [], removed: ["CAT_fileStorage"] },
+ diff: { added: [], removed: ["CAT_fileStorage"], updated: [] },
}}
/>
);
@@ -304,7 +310,7 @@ describe("不生效标记不会被折叠藏起来", () => {
risk: "warn",
values: ["GM_getValue", "GM_setValue", "GM_audio"],
sensitive: [],
- diff: { added: ["GM_getValue"], removed: [] },
+ diff: { added: ["GM_getValue"], removed: [], updated: [] },
}}
compat={marks([["GM_audio", 9]])}
/>
@@ -323,7 +329,7 @@ describe("不生效标记不会被折叠藏起来", () => {
risk: "warn",
values: ["GM_setValue", "GM_getValue", "GM_audio"],
sensitive: [],
- diff: { added: [], removed: [] },
+ diff: { added: [], removed: [], updated: [] },
}}
maxVisible={1}
compat={marks([["GM_audio", 9]])}
@@ -333,3 +339,176 @@ describe("不生效标记不会被折叠藏起来", () => {
expect(screen.getByTestId("permission-more")).toHaveTextContent("+1");
});
});
+
+describe("PermissionRow 更新态的行头", () => {
+ it("更新态只给变动数,不再给类别总数徽章;全新安装仍显示总数", () => {
+ const { rerender } = render(
+
+ );
+ expect(screen.queryByTestId("permission-count")).not.toBeInTheDocument();
+ rerender(
);
+ expect(screen.getByTestId("permission-count")).toHaveTextContent("1");
+ });
+});
+
+describe("PermissionRow 变动取值的配色", () => {
+ it("普通新增用新增色记号,危险与敏感的新增沿用风险色,不被染成新增色", () => {
+ render(
+ <>
+
+
+ >
+ );
+ const glyph = (value: string) =>
+ within(screen.getByText(value).closest("[data-chip]") as HTMLElement).getByText("+");
+ expect(glyph("GM_addStyle")).toHaveClass("text-success-fg");
+ expect(glyph("*")).not.toHaveClass("text-success-fg");
+ expect(glyph("GM_cookie")).not.toHaveClass("text-success-fg");
+ });
+
+ it("移除、更新、行头计数与折叠按钮都不用风险色或强调色——红色只留给危险取值", () => {
+ render(
+
+ );
+ const row = screen.getByTestId("permission-row");
+ expect(screen.getByText("未变动 1 项")).toBeInTheDocument();
+ expect(row.querySelectorAll('[class*="destructive"], [class*="primary"]')).toHaveLength(0);
+ });
+});
+
+describe("PermissionRow 只换了查询参数的外部资源", () => {
+ const row = {
+ kind: "require" as const,
+ risk: "normal" as const,
+ values: ["https://cdn.a.com/x/lib.js?v1.3.0"],
+ sensitive: [],
+ diff: {
+ added: [],
+ removed: [],
+ updated: [{ from: "https://cdn.a.com/x/lib.js?v1.2.0", to: "https://cdn.a.com/x/lib.js?v1.3.0" }],
+ },
+ };
+
+ it("合并成一条更新,给出旧参数到新参数,并计入行头的更新数", () => {
+ render(
);
+ const chip = screen.getByTitle("https://cdn.a.com/x/lib.js?v1.3.0").closest("[data-chip]") as HTMLElement;
+ expect(chip).toHaveAttribute("data-change", "updated");
+ expect(within(chip).getByText("?v1.2.0")).toBeInTheDocument();
+ expect(within(chip).getByText("?v1.3.0")).toBeInTheDocument();
+ expect(within(chip).getByText("已更新")).toBeInTheDocument();
+ expect(screen.getByTestId("permission-delta")).toHaveTextContent("~1");
+ expect(screen.queryByTestId("permission-more")).not.toBeInTheDocument();
+ });
+});
+
+describe("PermissionRow 增删很多时的截断", () => {
+ const many = (n: number) => Array.from({ length: n }, (_, i) => `https://s${i + 1}.com/*`);
+
+ it("新增超过 8 条时只显示前 8 条,其余收进「再显示 N 项新增」,点开后全部可见", () => {
+ const added = many(10);
+ render(
+
+ );
+ expect(screen.getByTitle("https://s8.com/*")).toBeInTheDocument();
+ expect(screen.queryByTitle("https://s9.com/*")).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: /再显示 2 项新增/ }));
+ expect(screen.getByTitle("https://s10.com/*")).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /项新增/ })).not.toBeInTheDocument();
+ });
+
+ it("危险与敏感的新增取值永远不被收起", () => {
+ const added = ["GM_a", "GM_b", "GM_c", "GM_cookie"];
+ render(
+
+ );
+ expect(screen.getByText("GM_cookie")).toBeInTheDocument();
+ expect(screen.queryByText("GM_c")).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /再显示 1 项新增/ })).toBeInTheDocument();
+ });
+
+ it("移除超过 8 条时只显示前 8 条,其余收进「再显示 N 项已移除」", () => {
+ const removed = many(9);
+ render(
+
+ );
+ expect(screen.queryByTitle("https://s9.com/*")).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: /再显示 1 项已移除/ }));
+ expect(screen.getByTitle("https://s9.com/*")).toBeInTheDocument();
+ });
+});
+
+describe("PermissionRow 地址类取值的展示", () => {
+ const value = "https://greasyfork.org/scripts/435207/code/GitHub%20%E4%B8%AD%E6%96%87.js?v1.9.2";
+
+ it("地址解码后单行展示,域名单独突出,悬停给出原文", () => {
+ render(
);
+ const toggle = screen.getByTitle(value);
+ expect(within(toggle).getByText("greasyfork.org")).toBeInTheDocument();
+ expect(within(toggle).getByText("/GitHub 中文.js?v1.9.2")).toBeInTheDocument();
+ expect(toggle).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("点击后展开为完整地址,再点收起", () => {
+ render(
);
+ fireEvent.click(screen.getByTitle(value));
+ expect(screen.getByTitle(value)).toHaveAttribute("aria-expanded", "true");
+ expect(screen.getByText("https://greasyfork.org/scripts/435207/code/GitHub 中文.js?v1.9.2")).toBeInTheDocument();
+ fireEvent.click(screen.getByTitle(value));
+ expect(screen.getByTitle(value)).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("跨域访问与 GM 能力的取值不是地址,保持原样", () => {
+ render(
);
+ expect(screen.getByText("api.a.com")).toBeInTheDocument();
+ expect(screen.queryByTitle("api.a.com")).not.toBeInTheDocument();
+ });
+});
diff --git a/src/pages/install/components/PermissionRow.tsx b/src/pages/install/components/PermissionRow.tsx
index 67cbf00fc..bce5b1dce 100644
--- a/src/pages/install/components/PermissionRow.tsx
+++ b/src/pages/install/components/PermissionRow.tsx
@@ -6,8 +6,10 @@ import { isScriptCatOnlyGrant } from "@App/pkg/utils/script_compat";
import { isMarkedValue, type CompatView } from "../compat";
import { catApiDocHref, metadataDocHref } from "../compat_docs";
import { CompatChip, ScriptCatOnlyBadge } from "./CompatChip";
+import { splitUrlForDisplay } from "../url_display";
import {
isPermissionChanged,
+ type PermissionUpdate,
type PermissionKind,
type PermissionRisk,
type PermissionRow as PermissionRowData,
@@ -22,7 +24,7 @@ export const KIND_META: Record
= {
normal: {
@@ -44,30 +46,82 @@ export const RISK_STYLE: Record = {
added: "install:perm_change_added",
removed: "install:perm_change_removed",
unchanged: "install:perm_change_unchanged",
+ updated: "install:perm_change_updated",
};
+const URL_KINDS = new Set(["match", "require"]);
+
+/**
+ * 地址类取值单行展示:域名与文件名加参数(版本号通常就在这里)常驻,中段路径优先被省略;
+ * 点击展开为完整地址。@require 默认的 https:// 不占位置,http:// 等其他协议照常显示——明文加载值得被看见。
+ */
+function UrlValue({
+ value,
+ kind,
+ title = value,
+ muted,
+}: {
+ value: string;
+ kind: PermissionKind;
+ title?: string;
+ muted?: boolean;
+}) {
+ const [open, setOpen] = useState(false);
+ const parts = URL_KINDS.has(kind) ? splitUrlForDisplay(value) : null;
+ if (!parts) return {value};
+ const { prefix, scheme, host, middle, tail } = parts;
+ const showScheme = !(kind === "require" && scheme === "https://");
+
+ return (
+
+ );
+}
+
function Chip({ value, row, change }: { value: string; row: PermissionRowData; change?: ChangeState }) {
const { t } = useTranslation(["install", "common"]);
const isSensitive = row.sensitive.includes(value);
// 装在脚本猫里能用,但换到别的脚本管理器就不行了;已移除的取值不再属于新版本,不标
const isScriptCatOnly = row.kind === "grant" && change !== "removed" && isScriptCatOnlyGrant(value);
- const base = isSensitive ? "border border-warning-fg bg-muted text-warning-fg" : RISK_STYLE[row.risk].chip;
+ const base = isSensitive ? "border border-warning-fg/60 bg-warning-bg text-warning-fg" : RISK_STYLE[row.risk].chip;
+ // 色相只表达风险,变动只靠对比度与 +/− 记号:移除权限是好事,若也用红,就和 @connect * 这类真正该警觉的取值混在一起;
+ // 反过来新增的 @connect * 若被染成新增色,最该报警的情况就被伪装成了安全的
+ const riskTone = isSensitive || row.risk === "danger";
- // 变动状态只用字重、描边与 +/− 记号表达,底色继续留给风险等级——
- // 否则新增的 @connect * 会被染成「新增色」,把最该报警的情况伪装成安全的。
const changeClass =
change === "removed"
- ? "border border-border bg-transparent text-muted-foreground line-through"
+ ? "border border-transparent bg-transparent pl-1 text-muted-foreground"
: change === "unchanged"
? "bg-muted border border-border text-muted-foreground"
: change === "added"
- ? cn(base, "font-semibold", row.risk === "danger" && !isSensitive ? "border-destructive" : "border-current")
+ ? riskTone
+ ? cn(base, "font-semibold")
+ : "border border-border bg-muted text-foreground"
: base;
return (
@@ -77,23 +131,70 @@ function Chip({ value, row, change }: { value: string; row: PermissionRowData; c
data-sensitive={isSensitive ? "true" : undefined}
className={cn("inline-flex max-w-full items-center gap-1 rounded-md px-2 py-0.5 font-mono text-xs", changeClass)}
>
- {change === "added" && {"+"}}
- {change === "removed" && {"−"}}
+ {change === "added" && (
+
+ {"+"}
+
+ )}
+ {change === "removed" && (
+
+ {"−"}
+
+ )}
{isSensitive && change !== "removed" && }
{change && {t(CHANGE_LABEL_KEY[change])}}
- {value}
+
+
+
{isScriptCatOnly && }
);
}
-function MoreButton({ label, onClick }: { label: string; onClick: () => void }) {
+/** 同一资源只换了查询参数:地址只出现一次,旧参数划掉、新参数紧随其后 */
+function UpdatedChip({ update, row }: { update: PermissionUpdate; row: PermissionRowData }) {
+ const { t } = useTranslation(["install", "common"]);
+ const base = update.to.split("?")[0];
+ const fromQuery = update.from.slice(base.length);
+ const toQuery = update.to.slice(base.length);
+
+ return (
+
+
+ {"~"}
+
+ {t(CHANGE_LABEL_KEY.updated)}
+
+
+ {fromQuery && {fromQuery}}
+
+ {"→"}
+
+ {toQuery && {toQuery}}
+
+
+ );
+}
+
+function MoreButton({
+ label,
+ onClick,
+ testId = "permission-more",
+}: {
+ label: string;
+ onClick: () => void;
+ testId?: string;
+}) {
return (