Skip to content

Commit 83e755e

Browse files
authored
修复合并错误 (#1062)
1 parent 53dbbe8 commit 83e755e

File tree

9 files changed

+20
-39
lines changed

9 files changed

+20
-39
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ jobs:
3939
4040
- name: Lint
4141
run: |
42-
pnpm run typecheck
43-
pnpm run lint:ci
42+
pnpm typecheck
43+
pnpm lint:ci
4444
4545
- name: Unit Test
4646
run: |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"test": "vitest --test-timeout=500 --no-coverage --isolate=false --reporter=verbose",
1111
"test:ci": "vitest run --test-timeout=500 --no-coverage --isolate=false --reporter=default --reporter.summary=false",
1212
"coverage": "vitest run --coverage",
13-
"typecheck": "tsc --noEmit",
1413
"coverage:ci": "vitest run --coverage --silent --reporter=default --reporter.default.summary=false",
14+
"typecheck": "tsc --noEmit",
1515
"build": "cross-env NODE_ENV=production rspack build",
1616
"dev": "cross-env NODE_ENV=development rspack",
1717
"dev:noMap": "cross-env NODE_ENV=development NO_MAP=true rspack",
Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BgGMXhr } from "@App/pkg/utils/xhr/bg_gm_xhr";
22
import type { IGetSender, Group } from "@Packages/message/server";
3+
import { mightPrepareSetClipboard, setClipboard } from "../service_worker/clipboard";
34

45
// nativePageXHR 不需要绑定 Offscreen.GMApi 的 this,外部可以直接引用
56
export const nativePageXHR = async (details: GMSend.XHRDetails, sender: IGetSender) => {
@@ -15,37 +16,17 @@ export const nativePageWindowOpen = (details: { url: string }): boolean => {
1516
return !!window.open(details.url);
1617
};
1718

19+
export const nativePageSetClipboard = ({ data, mimetype }: { data: string; mimetype: string }) => {
20+
setClipboard(data, mimetype);
21+
};
22+
1823
export default class GMApi {
1924
constructor(private group: Group) {}
2025

21-
textarea: HTMLTextAreaElement = document.createElement("textarea");
22-
23-
clipboardData: { type?: string; data: string } | undefined;
24-
25-
async setClipboard({ data, type }: { data: string; type: string }) {
26-
this.clipboardData = {
27-
type,
28-
data,
29-
};
30-
this.textarea.focus();
31-
document.execCommand("copy", false, <any>null);
32-
}
33-
3426
init() {
35-
this.textarea.style.display = "none";
36-
document.documentElement.appendChild(this.textarea);
37-
document.addEventListener("copy", (e: ClipboardEvent) => {
38-
if (!this.clipboardData || !e.clipboardData) {
39-
return;
40-
}
41-
e.preventDefault();
42-
const { type, data } = this.clipboardData;
43-
e.clipboardData.setData(type || "text/plain", data);
44-
this.clipboardData = undefined;
45-
});
46-
27+
mightPrepareSetClipboard();
4728
this.group.on("xmlHttpRequest", nativePageXHR);
4829
this.group.on("windowOpen", nativePageWindowOpen);
49-
this.group.on("setClipboard", this.setClipboard.bind(this));
30+
this.group.on("setClipboard", nativePageSetClipboard);
5031
}
5132
}

src/app/service/service_worker/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ export class RuntimeService {
663663
// 即使注册失败,通过重置 flag 可避免错误地呼叫已取消注册的Script
664664
runtimeGlobal.messageFlag = this.generateMessageFlag();
665665
await Promise.allSettled([
666-
chrome.userScripts.unregister(),
666+
chrome.userScripts?.unregister(),
667667
chrome.scripting.unregisterContentScripts(),
668668
this.localStorageDAO.save({ key: "scriptInjectMessageFlag", value: runtimeGlobal.messageFlag }),
669669
]);

src/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CustomEventMessage } from "@Packages/message/custom_event_message";
55
import { Server } from "@Packages/message/server";
66
import ContentRuntime from "./app/service/content/content";
77
import { initEnvInfo, ScriptExecutor } from "./app/service/content/script_executor";
8-
import { randomMessageFlag } from "./pkg/utils/utils";
8+
import { randomMessageFlag, getUspMessageFlag } from "./pkg/utils/utils";
99
import type { Message } from "@Packages/message/types";
1010

1111
// @ts-ignore

src/pages/components/RuntimeSetting/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ const RuntimeSetting: React.FC = () => {
5757

5858
return (
5959
<Card title={t("runtime")} bordered={false}>
60-
<Space direction="vertical" size={20} className={"w-full"}>
61-
<div className="flex items-center justify-between min-h-9">
62-
<div className="flex items-center gap-2 flex-1">
60+
<Space direction="vertical" size={20} className={"tw-w-full"}>
61+
<div className="tw-flex tw-items-center tw-justify-between tw-min-h-9">
62+
<div className="tw-flex tw-items-center tw-gap-2 tw-flex-1">
6363
<Switch onChange={setEnableBackground} checked={enableBackground} />
6464
<span
65-
className="min-w-20 font-medium cursor-pointer"
65+
className="tw-min-w-20 tw-font-medium tw-cursor-pointer"
6666
onClick={() => {
6767
setEnableBackground(!enableBackground);
6868
}}
6969
>
7070
{t("enable_background.title")}
7171
</span>
7272
</div>
73-
<span className="text-xs ml-6 flex-shrink-0">{t("enable_background.description")}</span>
73+
<span className="tw-text-xs tw-ml-6 tw-flex-shrink-0">{t("enable_background.description")}</span>
7474
</div>
7575
<Collapse bordered={false} defaultActiveKey={["storage"]}>
7676
<CollapseItem header={t("storage_api")} name="storage">

src/pages/options/routes/ScriptList/ScriptTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export const ScriptTable = ({
489489
filterIcon: <IconSearch />,
490490
filterDropdown: ({ filterKeys, setFilterKeys, confirm }: any) => {
491491
return (
492-
<div className="arco-table-custom-filter flex flex-row gap-2">
492+
<div className="arco-table-custom-filter tw-flex tw-flex-row tw-gap-2">
493493
<ScriptSearchField
494494
t={t}
495495
autoFocus

src/pages/options/routes/ScriptList/components.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const ScriptSearchField = ({ t, defaultValue, onChange, onSearch, autoFoc
196196
return (
197197
<Space direction="horizontal">
198198
<Select
199-
className="flex-1"
199+
className="tw-flex-1"
200200
triggerProps={{ autoAlignPopupWidth: false, autoAlignPopupMinWidth: true, position: "bl" }}
201201
size="small"
202202
value={type}

src/pages/options/routes/SubscribeList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function SubscribeList() {
123123
);
124124
},
125125
onFilter: (value, row) => !value || row.name.includes(value),
126-
className: "max-w-[240px]",
126+
className: "tw-max-w-[240px]",
127127
render: (col) => {
128128
return (
129129
<Tooltip content={col} position="tl">

0 commit comments

Comments
 (0)