Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71bbd2e54a | ||
|
|
3083d8e147 | ||
|
|
e74883e9c2 | ||
|
|
0816a9d167 |
2
.env
2
.env
@@ -2,7 +2,7 @@ GENERATE_SOURCEMAP=false
|
||||
|
||||
REACT_APP_NAME=KISS Translator
|
||||
REACT_APP_NAME_CN=简约翻译
|
||||
REACT_APP_VERSION=1.8.1
|
||||
REACT_APP_VERSION=1.8.2
|
||||
|
||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "kiss-translator",
|
||||
"description": "A minimalist bilingual translation Extension & Greasemonkey Script",
|
||||
"version": "1.8.1",
|
||||
"version": "1.8.2",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 2,
|
||||
"name": "__MSG_app_name__",
|
||||
"description": "__MSG_app_description__",
|
||||
"version": "1.8.1",
|
||||
"version": "1.8.2",
|
||||
"default_locale": "en",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 3,
|
||||
"name": "__MSG_app_name__",
|
||||
"description": "__MSG_app_description__",
|
||||
"version": "1.8.1",
|
||||
"version": "1.8.2",
|
||||
"default_locale": "en",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||
|
||||
@@ -28,39 +28,51 @@ globalThis.ContextType = "BACKGROUND";
|
||||
/**
|
||||
* 添加右键菜单
|
||||
*/
|
||||
function addContextMenus() {
|
||||
browser.contextMenus.create({
|
||||
id: CMD_TOGGLE_TRANSLATE,
|
||||
title: browser.i18n.getMessage("toggle_translate"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_TOGGLE_STYLE,
|
||||
title: browser.i18n.getMessage("toggle_style"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_OPEN_TRANBOX,
|
||||
title: browser.i18n.getMessage("open_tranbox"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: "options_separator",
|
||||
type: "separator",
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_OPEN_OPTIONS,
|
||||
title: browser.i18n.getMessage("open_options"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
}
|
||||
async function addContextMenus(contextMenuType = 1) {
|
||||
// 添加前先删除,避免重复ID的错误
|
||||
try {
|
||||
await browser.contextMenus.removeAll();
|
||||
} catch (err) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除右键菜单
|
||||
*/
|
||||
function removeContextMenus() {
|
||||
browser.contextMenus.removeAll();
|
||||
switch (contextMenuType) {
|
||||
case 1:
|
||||
browser.contextMenus.create({
|
||||
id: CMD_TOGGLE_TRANSLATE,
|
||||
title: browser.i18n.getMessage("toggle_translate"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
browser.contextMenus.create({
|
||||
id: CMD_TOGGLE_TRANSLATE,
|
||||
title: browser.i18n.getMessage("toggle_translate"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_TOGGLE_STYLE,
|
||||
title: browser.i18n.getMessage("toggle_style"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_OPEN_TRANBOX,
|
||||
title: browser.i18n.getMessage("open_tranbox"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: "options_separator",
|
||||
type: "separator",
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
browser.contextMenus.create({
|
||||
id: CMD_OPEN_OPTIONS,
|
||||
title: browser.i18n.getMessage("open_options"),
|
||||
contexts: ["page", "selection"],
|
||||
});
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,11 +92,8 @@ browser.runtime.onStartup.addListener(async () => {
|
||||
// 同步数据
|
||||
await trySyncSettingAndRules();
|
||||
|
||||
const {
|
||||
clearCache,
|
||||
contextMenus = true,
|
||||
subrulesList,
|
||||
} = await getSettingWithDefault();
|
||||
const { clearCache, contextMenuType, subrulesList } =
|
||||
await getSettingWithDefault();
|
||||
|
||||
// 清除缓存
|
||||
if (clearCache) {
|
||||
@@ -92,11 +101,8 @@ browser.runtime.onStartup.addListener(async () => {
|
||||
}
|
||||
|
||||
// 右键菜单
|
||||
if (contextMenus) {
|
||||
addContextMenus();
|
||||
} else {
|
||||
removeContextMenus();
|
||||
}
|
||||
// firefox重启后菜单会消失,故重复添加
|
||||
addContextMenus(contextMenuType);
|
||||
|
||||
// 同步订阅规则
|
||||
trySyncAllSubRules({ subrulesList });
|
||||
@@ -134,12 +140,8 @@ browser.runtime.onMessage.addListener(
|
||||
saveRule(args);
|
||||
break;
|
||||
case MSG_CONTEXT_MENUS:
|
||||
const { contextMenus } = args;
|
||||
if (contextMenus) {
|
||||
addContextMenus();
|
||||
} else {
|
||||
removeContextMenus();
|
||||
}
|
||||
const { contextMenuType } = args;
|
||||
addContextMenus(contextMenuType);
|
||||
break;
|
||||
case MSG_COMMAND_SHORTCUTS:
|
||||
browser.commands
|
||||
|
||||
@@ -140,7 +140,7 @@ async function showFab(translator) {
|
||||
* @returns
|
||||
*/
|
||||
function showTransbox({
|
||||
contextMenus = true,
|
||||
contextMenuType,
|
||||
tranboxSetting = DEFAULT_TRANBOX_SETTING,
|
||||
transApis,
|
||||
}) {
|
||||
@@ -165,7 +165,7 @@ function showTransbox({
|
||||
<React.StrictMode>
|
||||
<CacheProvider value={cache}>
|
||||
<Slection
|
||||
contextMenus={contextMenus}
|
||||
contextMenuType={contextMenuType}
|
||||
tranboxSetting={tranboxSetting}
|
||||
transApis={transApis}
|
||||
/>
|
||||
|
||||
@@ -723,9 +723,21 @@ export const I18N = {
|
||||
zh: `此功能依赖准确的语言检测,建议启用远程语言检测。`,
|
||||
en: `This feature relies on accurate language detection. It is recommended to enable remote language detection.`,
|
||||
},
|
||||
add_context_menus: {
|
||||
zh: `添加右键菜单`,
|
||||
en: `Add Context Menus`,
|
||||
context_menus: {
|
||||
zh: `右键菜单`,
|
||||
en: `Context Menus`,
|
||||
},
|
||||
hide_context_menus: {
|
||||
zh: `隐藏右键菜单`,
|
||||
en: `Hide Context Menus`,
|
||||
},
|
||||
simple_context_menus: {
|
||||
zh: `简单右键菜单`,
|
||||
en: `Simple_context_menus Context Menus`,
|
||||
},
|
||||
secondary_context_menus: {
|
||||
zh: `二级右键菜单`,
|
||||
en: `Secondary Context Menus`,
|
||||
},
|
||||
mulkeys_help: {
|
||||
zh: `支持用换行或英文逗号“,”分隔多个KEY轮询调用。`,
|
||||
|
||||
@@ -452,7 +452,8 @@ export const DEFAULT_SETTING = {
|
||||
injectRules: true, // 是否注入订阅规则
|
||||
injectWebfix: true, // 是否注入修复补丁
|
||||
detectRemote: false, // 是否使用远程语言检测
|
||||
contextMenus: true, // 是否添加右键菜单
|
||||
contextMenus: true, // 是否添加右键菜单(作废)
|
||||
contextMenuType: 1, // 右键菜单类型(0不显示,1简单菜单,2多级菜单)
|
||||
transTitle: false, // 是否同时翻译页面标题
|
||||
subrulesList: DEFAULT_SUBRULES_LIST, // 订阅列表
|
||||
owSubrule: DEFAULT_OW_RULE, // 覆写订阅规则
|
||||
|
||||
@@ -85,6 +85,7 @@ function brFixer(node, tag = "p") {
|
||||
"HR",
|
||||
"PRE",
|
||||
"TABLE",
|
||||
"BLOCKQUOTE",
|
||||
];
|
||||
|
||||
let html = "";
|
||||
|
||||
@@ -95,8 +95,8 @@ export default function Action({ translator, fab }) {
|
||||
// 注册菜单
|
||||
try {
|
||||
const menuCommandIds = [];
|
||||
const { contextMenus = true } = translator.setting;
|
||||
contextMenus &&
|
||||
const { contextMenuType } = translator.setting;
|
||||
contextMenuType !== 0 &&
|
||||
menuCommandIds.push(
|
||||
GM.registerMenuCommand(
|
||||
"Toggle Translate",
|
||||
|
||||
@@ -67,8 +67,8 @@ export default function Settings() {
|
||||
case "touchTranslate":
|
||||
value = limitNumber(value, 0, 4);
|
||||
break;
|
||||
case "contextMenus":
|
||||
isExt && sendBgMsg(MSG_CONTEXT_MENUS, { contextMenus: value });
|
||||
case "contextMenuType":
|
||||
isExt && sendBgMsg(MSG_CONTEXT_MENUS, { contextMenuType: value });
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export default function Settings() {
|
||||
newlineLength = TRANS_NEWLINE_LENGTH,
|
||||
mouseKey = OPT_MOUSEKEY_DISABLE,
|
||||
detectRemote = false,
|
||||
contextMenus = true,
|
||||
contextMenuType = 1,
|
||||
transTitle = false,
|
||||
touchTranslate = 2,
|
||||
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
||||
@@ -229,15 +229,16 @@ export default function Settings() {
|
||||
</FormControl>
|
||||
|
||||
<FormControl size="small">
|
||||
<InputLabel>{i18n("add_context_menus")}</InputLabel>
|
||||
<InputLabel>{i18n("context_menus")}</InputLabel>
|
||||
<Select
|
||||
name="contextMenus"
|
||||
value={contextMenus}
|
||||
label={i18n("add_context_menus")}
|
||||
name="contextMenuType"
|
||||
value={contextMenuType}
|
||||
label={i18n("context_menus")}
|
||||
onChange={handleChange}
|
||||
>
|
||||
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||
<MenuItem value={0}>{i18n("hide_context_menus")}</MenuItem>
|
||||
<MenuItem value={1}>{i18n("simple_context_menus")}</MenuItem>
|
||||
<MenuItem value={2}>{i18n("secondary_context_menus")}</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ import { isGm, isExt } from "../../libs/client";
|
||||
import { MSG_OPEN_TRANBOX, DEFAULT_TRANBOX_SHORTCUT } from "../../config";
|
||||
import { isMobile } from "../../libs/mobile";
|
||||
|
||||
export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||
export default function Slection({
|
||||
contextMenuType,
|
||||
tranboxSetting,
|
||||
transApis,
|
||||
}) {
|
||||
const boxWidth = limitNumber(window.innerWidth, 300, 600);
|
||||
const boxHeight = limitNumber(window.innerHeight, 200, 400);
|
||||
|
||||
@@ -106,7 +110,7 @@ export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||
// 注册菜单
|
||||
try {
|
||||
const menuCommandIds = [];
|
||||
contextMenus &&
|
||||
contextMenuType !== 0 &&
|
||||
menuCommandIds.push(
|
||||
GM.registerMenuCommand(
|
||||
"Translate Selected Text",
|
||||
@@ -125,7 +129,7 @@ export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||
} catch (err) {
|
||||
console.log("[registerMenuCommand]", err);
|
||||
}
|
||||
}, [handleTranbox, contextMenus]);
|
||||
}, [handleTranbox, contextMenuType]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user