fix: iframe bugs
This commit is contained in:
@@ -1788,7 +1788,7 @@ export const I18N = {
|
|||||||
zh: `滚动加载提前触发 (0-10000px)`,
|
zh: `滚动加载提前触发 (0-10000px)`,
|
||||||
en: `Early triggering of scroll loading (0-10000px)`,
|
en: `Early triggering of scroll loading (0-10000px)`,
|
||||||
zh_TW: `滾動載入提前觸發 (0-10000px)`,
|
zh_TW: `滾動載入提前觸發 (0-10000px)`,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newI18n = (lang) => (key) => I18N[key]?.[lang] || "";
|
export const newI18n = (lang) => (key) => I18N[key]?.[lang] || "";
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ export function AlertProvider({ children }) {
|
|||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
anchorOrigin={{ vertical, horizontal }}
|
anchorOrigin={{ vertical, horizontal }}
|
||||||
>
|
>
|
||||||
<Alert onClose={handleClose} severity={severity} sx={{ maxWidth: "80%" }}>
|
<Alert
|
||||||
|
onClose={handleClose}
|
||||||
|
severity={severity}
|
||||||
|
sx={{ maxWidth: "80%" }}
|
||||||
|
>
|
||||||
{message}
|
{message}
|
||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { APP_CONSTS } from "../config";
|
|||||||
import ContentFab from "../views/Action/ContentFab";
|
import ContentFab from "../views/Action/ContentFab";
|
||||||
|
|
||||||
export class FabManager extends ShadowDomManager {
|
export class FabManager extends ShadowDomManager {
|
||||||
constructor({ translator, processActions, fabConfig }) {
|
constructor({ processActions, fabConfig }) {
|
||||||
super({
|
super({
|
||||||
id: APP_CONSTS.fabID,
|
id: APP_CONSTS.fabID,
|
||||||
className: "notranslate",
|
className: "notranslate",
|
||||||
reactComponent: ContentFab,
|
reactComponent: ContentFab,
|
||||||
props: { translator, processActions, fabConfig },
|
props: { processActions, fabConfig },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!fabConfig?.isHide) {
|
if (!fabConfig?.isHide) {
|
||||||
|
|||||||
@@ -54,15 +54,15 @@ export default class TranslatorManager {
|
|||||||
isIframe,
|
isIframe,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._transboxManager = new TransboxManager(setting);
|
||||||
|
|
||||||
if (!isIframe) {
|
if (!isIframe) {
|
||||||
this._transboxManager = new TransboxManager(setting);
|
|
||||||
this._inputTranslator = new InputTranslator(setting);
|
this._inputTranslator = new InputTranslator(setting);
|
||||||
this._popupManager = new PopupManager({
|
this._popupManager = new PopupManager({
|
||||||
translator: this._translator,
|
translator: this._translator,
|
||||||
processActions: this.#processActions.bind(this),
|
processActions: this.#processActions.bind(this),
|
||||||
});
|
});
|
||||||
this._fabManager = new FabManager({
|
this._fabManager = new FabManager({
|
||||||
translator: this._translator,
|
|
||||||
processActions: this.#processActions.bind(this),
|
processActions: this.#processActions.bind(this),
|
||||||
fabConfig,
|
fabConfig,
|
||||||
});
|
});
|
||||||
@@ -137,6 +137,9 @@ export default class TranslatorManager {
|
|||||||
window.addEventListener("message", this.#windowMessageHandler);
|
window.addEventListener("message", this.#windowMessageHandler);
|
||||||
} else {
|
} else {
|
||||||
browser.runtime.onMessage.addListener(this.#browserMessageHandler);
|
browser.runtime.onMessage.addListener(this.#browserMessageHandler);
|
||||||
|
if (this.#isIframe) {
|
||||||
|
window.addEventListener("message", this.#windowMessageHandler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +187,7 @@ export default class TranslatorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#handleBrowserMessage(message, sender, sendResponse) {
|
#handleBrowserMessage(message, sender, sendResponse) {
|
||||||
const result = this.#processActions(message);
|
const result = this.#processActions(message, true);
|
||||||
const response = result || {
|
const response = result || {
|
||||||
rule: this._translator.rule,
|
rule: this._translator.rule,
|
||||||
setting: this._translator.setting,
|
setting: this._translator.setting,
|
||||||
@@ -242,9 +245,9 @@ export default class TranslatorManager {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
#processActions({ action, args } = {}) {
|
#processActions({ action, args } = {}, fromExt = false) {
|
||||||
if (this.#isUserscript) {
|
if (!fromExt) {
|
||||||
sendIframeMsg(action);
|
sendIframeMsg(action, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import Draggable from "./Draggable";
|
|||||||
import { useState, useMemo, useCallback } from "react";
|
import { useState, useMemo, useCallback } from "react";
|
||||||
import { SettingProvider } from "../../hooks/Setting";
|
import { SettingProvider } from "../../hooks/Setting";
|
||||||
import { MSG_TRANS_TOGGLE, MSG_POPUP_TOGGLE } from "../../config";
|
import { MSG_TRANS_TOGGLE, MSG_POPUP_TOGGLE } from "../../config";
|
||||||
import { sendIframeMsg } from "../../libs/iframe";
|
|
||||||
import useWindowSize from "../../hooks/WindowSize";
|
import useWindowSize from "../../hooks/WindowSize";
|
||||||
|
|
||||||
export default function ContentFab({
|
export default function ContentFab({
|
||||||
translator,
|
|
||||||
fabConfig: { x: fabX, y: fabY, fabClickAction = 0 } = {},
|
fabConfig: { x: fabX, y: fabY, fabClickAction = 0 } = {},
|
||||||
processActions,
|
processActions,
|
||||||
}) {
|
}) {
|
||||||
@@ -28,13 +26,12 @@ export default function ContentFab({
|
|||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(() => {
|
||||||
if (!moved) {
|
if (!moved) {
|
||||||
if (fabClickAction === 1) {
|
if (fabClickAction === 1) {
|
||||||
translator.toggle();
|
processActions({ action: MSG_TRANS_TOGGLE });
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE);
|
|
||||||
} else {
|
} else {
|
||||||
processActions({ action: MSG_POPUP_TOGGLE });
|
processActions({ action: MSG_POPUP_TOGGLE });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [moved, translator, fabClickAction, processActions]);
|
}, [moved, fabClickAction, processActions]);
|
||||||
|
|
||||||
const fabProps = useMemo(
|
const fabProps = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export default function PopupCont({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = async (e) => {
|
const handleChange = async (e) => {
|
||||||
|
console.log("handleChange", e);
|
||||||
try {
|
try {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
setRule((pre) => ({ ...pre, [name]: value }));
|
setRule((pre) => ({ ...pre, [name]: value }));
|
||||||
|
|||||||
Reference in New Issue
Block a user