From c37e26214a097ed2e0ca2e791befbb0eeaeb3bd2 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Fri, 27 Sep 2019 09:48:32 +0200 Subject: [PATCH] Update GoogleTranslateOption.plugin.js --- .../GoogleTranslateOption.plugin.js | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js b/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js index 089992623a..bc41c54169 100644 --- a/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js +++ b/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js @@ -3,7 +3,7 @@ class GoogleTranslateOption { getName () {return "GoogleTranslateOption";} - getVersion () {return "1.7.5";} + getVersion () {return "1.7.6";} getAuthor () {return "DevilBro";} @@ -11,7 +11,7 @@ class GoogleTranslateOption { constructor () { this.changelog = { - "added":[["Favorites","You can now add languages to your own favorites list, these languages will appear at the top of your choicemenu"]] + "improved":[["Embeds","Translating a message now also translates the embed descriptions (usually the maintext of embeds)"]] }; this.labels = {}; @@ -117,13 +117,21 @@ class GoogleTranslateOption { padding: 0 10px; width: 400px; } - ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messagebody + BDFDB.dotCN.messagemarkup} { + ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messagebody + BDFDB.dotCN.messagemarkup}, + ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messageaccessory + BDFDB.dotCN.embeddescription} { font-size: 0 !important; + line-height: 0 !important; } ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messagebody + BDFDB.dotCN.messagemarkup} > .GTO-translation { font-size: 1rem !important; + line-height: 1.375 !important; } - ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messagebody + BDFDB.dotCN.messagemarkup} > :not(.GTO-translation)${BDFDB.notCN.messageheadercompact + BDFDB.notCN.messageedited} { + ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messageaccessory + BDFDB.dotCN.embeddescription} > .GTO-translation { + font-size: 0.875rem !important; + line-height: 1rem !important; + } + ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messagebody + BDFDB.dotCN.messagemarkup} > :not(.GTO-translation)${BDFDB.notCN.messageheadercompact + BDFDB.notCN.messageedited}, + ${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messageaccessory + BDFDB.dotCN.embeddescription} > :not(.GTO-translation)${BDFDB.notCN.messageedited} { display: none !important; }`; } @@ -385,7 +393,7 @@ class GoogleTranslateOption { } getMessageAndPos (target) { - let messagediv = BDFDB.getParentEle(BDFDB.dotCN.messagegroup + "> [aria-disabled]", target); + let messagediv = BDFDB.getParentEle(BDFDB.dotCN.messagegroup + "> [aria-disabled]", target) || BDFDB.getParentEle(BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target); let pos = messagediv ? Array.from(messagediv.parentElement.childNodes).filter(n => n.nodeType != Node.TEXT_NODE).indexOf(messagediv) : -1; return {messagediv, pos}; } @@ -397,16 +405,27 @@ class GoogleTranslateOption { channel = channel ? channel : BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id); if (!messagediv.querySelector(BDFDB.dotCN.messageedited + ".GTO-translated")) { var markup = messagediv.querySelector(BDFDB.dotCN.messagemarkup); + var accessory = messagediv.querySelector(BDFDB.dotCN.messageaccessory); + var embeddescriptions = messagediv.querySelectorAll(BDFDB.dotCN.embeddescription) var fakemarkup = markup.cloneNode(true); BDFDB.removeEles(fakemarkup.querySelectorAll(BDFDB.dotCNC.messageheadercompact + BDFDB.dotCN.messageedited)); - this.translateText(fakemarkup.innerHTML, "context", (translation, input, output) => { + let string = fakemarkup.innerHTML; + if (embeddescriptions.length) for (let embeddescription of embeddescriptions) { + string += "\n__________________ __________________ __________________\n"; + string += embeddescription.innerHTML;; + } + this.translateText(string, "context", (translation, input, output) => { if (translation) { + BDFDB.addClass(messagediv, "GTO-translated-message"); + let translations = translation.split("\n__________________ __________________ __________________\n"); let compactheader = markup.querySelector(BDFDB.dotCN.messageheadercompact); - markup.insertBefore(BDFDB.htmlToElement(``), compactheader ? compactheader.nextSibling : markup.firstChild); - markup.querySelector(BDFDB.dotCN.messageedited + ".GTO-translated").addEventListener("mouseenter", e => { + markup.insertBefore(BDFDB.htmlToElement(``), compactheader ? compactheader.nextSibling : markup.firstChild); + if (embeddescriptions.length) for (let embeddescription of embeddescriptions) { + embeddescription.insertBefore(BDFDB.htmlToElement(``), embeddescription.firstChild); + } + BDFDB.addChildEventListener(messagediv, "mouseenter", BDFDB.dotCN.messageedited + ".GTO-translated", e => { BDFDB.createTooltip(`
From: ${input.name}
To: ${output.name}
`, e.currentTarget, {html:true, type:"top", selector:"translation-tooltip"}); }); - BDFDB.addClass(messagediv, "GTO-translated-message"); } }); } @@ -414,7 +433,7 @@ class GoogleTranslateOption { } resetMessage (messagediv) { - BDFDB.removeEles(messagediv.querySelector(".GTO-translation")); + BDFDB.removeEles(messagediv.querySelectorAll(".GTO-translation")); BDFDB.removeClass(messagediv, "GTO-translated-message"); }