mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/StarCitizenBoxBrowserEx.git
synced 2025-05-09 21:51:25 +08:00
fix: 兼容网页主动调用
This commit is contained in:
parent
23f7df8400
commit
72185370c9
6
core.ts
6
core.ts
@ -254,6 +254,7 @@ function _loadLocalizationData() {
|
|||||||
if (response.result.length > 0) {
|
if (response.result.length > 0) {
|
||||||
SCLocalizationTranslating = true;
|
SCLocalizationTranslating = true;
|
||||||
WebLocalizationUpdateReplaceWords(response.result);
|
WebLocalizationUpdateReplaceWords(response.result);
|
||||||
|
window.postMessage({ type: 'TOGGLED-SC-BOX-TRANSLATE', action: 'on' }, '*');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -283,8 +284,10 @@ window.addEventListener('message', async (event) => {
|
|||||||
|
|
||||||
if (action === 'translate') {
|
if (action === 'translate') {
|
||||||
try {
|
try {
|
||||||
|
_saveLocalizationSwitchStater(true)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
SCLocalizationEnableSplitMode = true;
|
SCLocalizationEnableSplitMode = true;
|
||||||
chrome.runtime.sendMessage({ action: "_loadLocalizationData", url: "manual" }, function (response) {
|
chrome.runtime.sendMessage({ action: "_loadLocalizationData", url: window.location.href }, function (response) {
|
||||||
SCLocalizationTranslating = true;
|
SCLocalizationTranslating = true;
|
||||||
window.postMessage({ type: 'TOGGLED-SC-BOX-TRANSLATE', action: 'on' }, '*');
|
window.postMessage({ type: 'TOGGLED-SC-BOX-TRANSLATE', action: 'on' }, '*');
|
||||||
WebLocalizationUpdateReplaceWords(response.result);
|
WebLocalizationUpdateReplaceWords(response.result);
|
||||||
@ -295,6 +298,7 @@ window.addEventListener('message', async (event) => {
|
|||||||
}
|
}
|
||||||
} else if (action === 'undoTranslate') {
|
} else if (action === 'undoTranslate') {
|
||||||
try {
|
try {
|
||||||
|
_saveLocalizationSwitchStater(false)
|
||||||
response = await undoTranslate();
|
response = await undoTranslate();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
response = { success: false, error: error.message };
|
response = { success: false, error: error.message };
|
||||||
|
2
dist/chrome/content_scripts/content-0.js
vendored
2
dist/chrome/content_scripts/content-0.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user