|
|
@ -17,7 +17,7 @@ class GoogleTranslateOption {
|
|
|
|
this.labels = {};
|
|
|
|
this.labels = {};
|
|
|
|
|
|
|
|
|
|
|
|
this.patchModules = {
|
|
|
|
this.patchModules = {
|
|
|
|
"ChannelTextArea":"componentDidMount",
|
|
|
|
"ChannelTextArea":["componentDidMount","render"],
|
|
|
|
"Message":"componentDidMount",
|
|
|
|
"Message":"componentDidMount",
|
|
|
|
"MessageContent":"componentDidMount",
|
|
|
|
"MessageContent":"componentDidMount",
|
|
|
|
"StandardSidebarView":"componentWillUnmount"
|
|
|
|
"StandardSidebarView":"componentWillUnmount"
|
|
|
@ -40,66 +40,23 @@ class GoogleTranslateOption {
|
|
|
|
|
|
|
|
|
|
|
|
this.defaults = {
|
|
|
|
this.defaults = {
|
|
|
|
settings: {
|
|
|
|
settings: {
|
|
|
|
addTranslateButton: {value:true, description:"Adds an translate button to the chatbar."},
|
|
|
|
addTranslateButton: {value:true, description:"Adds an translate button to the chatbar."},
|
|
|
|
sendOriginalMessage: {value:false, description:"Send the original message together with the translation."}
|
|
|
|
sendOriginalMessage: {value:false, description:"Send the original message together with the translation."}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
choices: {
|
|
|
|
choices: {
|
|
|
|
inputContext: {value:"auto", place:"Context", direction:"Input", popout:false, description:"Input Language in selected Messages:"},
|
|
|
|
inputContext: {value:"auto", direction:"input", place:"Context", description:"Input Language in selected Messages:"},
|
|
|
|
outputContext: {value:"$discord", place:"Context", direction:"Output", popout:false, description:"Output Language in selected Messages:"},
|
|
|
|
outputContext: {value:"$discord", direction:"output", place:"Context", description:"Output Language in selected Messages:"},
|
|
|
|
inputMessage: {value:"auto", place:"Message", direction:"Input", popout:true, description:"Input Language in your Message:"},
|
|
|
|
inputMessage: {value:"auto", direction:"input", place:"Message", description:"Input Language in your Message:"},
|
|
|
|
outputMessage: {value:"$discord", place:"Message", direction:"Output", popout:true, description:"Output Language in your Message:"}
|
|
|
|
outputMessage: {value:"$discord", direction:"output", place:"Message", description:"Output Language in your Message:"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.translateButtonMarkup =
|
|
|
|
|
|
|
|
`<button type="button" class="${BDFDB.disCNS.textareabuttonwrapper + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookblank + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCN.buttongrow} translate-button">
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCNS.buttoncontents + BDFDB.disCNS.textareabutton + BDFDB.disCN.textareapickerbutton}">
|
|
|
|
|
|
|
|
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="${BDFDB.disCN.textareaicon}" viewBox="0 0 22 22" fill="currentColor">
|
|
|
|
|
|
|
|
<path d="M 19.794, 3.299 H 9.765 L 8.797, 0 h -6.598 C 0.99, 0, 0, 0.99, 0, 2.199 V 16.495 c 0, 1.21, 0.99, 2.199, 2.199, 2.199 H 9.897 l 1.1, 3.299 H 19.794 c 1.21, 0, 2.199 -0.99, 2.199 -2.199 V 5.498 C 21.993, 4.289, 21.003, 3.299, 19.794, 3.299 z M 5.68, 13.839 c -2.48, 0 -4.492 -2.018 -4.492 -4.492 s 2.018 -4.492, 4.492 -4.492 c 1.144, 0, 2.183, 0.407, 3.008, 1.171 l 0.071, 0.071 l -1.342, 1.298 l -0.066 -0.06 c -0.313 -0.297 -0.858 -0.643 -1.671 -0.643 c -1.441, 0 -2.612, 1.193 -2.612, 2.661 c 0, 1.468, 1.171, 2.661, 2.612, 2.661 c 1.507, 0, 2.161 -0.962, 2.337 -1.606 h -2.43 v -1.704 h 4.344 l 0.016, 0.077 c 0.044, 0.231, 0.06, 0.434, 0.06, 0.665 C 10.001, 12.036, 8.225, 13.839, 5.68, 13.839 z M 11.739, 9.979 h 4.393 c 0, 0 -0.374, 1.446 -1.715, 3.008 c -0.588 -0.676 -0.995 -1.336 -1.254 -1.864 h -1.089 L 11.739, 9.979 z M 13.625, 13.839 l -0.588, 0.583 l -0.72 -2.452 C 12.685, 12.63, 13.13, 13.262, 13.625, 13.839 z M 20.893, 19.794 c 0, 0.605 -0.495, 1.1 -1.1, 1.1 H 12.096 l 2.199 -2.199 l -0.896 -3.041 l 1.012 -1.012 l 2.953, 2.953 l 0.803 -0.803 l -2.975 -2.953 c 0.99 -1.138, 1.759 -2.474, 2.106 -3.854 h 1.397 V 8.841 H 14.697 v -1.144 h -1.144 v 1.144 H 11.398 l -1.309 -4.443 H 19.794 c 0.605, 0, 1.1, 0.495, 1.1, 1.1 V 19.794 z"/>
|
|
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</button>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.reverseButtonMarkup =
|
|
|
|
|
|
|
|
`<svg class="reverse-button ${BDFDB.disCN.flexchild}" type="REPLACETYPE" version="1.1" xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" style="flex: 0 0 auto;">
|
|
|
|
|
|
|
|
<path d="M 0, 10.515 c 0, 2.892, 1.183, 5.521, 3.155, 7.361 L 0, 21.031 h 7.887 V 13.144 l -2.892, 2.892 C 3.549, 14.722, 2.629, 12.75, 2.629, 10.515 c 0 -3.418, 2.235 -6.309, 5.258 -7.492 v -2.629 C 3.418, 1.577, 0, 5.652, 0, 10.515 z M 21.031, 0 H 13.144 v 7.887 l 2.892 -2.892 C 17.482, 6.309, 18.402, 8.281, 18.402, 10.515 c 0, 3.418 -2.235, 6.309 -5.258, 7.492 V 20.768 c 4.469 -1.183, 7.887 -5.258, 7.887 -10.121 c 0 -2.892 -1.183 -5.521 -3.155 -7.361 L 21.031, 0 z"/>
|
|
|
|
|
|
|
|
</svg>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.translatePopoutMarkup =
|
|
|
|
|
|
|
|
`<div class="${BDFDB.disCNS.popout + BDFDB.disCNS.popoutbottomright + BDFDB.disCNS.popoutnoarrow + BDFDB.disCN.popoutnoshadow} popout-googletranslate BDFDB-modal" style="z-index: 1000; overflow: visible; visibility: visible; transform: translateX(-100%) translateY(-100%) translateZ(0px);">
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCN.popoutthemedpopout}">
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCNS.margintop8 + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">
|
|
|
|
|
|
|
|
<h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Words starting with "!" will be ignored</h3>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
${Object.keys(this.defaults.choices).map((key, i) =>
|
|
|
|
|
|
|
|
`<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCNS.margintop8 + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">
|
|
|
|
|
|
|
|
<h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.choices[key].description}</h3>
|
|
|
|
|
|
|
|
${this.defaults.choices[key].direction == "Output" ? this.reverseButtonMarkup.replace("REPLACETYPE",key) : ""}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">${BDFDB.createSelectMenu(`<div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightnormal + BDFDB.disCN.cursorpointer}" style="flex: 1 1 auto;"></div>`, this.defaults.choices[key].value, key)}</div>`).join("")}
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">
|
|
|
|
|
|
|
|
<h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Translate:</h3>
|
|
|
|
|
|
|
|
<div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCNS.switchthemedefault + BDFDB.disCN.switchvalueunchecked}" style="flex: 0 0 auto;">
|
|
|
|
|
|
|
|
<input type="checkbox" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner}" id="translating-checkbox">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.css = `
|
|
|
|
this.css = `
|
|
|
|
${BDFDB.dotCNS.textareawrapall + BDFDB.dotCN.textareainner} {
|
|
|
|
.translate-button.translating-active ${BDFDB.dotCN.textareaicon} {
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
${BDFDB.dotCNS.textareawrapall + BDFDB.dotCN.textareainner} .send-button {
|
|
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
|
|
right: 9px;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
${BDFDB.dotCN.textareabuttonwrapper}.translate-button.translating-active ${BDFDB.dotCN.textareaicon} {
|
|
|
|
|
|
|
|
color: #F04747 !important;
|
|
|
|
color: #F04747 !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.reverse-button {
|
|
|
|
.reverse-button {
|
|
|
|
margin-top: -5px;
|
|
|
|
margin-right: 5px;
|
|
|
|
opacity: 0.2;
|
|
|
|
opacity: 0.2;
|
|
|
|
transition: all 200ms ease;
|
|
|
|
transition: all 200ms ease;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,10 +70,6 @@ class GoogleTranslateOption {
|
|
|
|
cursor: pointer;
|
|
|
|
cursor: pointer;
|
|
|
|
opacity: 1;
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${BDFDB.dotCN.popout}.popout-googletranslate ${BDFDB.dotCN.popoutthemedpopout} {
|
|
|
|
|
|
|
|
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} {
|
|
|
|
${BDFDB.dotCN.messagegroup} .GTO-translated-message ${BDFDB.dotCNS.messageaccessory + BDFDB.dotCN.embeddescription} {
|
|
|
|
font-size: 0 !important;
|
|
|
|
font-size: 0 !important;
|
|
|
@ -138,29 +91,20 @@ class GoogleTranslateOption {
|
|
|
|
|
|
|
|
|
|
|
|
getSettingsPanel () {
|
|
|
|
getSettingsPanel () {
|
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
|
|
|
var choices = BDFDB.DataUtils.get(this, "choices");
|
|
|
|
let settings = BDFDB.DataUtils.get(this, "settings");
|
|
|
|
var settings = BDFDB.DataUtils.get(this, "settings");
|
|
|
|
let settingsitems = [];
|
|
|
|
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
|
|
|
|
|
|
|
|
for (let key in choices) {
|
|
|
|
settingsitems = settingsitems.concat(this.createSelects(false));
|
|
|
|
let choice = this.getLanguageChoice(key);
|
|
|
|
|
|
|
|
settingshtml += `<h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.flexchild + BDFDB.disCNS.marginbottom8 + BDFDB.disCN.margintop8}" style="flex: 1 1 auto;">${this.defaults.choices[key].description}</h3><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">${BDFDB.createSelectMenu(this.createSelectChoice(choice), choice, key)}</div>`
|
|
|
|
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSwitch, {
|
|
|
|
}
|
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
for (let key in settings) {
|
|
|
|
plugin: this,
|
|
|
|
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
|
|
|
|
keys: ["settings", key],
|
|
|
|
}
|
|
|
|
label: this.defaults.settings[key].description,
|
|
|
|
settingshtml += `</div></div>`;
|
|
|
|
value: settings[key]
|
|
|
|
|
|
|
|
}));
|
|
|
|
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
|
|
|
|
|
|
|
|
|
|
|
|
return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
|
|
|
BDFDB.initElements(settingspanel, this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BDFDB.ListenerUtils.add(this, settingspanel, "click", BDFDB.dotCN.selectcontrol, e => {
|
|
|
|
|
|
|
|
let type = BDFDB.DOMUtils.getParent(BDFDB.dotCN.select, e.currentTarget).getAttribute("type");
|
|
|
|
|
|
|
|
let menulanguages = this.defaults.choices[type].direction == "Output" ? BDFDB.ObjectUtils.filter(this.languages, lang => {return lang.id != "auto";}) : this.languages;
|
|
|
|
|
|
|
|
BDFDB.openDropdownMenu(e, this.saveSelectChoice.bind(this), this.createSelectChoice.bind(this), menulanguages);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return settingspanel;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//legacy
|
|
|
|
//legacy
|
|
|
@ -203,8 +147,8 @@ class GoogleTranslateOption {
|
|
|
|
document.querySelectorAll(BDFDB.dotCN.messagegroup + " .GTO-translated-message").forEach(message => {
|
|
|
|
document.querySelectorAll(BDFDB.dotCN.messagegroup + " .GTO-translated-message").forEach(message => {
|
|
|
|
this.resetMessage(message);
|
|
|
|
this.resetMessage(message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.remove(".translate-button", ".popout-googletranslate");
|
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this, "ChannelTextArea");
|
|
|
|
|
|
|
|
|
|
|
|
BDFDB.PluginUtils.clear(this);
|
|
|
|
BDFDB.PluginUtils.clear(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -284,54 +228,11 @@ class GoogleTranslateOption {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setLanguages () {
|
|
|
|
processChannelTextArea (instance, wrapper, returnvalue, methodnames) {
|
|
|
|
this.languages = Object.assign({},
|
|
|
|
if (instance.props.type != "normal" || instance.props.disabled) return;
|
|
|
|
{"auto": {name:"Auto", id:"auto", integrated:false, dic:false}},
|
|
|
|
if (methodnames.includes("componentDidMount") && wrapper) {
|
|
|
|
BDFDB.LanguageUtils.languages,
|
|
|
|
let textarea = wrapper.querySelector(BDFDB.dotCN.textarea);
|
|
|
|
{"binary": {name:"Binary", id:"binary", integrated:false, dic:false}},
|
|
|
|
|
|
|
|
{"braille": {name:"Braille 6-dot", id:"braille", integrated:false, dic:false}},
|
|
|
|
|
|
|
|
{"morse": {name:"Morse", id:"morse", integrated:false, dic:false}}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let favorites = BDFDB.DataUtils.load(this, "favorites");
|
|
|
|
|
|
|
|
for (let id in this.languages) this.languages[id].fav = favorites[id] != undefined ? 0 : 1;
|
|
|
|
|
|
|
|
this.languages = BDFDB.ObjectUtils.sort(this.languages, "fav");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLanguageChoice (direction, place) {
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
var type = typeof place === "undefined" ? direction : direction.toLowerCase() + place.charAt(0).toUpperCase() + place.slice(1).toLowerCase();
|
|
|
|
|
|
|
|
var choice = BDFDB.DataUtils.get(this, "choices", type);
|
|
|
|
|
|
|
|
choice = this.languages[choice] ? choice : Object.keys(this.languages)[0];
|
|
|
|
|
|
|
|
choice = type.indexOf("output") > -1 && choice == "auto" ? "en" : choice;
|
|
|
|
|
|
|
|
return choice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processStandardSidebarView (instance, wrapper, returnvalue) {
|
|
|
|
|
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
|
|
|
|
delete this.SettingsUpdated;
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.remove(".translate-button");
|
|
|
|
|
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this, "ChannelTextArea");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processChannelTextArea (instance, wrapper, returnvalue) {
|
|
|
|
|
|
|
|
if (instance.props && instance.props.type && instance.props.type == "normal" && !instance.props.disabled && !wrapper.querySelector(".translate-button") && BDFDB.DataUtils.get(this, "settings", "addTranslateButton")) {
|
|
|
|
|
|
|
|
let textarea = wrapper.querySelector("textarea");
|
|
|
|
|
|
|
|
if (textarea) {
|
|
|
|
if (textarea) {
|
|
|
|
var buttoncontainer = wrapper.querySelector(BDFDB.dotCN.textareapickerbuttons);
|
|
|
|
|
|
|
|
if (!buttoncontainer) return;
|
|
|
|
|
|
|
|
var translateButton = BDFDB.DOMUtils.create(this.translateButtonMarkup);
|
|
|
|
|
|
|
|
translateButton.addEventListener("click", () => {
|
|
|
|
|
|
|
|
this.openTranslatePopout(translateButton);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
translateButton.addEventListener("contextmenu", () => {
|
|
|
|
|
|
|
|
this.translating = !this.translating;
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.toggleClass(document.querySelectorAll(BDFDB.dotCNS.textareawrapchat + ".translate-button"), "translating-active", this.translating);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
buttoncontainer.insertBefore(translateButton, buttoncontainer.firstElementChild);
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.addClass(translateButton, instance.props.type);
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.toggleClass(translateButton, "translating-active", this.translating);
|
|
|
|
|
|
|
|
BDFDB.ListenerUtils.add(this, textarea, "input", () => {
|
|
|
|
BDFDB.ListenerUtils.add(this, textarea, "input", () => {
|
|
|
|
if (this.doTranslate) {
|
|
|
|
if (this.doTranslate) {
|
|
|
|
this.doTranslate = false;
|
|
|
|
this.doTranslate = false;
|
|
|
@ -358,6 +259,69 @@ class GoogleTranslateOption {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (methodnames.includes("render")) {
|
|
|
|
|
|
|
|
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {props:[["className", BDFDB.disCN.textareapickerbuttons]]});
|
|
|
|
|
|
|
|
if (!this.stopping && index > -1 && children[index].props && children[index].props.children) {
|
|
|
|
|
|
|
|
children[index].props.children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PopoutContainer, {
|
|
|
|
|
|
|
|
onClose: instance => {
|
|
|
|
|
|
|
|
let channelTextareaButtonIns = BDFDB.ReactUtils.findOwner(instance, {name:"ChannelTextAreaButton"});
|
|
|
|
|
|
|
|
if (channelTextareaButtonIns) {
|
|
|
|
|
|
|
|
channelTextareaButtonIns.props.isActive = false;
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.forceUpdate(channelTextareaButtonIns);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onContextMenu: _ => {
|
|
|
|
|
|
|
|
this.translating = !this.translating;
|
|
|
|
|
|
|
|
let channelTextareaButtonIns = BDFDB.ReactUtils.findOwner(instance, {name:"ChannelTextAreaButton"});
|
|
|
|
|
|
|
|
if (channelTextareaButtonIns) {
|
|
|
|
|
|
|
|
channelTextareaButtonIns.props.className = ["translate-button", this.translating ? "translating-active" : null, BDFDB.disCN.textareapickerbutton].filter(n => n).join(" ");
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.forceUpdate(channelTextareaButtonIns);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
renderPopout: instance => {
|
|
|
|
|
|
|
|
let channelTextareaButtonIns = BDFDB.ReactUtils.findOwner(instance, {name:"ChannelTextAreaButton"});
|
|
|
|
|
|
|
|
if (channelTextareaButtonIns) {
|
|
|
|
|
|
|
|
channelTextareaButtonIns.props.isActive = true;
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.forceUpdate(channelTextareaButtonIns);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let popoutelements = [];
|
|
|
|
|
|
|
|
popoutelements.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
|
|
|
|
|
|
|
className: BDFDB.disCNS.margintop8 + BDFDB.disCN.marginbottom8,
|
|
|
|
|
|
|
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
|
|
|
|
|
|
|
label: `Words starting with "!" will be ignored`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
popoutelements.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
|
|
|
|
|
|
|
className: BDFDB.disCN.marginbottom8
|
|
|
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
popoutelements = popoutelements.concat(this.createSelects(true));
|
|
|
|
|
|
|
|
popoutelements.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
|
|
|
|
|
|
|
type: "Switch",
|
|
|
|
|
|
|
|
className: BDFDB.disCN.marginbottom20,
|
|
|
|
|
|
|
|
label: "Translate:",
|
|
|
|
|
|
|
|
value: this.translating,
|
|
|
|
|
|
|
|
onChange: value => {
|
|
|
|
|
|
|
|
this.translating = value;
|
|
|
|
|
|
|
|
if (channelTextareaButtonIns) {
|
|
|
|
|
|
|
|
channelTextareaButtonIns.props.className = ["translate-button", this.translating ? "translating-active" : null, BDFDB.disCN.textareapickerbutton].filter(n => n).join(" ");
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.forceUpdate(channelTextareaButtonIns);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
return popoutelements;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
width: 400,
|
|
|
|
|
|
|
|
padding: 10,
|
|
|
|
|
|
|
|
animation: BDFDB.LibraryComponents.PopoutContainer.Animation.SCALE,
|
|
|
|
|
|
|
|
position: BDFDB.LibraryComponents.PopoutContainer.Positions.TOP,
|
|
|
|
|
|
|
|
align: BDFDB.LibraryComponents.PopoutContainer.Align.RIGHT,
|
|
|
|
|
|
|
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ChannelTextAreaButton, {
|
|
|
|
|
|
|
|
className: ["translate-button", this.translating ? "translating-active" : null, BDFDB.disCN.textareapickerbutton].filter(n => n).join(" "),
|
|
|
|
|
|
|
|
iconSVG: `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="${BDFDB.disCN.textareaicon}" viewBox="0 0 22 22" fill="currentColor"><path d="M 19.794, 3.299 H 9.765 L 8.797, 0 h -6.598 C 0.99, 0, 0, 0.99, 0, 2.199 V 16.495 c 0, 1.21, 0.99, 2.199, 2.199, 2.199 H 9.897 l 1.1, 3.299 H 19.794 c 1.21, 0, 2.199 -0.99, 2.199 -2.199 V 5.498 C 21.993, 4.289, 21.003, 3.299, 19.794, 3.299 z M 5.68, 13.839 c -2.48, 0 -4.492 -2.018 -4.492 -4.492 s 2.018 -4.492, 4.492 -4.492 c 1.144, 0, 2.183, 0.407, 3.008, 1.171 l 0.071, 0.071 l -1.342, 1.298 l -0.066 -0.06 c -0.313 -0.297 -0.858 -0.643 -1.671 -0.643 c -1.441, 0 -2.612, 1.193 -2.612, 2.661 c 0, 1.468, 1.171, 2.661, 2.612, 2.661 c 1.507, 0, 2.161 -0.962, 2.337 -1.606 h -2.43 v -1.704 h 4.344 l 0.016, 0.077 c 0.044, 0.231, 0.06, 0.434, 0.06, 0.665 C 10.001, 12.036, 8.225, 13.839, 5.68, 13.839 z M 11.739, 9.979 h 4.393 c 0, 0 -0.374, 1.446 -1.715, 3.008 c -0.588 -0.676 -0.995 -1.336 -1.254 -1.864 h -1.089 L 11.739, 9.979 z M 13.625, 13.839 l -0.588, 0.583 l -0.72 -2.452 C 12.685, 12.63, 13.13, 13.262, 13.625, 13.839 z M 20.893, 19.794 c 0, 0.605 -0.495, 1.1 -1.1, 1.1 H 12.096 l 2.199 -2.199 l -0.896 -3.041 l 1.012 -1.012 l 2.953, 2.953 l 0.803 -0.803 l -2.975 -2.953 c 0.99 -1.138, 1.759 -2.474, 2.106 -3.854 h 1.397 V 8.841 H 14.697 v -1.144 h -1.144 v 1.144 H 11.398 l -1.309 -4.443 H 19.794 c 0.605, 0, 1.1, 0.495, 1.1, 1.1 V 19.794 z"/></svg>`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
processMessage (instance, wrapper, returnvalue) {
|
|
|
|
processMessage (instance, wrapper, returnvalue) {
|
|
|
@ -377,6 +341,107 @@ class GoogleTranslateOption {
|
|
|
|
if (messagediv && !wrapper.querySelector(".GTO-translation")) BDFDB.DOMUtils.removeClass(messagediv, "GTO-translated-message");
|
|
|
|
if (messagediv && !wrapper.querySelector(".GTO-translation")) BDFDB.DOMUtils.removeClass(messagediv, "GTO-translated-message");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processStandardSidebarView (instance, wrapper, returnvalue) {
|
|
|
|
|
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
|
|
|
|
delete this.SettingsUpdated;
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this, "ChannelTextArea");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createSelects (inPopout) {
|
|
|
|
|
|
|
|
let selects = [];
|
|
|
|
|
|
|
|
for (let key in this.defaults.choices) {
|
|
|
|
|
|
|
|
let isOutput = this.defaults.choices[key].direction == "output";
|
|
|
|
|
|
|
|
selects.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
|
|
|
|
|
|
|
|
title: this.defaults.choices[key].description,
|
|
|
|
|
|
|
|
titlechildren: isOutput ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
|
|
|
|
|
|
|
|
look: BDFDB.LibraryComponents.Button.Looks.BLANK,
|
|
|
|
|
|
|
|
size: BDFDB.LibraryComponents.Button.Sizes.NONE,
|
|
|
|
|
|
|
|
onClick: e => {
|
|
|
|
|
|
|
|
let place = this.defaults.choices[key].place;
|
|
|
|
|
|
|
|
let input = this.getLanguageChoice("output", place);
|
|
|
|
|
|
|
|
let output = this.getLanguageChoice("input", place);
|
|
|
|
|
|
|
|
output = output == "auto" ? "en" : output;
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(input, this, "choices", "input" + place);
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(output, this, "choices", "output" + place);
|
|
|
|
|
|
|
|
let containerIns = BDFDB.ReactUtils.findOwner(e._targetInst, {name:["BDFDB_Popout", "BDFDB_SettingsPanel"], up:true});
|
|
|
|
|
|
|
|
if (containerIns) {
|
|
|
|
|
|
|
|
let allSelectIns = BDFDB.ReactUtils.findOwner(containerIns, {name:"BDFDB_Select", all:true, noCopies:true});
|
|
|
|
|
|
|
|
for (let i in allSelectIns) {
|
|
|
|
|
|
|
|
let selectIns = allSelectIns[i];
|
|
|
|
|
|
|
|
if (selectIns && selectIns.props && selectIns.props.id && this.defaults.choices[selectIns.props.id].place == place) {
|
|
|
|
|
|
|
|
selectIns.props.value = this.defaults.choices[selectIns.props.id].direction == "input" ? output : input;
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.forceUpdate(selectIns);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
|
|
|
|
|
|
|
iconSVG: `<svg class="reverse-button" version="1.1" xmlns="http://www.w3.org/2000/svg" width="21" height="21" fill="currentColor"><path d="M 0, 10.515 c 0, 2.892, 1.183, 5.521, 3.155, 7.361 L 0, 21.031 h 7.887 V 13.144 l -2.892, 2.892 C 3.549, 14.722, 2.629, 12.75, 2.629, 10.515 c 0 -3.418, 2.235 -6.309, 5.258 -7.492 v -2.629 C 3.418, 1.577, 0, 5.652, 0, 10.515 z M 21.031, 0 H 13.144 v 7.887 l 2.892 -2.892 C 17.482, 6.309, 18.402, 8.281, 18.402, 10.515 c 0, 3.418 -2.235, 6.309 -5.258, 7.492 V 20.768 c 4.469 -1.183, 7.887 -5.258, 7.887 -10.121 c 0 -2.892 -1.183 -5.521 -3.155 -7.361 L 21.031, 0 z"/></svg>`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}) : null,
|
|
|
|
|
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
|
|
|
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
|
|
|
|
|
|
|
|
menuPlacement: inPopout ? BDFDB.LibraryComponents.Select.MenuPlacements.TOP : BDFDB.LibraryComponents.Select.MenuPlacements.BOTTOM,
|
|
|
|
|
|
|
|
value: this.getLanguageChoice(key),
|
|
|
|
|
|
|
|
id: key,
|
|
|
|
|
|
|
|
options: BDFDB.ObjectUtils.toArray(BDFDB.ObjectUtils.map(isOutput ? BDFDB.ObjectUtils.filter(this.languages, lang => lang.id != "auto") : this.languages, (lang, id) => {return {value:id, label:lang.name}})),
|
|
|
|
|
|
|
|
searchable: true,
|
|
|
|
|
|
|
|
optionRenderer: lang => {
|
|
|
|
|
|
|
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
|
|
|
|
|
|
|
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
|
|
|
|
|
|
|
grow: 1,
|
|
|
|
|
|
|
|
children: lang.label
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
inPopout ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FavButton, {
|
|
|
|
|
|
|
|
isFavorite: this.languages[lang.value].fav == 0,
|
|
|
|
|
|
|
|
onClick: value => {
|
|
|
|
|
|
|
|
if (value) BDFDB.DataUtils.save(true, this, "favorites", lang.value);
|
|
|
|
|
|
|
|
else BDFDB.DataUtils.remove(this, "favorites", lang.value);
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}) : null
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange: lang => {
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(lang.value, this, "choices", key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (isOutput) selects.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
|
|
|
|
|
|
|
className: BDFDB.disCN.marginbottom8
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return selects;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setLanguages () {
|
|
|
|
|
|
|
|
this.languages = Object.assign({},
|
|
|
|
|
|
|
|
{"auto": {name:"Auto", id:"auto", integrated:false, dic:false}},
|
|
|
|
|
|
|
|
BDFDB.LanguageUtils.languages,
|
|
|
|
|
|
|
|
{"binary": {name:"Binary", id:"binary", integrated:false, dic:false}},
|
|
|
|
|
|
|
|
{"braille": {name:"Braille 6-dot", id:"braille", integrated:false, dic:false}},
|
|
|
|
|
|
|
|
{"morse": {name:"Morse", id:"morse", integrated:false, dic:false}}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let favorites = BDFDB.DataUtils.load(this, "favorites");
|
|
|
|
|
|
|
|
for (let id in this.languages) this.languages[id].fav = favorites[id] != undefined ? 0 : 1;
|
|
|
|
|
|
|
|
this.languages = BDFDB.ObjectUtils.sort(this.languages, "fav");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLanguageChoice (direction, place) {
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
var type = place === undefined ? direction : direction.toLowerCase() + place.charAt(0).toUpperCase() + place.slice(1).toLowerCase();
|
|
|
|
|
|
|
|
var choice = BDFDB.DataUtils.get(this, "choices", type);
|
|
|
|
|
|
|
|
choice = this.languages[choice] ? choice : Object.keys(this.languages)[0];
|
|
|
|
|
|
|
|
choice = type.indexOf("output") > -1 && choice == "auto" ? "en" : choice;
|
|
|
|
|
|
|
|
return choice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getMessageAndPos (target) {
|
|
|
|
getMessageAndPos (target) {
|
|
|
|
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]", target) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target);
|
|
|
|
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]", target) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target);
|
|
|
@ -597,81 +662,6 @@ class GoogleTranslateOption {
|
|
|
|
return [newString.join(" "), exceptions, newString.length-count != 0];
|
|
|
|
return [newString.join(" "), exceptions, newString.length-count != 0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
openTranslatePopout (button) {
|
|
|
|
|
|
|
|
let container = document.querySelector(BDFDB.dotCN.popouts);
|
|
|
|
|
|
|
|
if (!container || BDFDB.DOMUtils.containsClass(button, BDFDB.disCN.textareabuttonactive)) return;
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.addClass(button, BDFDB.disCN.textareabuttonactive);
|
|
|
|
|
|
|
|
let translatepopout = BDFDB.DOMUtils.create(this.translatePopoutMarkup);
|
|
|
|
|
|
|
|
container.appendChild(translatepopout);
|
|
|
|
|
|
|
|
let buttonrects = BDFDB.DOMUtils.getRects(button);
|
|
|
|
|
|
|
|
translatepopout.style.setProperty("left", buttonrects.left + buttonrects.width + "px");
|
|
|
|
|
|
|
|
translatepopout.style.setProperty("top", buttonrects.top - buttonrects.height/2 + "px");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BDFDB.ListenerUtils.addToChildren(translatepopout, "click", BDFDB.dotCN.selectcontrol, e => {
|
|
|
|
|
|
|
|
let type = BDFDB.DOMUtils.getParent(BDFDB.dotCN.select, e.currentTarget).getAttribute("type");
|
|
|
|
|
|
|
|
let menulanguages = this.defaults.choices[type].direction == "Output" ? BDFDB.ObjectUtils.filter(this.languages, lang => {return lang.id != "auto";}) : this.languages;
|
|
|
|
|
|
|
|
let menu = BDFDB.openDropdownMenu(e, this.saveSelectChoice.bind(this), this.createSelectChoice.bind(this), menulanguages, true);
|
|
|
|
|
|
|
|
BDFDB.ListenerUtils.addToChildren(menu, "click", BDFDB.dotCN.giffavoritebutton, e => {
|
|
|
|
|
|
|
|
let choice = e.currentTarget.parentElement.getAttribute("value");
|
|
|
|
|
|
|
|
if (choice) {
|
|
|
|
|
|
|
|
let favorize = !BDFDB.DataUtils.load(this, "favorites", choice);
|
|
|
|
|
|
|
|
if (favorize) BDFDB.DataUtils.save(true, this, "favorites", choice);
|
|
|
|
|
|
|
|
else BDFDB.DataUtils.remove(this, "favorites", choice);
|
|
|
|
|
|
|
|
this.setLanguages();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
BDFDB.ListenerUtils.addToChildren(translatepopout, "click", ".reverse-button", e => {
|
|
|
|
|
|
|
|
let place = e.currentTarget.getAttribute("type").replace("output","");
|
|
|
|
|
|
|
|
let input = this.getLanguageChoice("output", place);
|
|
|
|
|
|
|
|
let output = this.getLanguageChoice("input", place);
|
|
|
|
|
|
|
|
output = output == "auto" ? "en" : output;
|
|
|
|
|
|
|
|
let inputselect = translatepopout.querySelector(BDFDB.dotCN.select + "[type='input" + place + "']");
|
|
|
|
|
|
|
|
let outputselect = translatepopout.querySelector(BDFDB.dotCN.select + "[type='output" + place + "']");
|
|
|
|
|
|
|
|
inputselect.setAttribute("value", input);
|
|
|
|
|
|
|
|
inputselect.querySelector(BDFDB.dotCN.title).innerText = this.languages[input].name;
|
|
|
|
|
|
|
|
outputselect.setAttribute("value", output);
|
|
|
|
|
|
|
|
outputselect.querySelector(BDFDB.dotCN.title).innerText = this.languages[output].name;
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(input, this, "choices", "input" + place);
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(output, this, "choices", "output" + place);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
translatepopout.querySelectorAll(BDFDB.dotCN.select).forEach(selectWrap => {
|
|
|
|
|
|
|
|
let language = this.getLanguageChoice(selectWrap.getAttribute("type"));
|
|
|
|
|
|
|
|
selectWrap.setAttribute("value", language);
|
|
|
|
|
|
|
|
selectWrap.querySelector(BDFDB.dotCN.title).innerText = this.languages[language].name;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var translatecheckbox = translatepopout.querySelector("#translating-checkbox");
|
|
|
|
|
|
|
|
translatecheckbox.checked = this.translating;
|
|
|
|
|
|
|
|
translatecheckbox.addEventListener("click", () => {
|
|
|
|
|
|
|
|
BDFDB.DOMUtils.toggleClass(button, "translating-active", translatecheckbox.checked);
|
|
|
|
|
|
|
|
this.translating = translatecheckbox.checked;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var removePopout = e => {
|
|
|
|
|
|
|
|
if (!translatepopout.contains(e.target)) {
|
|
|
|
|
|
|
|
document.removeEventListener("mousedown", removePopout);
|
|
|
|
|
|
|
|
translatepopout.remove();
|
|
|
|
|
|
|
|
setTimeout(() => {BDFDB.DOMUtils.removeClass(button, BDFDB.disCN.textareabuttonactive);},300);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener("mousedown", removePopout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BDFDB.initElements(translatepopout, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveSelectChoice (selectWrap, type, choice) {
|
|
|
|
|
|
|
|
if (type && choice) {
|
|
|
|
|
|
|
|
selectWrap.querySelector(BDFDB.dotCN.title).innerText = this.languages[choice].name;
|
|
|
|
|
|
|
|
BDFDB.DataUtils.save(choice, this, "choices", type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createSelectChoice (key) {
|
|
|
|
|
|
|
|
return `<div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightnormal + BDFDB.disCN.cursorpointer}" style="flex: 1 1 auto;">${this.languages[key].name}</div><div tabindex="0" class="${BDFDB.disCNS.giffavoritebutton + BDFDB.disCN.giffavoritecolor + (this.languages[key].fav == 0 ? ' ' + BDFDB.disCN.giffavoriteselected : '')}" role="button" style="width: 24px !important; height: 24px !important; position: relative !important; opacity: 1 !important; transform: none !important;"><svg class="${BDFDB.disCNS.giffavoriteicon}" name="Favorite" viewBox="2 2 20 20" width="24" height="24"></svg></div>`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getGoogleTranslateApiURL (input, output, text) {
|
|
|
|
getGoogleTranslateApiURL (input, output, text) {
|
|
|
|
input = BDFDB.LanguageUtils.languages[input] ? input : "auto";
|
|
|
|
input = BDFDB.LanguageUtils.languages[input] ? input : "auto";
|
|
|
|
return "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + input + "&tl=" + output + "&dt=t&ie=UTF-8&oe=UTF-8&q=" + encodeURIComponent(text);
|
|
|
|
return "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + input + "&tl=" + output + "&dt=t&ie=UTF-8&oe=UTF-8&q=" + encodeURIComponent(text);
|
|
|
@ -683,7 +673,7 @@ class GoogleTranslateOption {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setLabelsByLanguage () {
|
|
|
|
setLabelsByLanguage () {
|
|
|
|
switch (BDFDB.getDiscordLanguage().id) {
|
|
|
|
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
|
|
|
case "hr": //croatian
|
|
|
|
case "hr": //croatian
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
context_messagetranslateoption_text: "Prijevod poruke",
|
|
|
|
context_messagetranslateoption_text: "Prijevod poruke",
|
|
|
|