Update GoogleTranslateOption.plugin.js
This commit is contained in:
parent
1bcab0d5ae
commit
3b6917e810
|
@ -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,40 +186,56 @@ var GoogleTranslateOption = (_ => {
|
||||||
this.translateMessage(e.instance.props.message, e.instance.props.channel);
|
this.translateMessage(e.instance.props.message, e.instance.props.channel);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
let text = document.getSelection().toString();
|
this.injectSearchItem(e);
|
||||||
if (text) {
|
}
|
||||||
let translating, foundTranslation, foundInput, foundOutput;
|
}
|
||||||
let [children2, index2] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["id", "search-google"]]});
|
|
||||||
if (index2 > -1) children2.splice(index2 > -1 ? index2 + 1 : 0, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
onNativeContextMenu (e) {
|
||||||
label: this.labels.context_googletranslateoption_text,
|
this.injectSearchItem(e);
|
||||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "search-translation"),
|
}
|
||||||
disabled: isTranslating,
|
|
||||||
action: event => {
|
onSlateContextMenu (e) {
|
||||||
let item = BDFDB.DOMUtils.getParent(BDFDB.dotCN.menuitem, event.target);
|
this.injectSearchItem(e);
|
||||||
if (item) {
|
}
|
||||||
let createTooltip = _ => {
|
|
||||||
BDFDB.TooltipUtils.create(item, `From ${foundInput.name}:\n${text}\n\nTo ${foundOutput.name}:\n${foundTranslation}`, {type:"right", selector:"googletranslate-tooltip"});
|
injectSearchItem (e) {
|
||||||
};
|
let text = document.getSelection().toString();
|
||||||
if (foundTranslation && foundInput && foundOutput) {
|
if (text) {
|
||||||
if (document.querySelector(".googletranslate-tooltip")) {
|
let translating, foundTranslation, foundInput, foundOutput;
|
||||||
BDFDB.ContextMenuUtils.close(e.instance);
|
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["id", ["devmode-copy-id", "search-google"]]]});
|
||||||
BDFDB.DiscordUtils.openLink(this.getGoogleTranslatePageURL(foundInput.id, foundOutput.id, text), BDFDB.DataUtils.get(this, "settings", "useChromium"));
|
children.splice(index > -1 ? index + 1 : 0, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||||
}
|
id: BDFDB.ContextMenuUtils.createItemId(this.name, "search-translation"),
|
||||||
else createTooltip();
|
disabled: isTranslating,
|
||||||
}
|
render: itemData => {
|
||||||
else if (!translating) {
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.ChildItem, Object.assign({
|
||||||
translating = true;
|
label: this.labels.context_googletranslateoption_text,
|
||||||
this.translateText(text, "context", (translation, input, output) => {
|
action: event => {
|
||||||
if (translation) {
|
let item = BDFDB.DOMUtils.getParent(BDFDB.dotCN.menuitem, event.target);
|
||||||
foundTranslation = translation, foundInput = input, foundOutput = output;
|
if (item) {
|
||||||
createTooltip();
|
let createTooltip = _ => {
|
||||||
|
BDFDB.TooltipUtils.create(item, `From ${foundInput.name}:\n${text}\n\nTo ${foundOutput.name}:\n${foundTranslation}`, {type:"right", selector:"googletranslate-tooltip"});
|
||||||
|
};
|
||||||
|
if (foundTranslation && foundInput && foundOutput) {
|
||||||
|
if (document.querySelector(".googletranslate-tooltip")) {
|
||||||
|
BDFDB.ContextMenuUtils.close(e.instance);
|
||||||
|
BDFDB.DiscordUtils.openLink(this.getGoogleTranslatePageURL(foundInput.id, foundOutput.id, text), BDFDB.DataUtils.get(this, "settings", "useChromium"));
|
||||||
}
|
}
|
||||||
});
|
else createTooltip();
|
||||||
|
}
|
||||||
|
else if (!translating) {
|
||||||
|
translating = true;
|
||||||
|
this.translateText(text, "context", (translation, input, output) => {
|
||||||
|
if (translation) {
|
||||||
|
foundTranslation = translation, foundInput = input, foundOutput = output;
|
||||||
|
createTooltip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, itemData));
|
||||||
}));
|
}
|
||||||
}
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue