diff --git a/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx b/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx
index 88ccd656b..9bd7b6c07 100644
--- a/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx
+++ b/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx
@@ -223,10 +223,25 @@ describe("SettingsPane 更新URL", () => {
it("应展示更新URL并在失焦后调用 setCheckUpdateUrl", async () => {
render();
await screen.findByText("alpha");
- const input = screen.getByDisplayValue("https://example.com/a.meta.js");
- fireEvent.change(input, { target: { value: "https://new.example.com/a.meta.js" } });
+ const input = screen.getByDisplayValue("https://example.com/a.user.js");
+ fireEvent.change(input, { target: { value: "https://new.example.com/a.user.js" } });
fireEvent.blur(input);
- expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://new.example.com/a.meta.js");
+ expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://new.example.com/a.user.js");
+ });
+
+ // setCheckUpdateUrl 会把同一个值写进 downloadUrl,回显 meta.js 会让失焦/切开关把下载地址改成 meta.js (#1793)
+ it("未修改直接失焦时应以下载地址提交,而不是 meta.js", async () => {
+ render();
+ await screen.findByText("alpha");
+ fireEvent.blur(screen.getByDisplayValue("https://example.com/a.user.js"));
+ expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://example.com/a.user.js");
+ });
+
+ it("切换检查更新开关时应以下载地址提交,而不是 meta.js", async () => {
+ render();
+ await screen.findByText("alpha");
+ fireEvent.click(screen.getByRole("switch", { name: t("check_update") }));
+ expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", false, "https://example.com/a.user.js");
});
});
diff --git a/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx b/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx
index 36859a0a4..843389a3d 100644
--- a/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx
+++ b/src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx
@@ -210,7 +210,8 @@ function SettingsPaneContent({ uuid, data }: SettingsPaneProps & { data: Setting
return parseTags({ tag: self.tag ?? meta.tag });
});
const [tagInput, setTagInput] = useState("");
- const [updateUrl, setUpdateUrl] = useState(data.script.checkUpdateUrl ?? data.script.downloadUrl ?? "");
+ // 回显 downloadUrl 而非 checkUpdateUrl:保存时 setCheckUpdateUrl 会把该值同时写入两者,回显 meta.js 会把下载地址写坏 (#1793)
+ const [updateUrl, setUpdateUrl] = useState(data.script.downloadUrl || "");
const [matches, setMatches] = useState(() => {
const meta = data.script.metadata || {};
const self = data.script.selfMetadata || {};
@@ -597,7 +598,7 @@ function SettingsPaneContent({ uuid, data }: SettingsPaneProps & { data: Setting
value={updateUrl}
onChange={(e) => setUpdateUrl(e.target.value)}
onBlur={saveUpdateUrl}
- placeholder="https://example.com/script.meta.js"
+ placeholder="https://example.com/script.user.js"
className="h-8 flex-1 font-mono text-xs"
/>