From 4e0c452de11845d2cbbc120985191de856573d11 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 24 Oct 2019 11:47:57 +0200 Subject: [PATCH] stuff --- .../CompleteTimestamps.plugin.js | 2 +- Plugins/CreationDate/CreationDate.plugin.js | 4 +- Plugins/EditChannels/EditChannels.plugin.js | 2 +- .../EmojiStatistics/EmojiStatistics.plugin.js | 2 +- .../GoogleSearchReplace.plugin.js | 2 +- .../GoogleTranslateOption.plugin.js | 398 +++++++++--------- Plugins/JoinedAtDate/JoinedAtDate.plugin.js | 4 +- .../LastMessageDate/LastMessageDate.plugin.js | 4 +- Plugins/PersonalPins/PersonalPins.plugin.js | 4 +- .../ReadAllNotificationsButton.plugin.js | 2 +- 10 files changed, 207 insertions(+), 217 deletions(-) diff --git a/Plugins/CompleteTimestamps/CompleteTimestamps.plugin.js b/Plugins/CompleteTimestamps/CompleteTimestamps.plugin.js index 736b54c3ea..a8d0e5a3e2 100644 --- a/Plugins/CompleteTimestamps/CompleteTimestamps.plugin.js +++ b/Plugins/CompleteTimestamps/CompleteTimestamps.plugin.js @@ -240,7 +240,7 @@ class CompleteTimestamps { } else { let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat"); - languageid = BDFDB.getDiscordLanguage().id; + languageid = BDFDB.LanguageUtils.getLanguage().id; let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = ""; if (ownformat.indexOf("$timemode") > -1) { timemode = hour >= 12 ? "PM" : "AM"; diff --git a/Plugins/CreationDate/CreationDate.plugin.js b/Plugins/CreationDate/CreationDate.plugin.js index 48435b2226..891240c089 100644 --- a/Plugins/CreationDate/CreationDate.plugin.js +++ b/Plugins/CreationDate/CreationDate.plugin.js @@ -230,7 +230,7 @@ class CreationDate { } else { let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat"); - languageid = BDFDB.getDiscordLanguage().id; + languageid = BDFDB.LanguageUtils.getLanguage().id; let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = ""; if (ownformat.indexOf("$timemode") > -1) { timemode = hour >= 12 ? "PM" : "AM"; @@ -269,7 +269,7 @@ class CreationDate { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { createdat_text: "Izrađen {{time}}" diff --git a/Plugins/EditChannels/EditChannels.plugin.js b/Plugins/EditChannels/EditChannels.plugin.js index 5ccba1ad33..f47f2008e9 100644 --- a/Plugins/EditChannels/EditChannels.plugin.js +++ b/Plugins/EditChannels/EditChannels.plugin.js @@ -682,7 +682,7 @@ class EditChannels { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { context_localchannelsettings_text: "Postavke lokalnih kanala", diff --git a/Plugins/EmojiStatistics/EmojiStatistics.plugin.js b/Plugins/EmojiStatistics/EmojiStatistics.plugin.js index e945dfdc29..7bfc14e251 100644 --- a/Plugins/EmojiStatistics/EmojiStatistics.plugin.js +++ b/Plugins/EmojiStatistics/EmojiStatistics.plugin.js @@ -324,7 +324,7 @@ class EmojiStatistics { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { modal_header_text: "Statistike o emojima", diff --git a/Plugins/GoogleSearchReplace/GoogleSearchReplace.plugin.js b/Plugins/GoogleSearchReplace/GoogleSearchReplace.plugin.js index d6e5d355f7..65f66cfa39 100644 --- a/Plugins/GoogleSearchReplace/GoogleSearchReplace.plugin.js +++ b/Plugins/GoogleSearchReplace/GoogleSearchReplace.plugin.js @@ -142,7 +142,7 @@ class GoogleSearchReplace { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { context_googlesearchreplace_text: "Pretražujte s ...", diff --git a/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js b/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js index cc42c67ebb..b09713e164 100644 --- a/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js +++ b/Plugins/GoogleTranslateOption/GoogleTranslateOption.plugin.js @@ -17,7 +17,7 @@ class GoogleTranslateOption { this.labels = {}; this.patchModules = { - "ChannelTextArea":"componentDidMount", + "ChannelTextArea":["componentDidMount","render"], "Message":"componentDidMount", "MessageContent":"componentDidMount", "StandardSidebarView":"componentWillUnmount" @@ -40,66 +40,23 @@ class GoogleTranslateOption { this.defaults = { settings: { - addTranslateButton: {value:true, description:"Adds an translate button to the chatbar."}, - sendOriginalMessage: {value:false, description:"Send the original message together with the translation."} + addTranslateButton: {value:true, description:"Adds an translate button to the chatbar."}, + sendOriginalMessage: {value:false, description:"Send the original message together with the translation."} }, choices: { - inputContext: {value:"auto", place:"Context", direction:"Input", popout:false, description:"Input Language in selected Messages:"}, - outputContext: {value:"$discord", place:"Context", direction:"Output", popout:false, description:"Output Language in selected Messages:"}, - inputMessage: {value:"auto", place:"Message", direction:"Input", popout:true, description:"Input Language in your Message:"}, - outputMessage: {value:"$discord", place:"Message", direction:"Output", popout:true, description:"Output Language in your Message:"} + inputContext: {value:"auto", direction:"input", place:"Context", description:"Input Language in selected Messages:"}, + outputContext: {value:"$discord", direction:"output", place:"Context", description:"Output Language in selected Messages:"}, + inputMessage: {value:"auto", direction:"input", place:"Message", description:"Input Language in your Message:"}, + outputMessage: {value:"$discord", direction:"output", place:"Message", description:"Output Language in your Message:"} } }; - this.translateButtonMarkup = - ``; - - this.reverseButtonMarkup = - ` - - `; - - this.translatePopoutMarkup = - `
-
-
-

Words starting with "!" will be ignored

-
- ${Object.keys(this.defaults.choices).map((key, i) => - `
-

${this.defaults.choices[key].description}

- ${this.defaults.choices[key].direction == "Output" ? this.reverseButtonMarkup.replace("REPLACETYPE",key) : ""} -
-
${BDFDB.createSelectMenu(`
`, this.defaults.choices[key].value, key)}
`).join("")} -
-

Translate:

-
- -
-
-
-
`; - this.css = ` - ${BDFDB.dotCNS.textareawrapall + BDFDB.dotCN.textareainner} { - 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} { + .translate-button.translating-active ${BDFDB.dotCN.textareaicon} { color: #F04747 !important; } .reverse-button { - margin-top: -5px; + margin-right: 5px; opacity: 0.2; transition: all 200ms ease; } @@ -113,10 +70,6 @@ class GoogleTranslateOption { cursor: pointer; 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.messageaccessory + BDFDB.dotCN.embeddescription} { font-size: 0 !important; @@ -138,29 +91,20 @@ class GoogleTranslateOption { getSettingsPanel () { if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; - var choices = BDFDB.DataUtils.get(this, "choices"); - var settings = BDFDB.DataUtils.get(this, "settings"); - var settingshtml = `
${this.name}
`; - for (let key in choices) { - let choice = this.getLanguageChoice(key); - settingshtml += `

${this.defaults.choices[key].description}

${BDFDB.createSelectMenu(this.createSelectChoice(choice), choice, key)}
` - } - for (let key in settings) { - settingshtml += `

${this.defaults.settings[key].description}

`; - } - settingshtml += `
`; - - let settingspanel = BDFDB.DOMUtils.create(settingshtml); - - 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; + let settings = BDFDB.DataUtils.get(this, "settings"); + let settingsitems = []; + + settingsitems = settingsitems.concat(this.createSelects(false)); + + for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSwitch, { + className: BDFDB.disCN.marginbottom8, + plugin: this, + keys: ["settings", key], + label: this.defaults.settings[key].description, + value: settings[key] + })); + + return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems); } //legacy @@ -203,8 +147,8 @@ class GoogleTranslateOption { document.querySelectorAll(BDFDB.dotCN.messagegroup + " .GTO-translated-message").forEach(message => { this.resetMessage(message); }); - - BDFDB.DOMUtils.remove(".translate-button", ".popout-googletranslate"); + + BDFDB.ModuleUtils.forceAllUpdates(this, "ChannelTextArea"); BDFDB.PluginUtils.clear(this); } @@ -284,54 +228,11 @@ class GoogleTranslateOption { } } - 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 = 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"); + processChannelTextArea (instance, wrapper, returnvalue, methodnames) { + if (instance.props.type != "normal" || instance.props.disabled) return; + if (methodnames.includes("componentDidMount") && wrapper) { + let textarea = wrapper.querySelector(BDFDB.dotCN.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", () => { if (this.doTranslate) { 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: `` + }) + })); + } + } } processMessage (instance, wrapper, returnvalue) { @@ -377,6 +341,107 @@ class GoogleTranslateOption { 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: `` + }) + }) : 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) { 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]; } - 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 `
${this.languages[key].name}
`; - } - getGoogleTranslateApiURL (input, output, text) { 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); @@ -683,7 +673,7 @@ class GoogleTranslateOption { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { context_messagetranslateoption_text: "Prijevod poruke", diff --git a/Plugins/JoinedAtDate/JoinedAtDate.plugin.js b/Plugins/JoinedAtDate/JoinedAtDate.plugin.js index 9777670d85..6ae33aa94b 100644 --- a/Plugins/JoinedAtDate/JoinedAtDate.plugin.js +++ b/Plugins/JoinedAtDate/JoinedAtDate.plugin.js @@ -242,7 +242,7 @@ class JoinedAtDate { } else { let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat"); - languageid = BDFDB.getDiscordLanguage().id; + languageid = BDFDB.LanguageUtils.getLanguage().id; let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = ""; if (ownformat.indexOf("$timemode") > -1) { timemode = hour >= 12 ? "PM" : "AM"; @@ -281,7 +281,7 @@ class JoinedAtDate { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { joinedat_text: "Pridružio {{time}}" diff --git a/Plugins/LastMessageDate/LastMessageDate.plugin.js b/Plugins/LastMessageDate/LastMessageDate.plugin.js index 80b5bc8662..b1f6b45c83 100644 --- a/Plugins/LastMessageDate/LastMessageDate.plugin.js +++ b/Plugins/LastMessageDate/LastMessageDate.plugin.js @@ -258,7 +258,7 @@ class LastMessageDate { } else { let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat"); - languageid = BDFDB.getDiscordLanguage().id; + languageid = BDFDB.LanguageUtils.getLanguage().id; let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = ""; if (ownformat.indexOf("$timemode") > -1) { timemode = hour >= 12 ? "PM" : "AM"; @@ -297,7 +297,7 @@ class LastMessageDate { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { lastmessage_text: "Posljednja poruka dana {{time}}" diff --git a/Plugins/PersonalPins/PersonalPins.plugin.js b/Plugins/PersonalPins/PersonalPins.plugin.js index ce2c6c8a3a..9bd4a5da8d 100644 --- a/Plugins/PersonalPins/PersonalPins.plugin.js +++ b/Plugins/PersonalPins/PersonalPins.plugin.js @@ -423,7 +423,7 @@ class PersonalPins { EditUsers.addTag({id:noteData.author_id,username:noteData.author_name}, username.parentElement, " " + BDFDB.disCN.bottagnametag); } let timestamp = message.querySelector(BDFDB.dotCN.messagetimestampcozy); - timestamp.innerText = date.toLocaleString(BDFDB.getDiscordLanguage().id); + timestamp.innerText = date.toLocaleString(BDFDB.LanguageUtils.getLanguage().id); timestamp.setAttribute("datetime", date); if (BDFDB.BDUtils.isPluginEnabled("CompleteTimestamps") && BDFDB.DataUtils.load("CompleteTimestamps", "settings"), "showInChat") { BDFDB.BDUtils.getPlugin("CompleteTimestamps").changeTimestamp(timestamp); @@ -584,7 +584,7 @@ class PersonalPins { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { popout_note_text: "Bilješke", diff --git a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js index 84c49b2ab3..060d7a20dc 100644 --- a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js +++ b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js @@ -235,7 +235,7 @@ class ReadAllNotificationsButton { } setLabelsByLanguage () { - switch (BDFDB.getDiscordLanguage().id) { + switch (BDFDB.LanguageUtils.getLanguage().id) { case "hr": //croatian return { context_unreadguilds_text: "Nepročitani poslužitelje",