Update GoogleTranslateOption.plugin.js

This commit is contained in:
Mirco Wittrien 2020-05-20 10:25:47 +02:00
parent 1bcab0d5ae
commit 3b6917e810
1 changed files with 48 additions and 32 deletions

View File

@ -27,7 +27,7 @@ var GoogleTranslateOption = (_ => {
return class GoogleTranslateOption { return class GoogleTranslateOption {
getName () {return "GoogleTranslateOption";} getName () {return "GoogleTranslateOption";}
getVersion () {return "2.0.2";} getVersion () {return "2.0.3";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -186,14 +186,29 @@ var GoogleTranslateOption = (_ => {
this.translateMessage(e.instance.props.message, e.instance.props.channel); this.translateMessage(e.instance.props.message, e.instance.props.channel);
} }
})); }));
this.injectSearchItem(e);
}
}
onNativeContextMenu (e) {
this.injectSearchItem(e);
}
onSlateContextMenu (e) {
this.injectSearchItem(e);
}
injectSearchItem (e) {
let text = document.getSelection().toString(); let text = document.getSelection().toString();
if (text) { if (text) {
let translating, foundTranslation, foundInput, foundOutput; let translating, foundTranslation, foundInput, foundOutput;
let [children2, index2] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["id", "search-google"]]}); let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["id", ["devmode-copy-id", "search-google"]]]});
if (index2 > -1) children2.splice(index2 > -1 ? index2 + 1 : 0, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuItem, { children.splice(index > -1 ? index + 1 : 0, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_googletranslateoption_text,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "search-translation"), id: BDFDB.ContextMenuUtils.createItemId(this.name, "search-translation"),
disabled: isTranslating, disabled: isTranslating,
render: itemData => {
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.ChildItem, Object.assign({
label: this.labels.context_googletranslateoption_text,
action: event => { action: event => {
let item = BDFDB.DOMUtils.getParent(BDFDB.dotCN.menuitem, event.target); let item = BDFDB.DOMUtils.getParent(BDFDB.dotCN.menuitem, event.target);
if (item) { if (item) {
@ -218,8 +233,9 @@ var GoogleTranslateOption = (_ => {
} }
} }
} }
})); }, itemData));
} }
}));
} }
} }