stuff
This commit is contained in:
parent
8894a62c40
commit
cf71c83570
|
@ -599,7 +599,25 @@ module.exports = (_ => {
|
|||
if (!pluginName || !url) return;
|
||||
let updateNotice = document.querySelector("#pluginNotice");
|
||||
if (!updateNotice) {
|
||||
updateNotice = BDFDB.NotificationUtils.notice(`${BDFDB.LanguageUtils.LibraryStrings.update_notice_update} <strong id="outdatedPlugins"></strong>`, {html:true, id:"pluginNotice", type:"info", btn:!BDFDB.BDUtils.getSettings(BDFDB.BDUtils.settingsIds.automaticLoading) ? BDFDB.LanguageUtils.LanguageStrings.ERRORS_RELOAD : "", customicon:`<svg height="100%" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100%" version="1.1" viewBox="0 0 2000 2000"><metadata /><defs><filter id="shadow1"><feDropShadow dx="20" dy="0" stdDeviation="20" flood-color="rgba(0,0,0,0.35)"/></filter><filter id="shadow2"><feDropShadow dx="15" dy="0" stdDeviation="20" flood-color="rgba(255,255,255,0.15)"/></filter><filter id="shadow3"><feDropShadow dx="10" dy="0" stdDeviation="20" flood-color="rgba(0,0,0,0.35)"/></filter></defs><g><path style="filter: url(#shadow3)" d="M1195.44+135.442L1195.44+135.442L997.6+136.442C1024.2+149.742+1170.34+163.542+1193.64+179.742C1264.34+228.842+1319.74+291.242+1358.24+365.042C1398.14+441.642+1419.74+530.642+1422.54+629.642L1422.54+630.842L1422.54+632.042C1422.54+773.142+1422.54+1228.14+1422.54+1369.14L1422.54+1370.34L1422.54+1371.54C1419.84+1470.54+1398.24+1559.54+1358.24+1636.14C1319.74+1709.94+1264.44+1772.34+1193.64+1821.44C1171.04+1837.14+1025.7+1850.54+1000+1863.54L1193.54+1864.54C1539.74+1866.44+1864.54+1693.34+1864.54+1296.64L1864.54+716.942C1866.44+312.442+1541.64+135.442+1195.44+135.442Z" fill="#171717" opacity="1"/><path style="filter: url(#shadow2)" d="M1695.54+631.442C1685.84+278.042+1409.34+135.442+1052.94+135.442L361.74+136.442L803.74+490.442L1060.74+490.442C1335.24+490.442+1335.24+835.342+1060.74+835.342L1060.74+1164.84C1150.22+1164.84+1210.53+1201.48+1241.68+1250.87C1306.07+1353+1245.76+1509.64+1060.74+1509.64L361.74+1863.54L1052.94+1864.54C1409.24+1864.54+1685.74+1721.94+1695.54+1368.54C1695.54+1205.94+1651.04+1084.44+1572.64+999.942C1651.04+915.542+1695.54+794.042+1695.54+631.442Z" fill="#3E82E5" opacity="1"/><path style="filter: url(#shadow1)" d="M1469.25+631.442C1459.55+278.042+1183.05+135.442+826.65+135.442L135.45+135.442L135.45+1004C135.45+1004+135.427+1255.21+355.626+1255.21C575.825+1255.21+575.848+1004+575.848+1004L577.45+490.442L834.45+490.442C1108.95+490.442+1108.95+835.342+834.45+835.342L664.65+835.342L664.65+1164.84L834.45+1164.84C923.932+1164.84+984.244+1201.48+1015.39+1250.87C1079.78+1353+1019.47+1509.64+834.45+1509.64L135.45+1509.64L135.45+1864.54L826.65+1864.54C1182.95+1864.54+1459.45+1721.94+1469.25+1368.54C1469.25+1205.94+1424.75+1084.44+1346.35+999.942C1424.75+915.542+1469.25+794.042+1469.25+631.442Z" fill="#FFFFFF" opacity="1"/></g></svg>`});
|
||||
let vanishObserver = new MutationObserver(changes => {
|
||||
if (!document.contains(updateNotice)) {
|
||||
if (updateNotice.querySelector("#outdatedPlugins span")) {
|
||||
let layers = document.querySelector(BDFDB.dotCN.layers) || document.querySelector(BDFDB.dotCN.appmount);
|
||||
if (layers) layers.parentElement.insertBefore(updateNotice, layers);
|
||||
}
|
||||
else vanishObserver.disconnect();
|
||||
}
|
||||
else if (document.contains(updateNotice) && !updateNotice.querySelector("#outdatedPlugins span," + BDFDB.dotCN.noticebutton)) vanishObserver.disconnect();
|
||||
});
|
||||
vanishObserver.observe(document.body, {childList:true, subtree:true});
|
||||
updateNotice = BDFDB.NotificationUtils.notice(`${BDFDB.LanguageUtils.LibraryStrings.update_notice_update} <strong id="outdatedPlugins"></strong>`, {
|
||||
id:"pluginNotice",
|
||||
type:"info",
|
||||
html:true,
|
||||
btn:!BDFDB.BDUtils.getSettings(BDFDB.BDUtils.settingsIds.automaticLoading) ? BDFDB.LanguageUtils.LanguageStrings.ERRORS_RELOAD : "",
|
||||
customicon:`<svg height="100%" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100%" version="1.1" viewBox="0 0 2000 2000"><metadata /><defs><filter id="shadow1"><feDropShadow dx="20" dy="0" stdDeviation="20" flood-color="rgba(0,0,0,0.35)"/></filter><filter id="shadow2"><feDropShadow dx="15" dy="0" stdDeviation="20" flood-color="rgba(255,255,255,0.15)"/></filter><filter id="shadow3"><feDropShadow dx="10" dy="0" stdDeviation="20" flood-color="rgba(0,0,0,0.35)"/></filter></defs><g><path style="filter: url(#shadow3)" d="M1195.44+135.442L1195.44+135.442L997.6+136.442C1024.2+149.742+1170.34+163.542+1193.64+179.742C1264.34+228.842+1319.74+291.242+1358.24+365.042C1398.14+441.642+1419.74+530.642+1422.54+629.642L1422.54+630.842L1422.54+632.042C1422.54+773.142+1422.54+1228.14+1422.54+1369.14L1422.54+1370.34L1422.54+1371.54C1419.84+1470.54+1398.24+1559.54+1358.24+1636.14C1319.74+1709.94+1264.44+1772.34+1193.64+1821.44C1171.04+1837.14+1025.7+1850.54+1000+1863.54L1193.54+1864.54C1539.74+1866.44+1864.54+1693.34+1864.54+1296.64L1864.54+716.942C1866.44+312.442+1541.64+135.442+1195.44+135.442Z" fill="#171717" opacity="1"/><path style="filter: url(#shadow2)" d="M1695.54+631.442C1685.84+278.042+1409.34+135.442+1052.94+135.442L361.74+136.442L803.74+490.442L1060.74+490.442C1335.24+490.442+1335.24+835.342+1060.74+835.342L1060.74+1164.84C1150.22+1164.84+1210.53+1201.48+1241.68+1250.87C1306.07+1353+1245.76+1509.64+1060.74+1509.64L361.74+1863.54L1052.94+1864.54C1409.24+1864.54+1685.74+1721.94+1695.54+1368.54C1695.54+1205.94+1651.04+1084.44+1572.64+999.942C1651.04+915.542+1695.54+794.042+1695.54+631.442Z" fill="#3E82E5" opacity="1"/><path style="filter: url(#shadow1)" d="M1469.25+631.442C1459.55+278.042+1183.05+135.442+826.65+135.442L135.45+135.442L135.45+1004C135.45+1004+135.427+1255.21+355.626+1255.21C575.825+1255.21+575.848+1004+575.848+1004L577.45+490.442L834.45+490.442C1108.95+490.442+1108.95+835.342+834.45+835.342L664.65+835.342L664.65+1164.84L834.45+1164.84C923.932+1164.84+984.244+1201.48+1015.39+1250.87C1079.78+1353+1019.47+1509.64+834.45+1509.64L135.45+1509.64L135.45+1864.54L826.65+1864.54C1182.95+1864.54+1459.45+1721.94+1469.25+1368.54C1469.25+1205.94+1424.75+1084.44+1346.35+999.942C1424.75+915.542+1469.25+794.042+1469.25+631.442Z" fill="#FFFFFF" opacity="1"/></g></svg>`,
|
||||
onClose: _ => {vanishObserver.disconnect();}
|
||||
});
|
||||
updateNotice.style.setProperty("z-index", "100000", "important");
|
||||
updateNotice.style.setProperty("display", "block", "important");
|
||||
updateNotice.style.setProperty("visibility", "visible", "important");
|
||||
|
@ -1102,7 +1120,7 @@ module.exports = (_ => {
|
|||
};
|
||||
BDFDB.NotificationUtils.notice = function (text, options = {}) {
|
||||
if (!text) return;
|
||||
let layers = document.querySelector(BDFDB.dotCNC.layers + BDFDB.dotCN.appmount);
|
||||
let layers = document.querySelector(BDFDB.dotCN.layers) || document.querySelector(BDFDB.dotCN.appmount);
|
||||
if (!layers) return;
|
||||
let id = BDFDB.NumberUtils.generateId(NotificationBars);
|
||||
let notice = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCNS.notice + BDFDB.disCN.noticewrapper}" notice-id="${id}"><div class="${BDFDB.disCN.noticedismiss}" style="width: 36px !important; height: 36px !important; position: absolute !important; top: 0 !important; right: 0 !important; left: unset !important;"></div><span class="notice-message"></span></div>`);
|
||||
|
@ -1174,6 +1192,7 @@ module.exports = (_ => {
|
|||
notice.style.setProperty("height", "0px", "important");
|
||||
if (notice.tooltip && typeof notice.tooltip.removeTooltip == "function") notice.tooltip.removeTooltip();
|
||||
BDFDB.TimeUtils.timeout(_ => {
|
||||
if (typeof options.onClose == "function") options.onClose();
|
||||
BDFDB.ArrayUtils.remove(NotificationBars, id);
|
||||
BDFDB.DOMUtils.removeLocalStyle("BDFDBcustomNotificationBar" + id);
|
||||
BDFDB.DOMUtils.removeLocalStyle("BDFDBcustomNotificationBarColorCorrection" + id);
|
||||
|
|
|
@ -13,15 +13,16 @@ module.exports = (_ => {
|
|||
"info": {
|
||||
"name": "GoogleTranslateOption",
|
||||
"author": "DevilBro",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"description": "Add a Google Translate option to your context menu, which shows a preview of the translated text and on click will open the selected text in Google Translate. Also adds a translation button to your textareas, which will automatically translate the text for you before it is being send"
|
||||
},
|
||||
"changeLog": {
|
||||
"improved": {
|
||||
"Quick Action": "Added Icon to quick action bar. Holding shift while hovering a message shows the quick action bar"
|
||||
"fixed": {
|
||||
"Crashes": "No longer causes crashes"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
|
||||
getName () {return config.info.name;}
|
||||
getAuthor () {return config.info.author;}
|
||||
|
@ -73,7 +74,7 @@ module.exports = (_ => {
|
|||
};
|
||||
|
||||
var languages, translating, isTranslating, translatedMessages, oldMessages;
|
||||
var settings = {}, choices = {}, engines = {}, favorites = {};
|
||||
var settings = {}, choices = {}, exceptions = {}, engines = {}, favorites = {};
|
||||
|
||||
return class GoogleTranslateOption extends Plugin {
|
||||
onLoad() {
|
||||
|
@ -95,6 +96,9 @@ module.exports = (_ => {
|
|||
inputMessage: {value:"auto", direction:"input", place:"Message", description:"Input Language in sent Messages:"},
|
||||
outputMessage: {value:"$discord", direction:"output", place:"Message", description:"Output Language in sent Messages:"}
|
||||
},
|
||||
exceptions: {
|
||||
wordStart: {value:["!"], max:1, description:"Words starting with any of these will be ignored"}
|
||||
},
|
||||
engines: {
|
||||
translator: {value:"googleapi", description:"Translation Engine:"}
|
||||
}
|
||||
|
@ -153,6 +157,24 @@ module.exports = (_ => {
|
|||
value: settings[key]
|
||||
}));
|
||||
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCNS.dividerdefault + BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in exceptions) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
|
||||
title: this.defaults.exceptions[key].description,
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListInput, {
|
||||
placeholder: "New Exception",
|
||||
maxLength: this.defaults.exceptions[key].max,
|
||||
items: exceptions[key],
|
||||
onChange: newExceptions => {
|
||||
this.SettingsUpdated = true;
|
||||
BDFDB.DataUtils.save(newExceptions, this, "exceptions", key);
|
||||
}
|
||||
})
|
||||
}));
|
||||
|
||||
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
|
||||
}
|
||||
|
||||
|
@ -166,6 +188,7 @@ module.exports = (_ => {
|
|||
forceUpdateAll () {
|
||||
settings = BDFDB.DataUtils.get(this, "settings");
|
||||
choices = BDFDB.DataUtils.get(this, "choices");
|
||||
exceptions = BDFDB.DataUtils.get(this, "exceptions");
|
||||
engines = BDFDB.DataUtils.get(this, "engines");
|
||||
favorites = BDFDB.DataUtils.load(this, "favorites");
|
||||
|
||||
|
@ -308,10 +331,10 @@ module.exports = (_ => {
|
|||
|
||||
processChannelTextAreaContainer (e) {
|
||||
if (settings.addTranslateButton) {
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "ChannelEditorContainer"});
|
||||
if (index > -1 && children[index].props.type == BDFDB.DiscordConstants.TextareaTypes.NORMAL && !children[index].props.disabled) {
|
||||
let [children2, index2] = BDFDB.ReactUtils.findParent(e.returnvalue, {props:[["className", BDFDB.disCN.textareapickerbuttons]]});
|
||||
if (index2 > -1 && children2[index2].props && children2[index2].props.children) children2[index2].props.children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PopoutContainer, {
|
||||
let editor = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "ChannelEditorContainer"});
|
||||
if (editor && editor.props.type == BDFDB.DiscordConstants.TextareaTypes.NORMAL && !editor.props.disabled) {
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props:[["className", BDFDB.disCN.textareapickerbuttons]]});
|
||||
if (index > -1 && children[index].props && children[index].props.children) children[index].props.children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PopoutContainer, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ChannelTextAreaButton, {
|
||||
key: "translate-button",
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._googletranslateoptiontranslatebutton, translating && BDFDB.disCN._googletranslateoptiontranslating, BDFDB.disCN.textareapickerbutton),
|
||||
|
@ -346,19 +369,20 @@ module.exports = (_ => {
|
|||
BDFDB.ReactUtils.forceUpdate(channelTextareaButtonIns);
|
||||
}
|
||||
let popoutelements = [];
|
||||
popoutelements.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: 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
|
||||
}));
|
||||
if (BDFDB.ArrayUtils.is(exceptions.wordStart) && exceptions.wordStart.length) {
|
||||
popoutelements.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
||||
label: `Words starting with ${exceptions.wordStart.map(n => '"' + n + '"').join(", ")} 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.marginbottom8,
|
||||
label: "Translate your Messages before sending",
|
||||
tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H5,
|
||||
value: translating,
|
||||
|
@ -599,14 +623,14 @@ module.exports = (_ => {
|
|||
translateText (text, type, callback) {
|
||||
let toast = null, finishTranslation = translation => {
|
||||
isTranslating = false;
|
||||
if (translation) translation = this.addExceptions(translation, exceptions);
|
||||
if (translation) translation = this.addExceptions(translation, excepts);
|
||||
if (toast) {
|
||||
BDFDB.TimeUtils.clear(toast.interval);
|
||||
toast.close();
|
||||
}
|
||||
callback(translation == text ? "" : translation, input, output);
|
||||
};
|
||||
let [newtext, exceptions, translate] = this.removeExceptions(text.trim(), type);
|
||||
let [newText, excepts, translate] = this.removeExceptions(text.trim(), type);
|
||||
let input = Object.assign({}, languages[this.getLanguageChoice("input", type)]);
|
||||
let output = Object.assign({}, languages[this.getLanguageChoice("output", type)]);
|
||||
if (translate) {
|
||||
|
@ -619,27 +643,27 @@ module.exports = (_ => {
|
|||
}
|
||||
else toast.textContent = toast.textContent.indexOf(".....") > -1 ? "Translating. Please wait" : toast.textContent + ".";
|
||||
}, 500);
|
||||
let specialcase = this.checkForSpecialCase(newtext, input);
|
||||
let specialcase = this.checkForSpecialCase(newText, input);
|
||||
if (specialcase) {
|
||||
input.name = specialcase.name;
|
||||
switch (specialcase.id) {
|
||||
case "binary": newtext = this.binary2string(newtext); break;
|
||||
case "braille": newtext = this.braille2string(newtext); break;
|
||||
case "morse": newtext = this.morse2string(newtext); break;
|
||||
case "binary": newText = this.binary2string(newText); break;
|
||||
case "braille": newText = this.braille2string(newText); break;
|
||||
case "morse": newText = this.morse2string(newText); break;
|
||||
}
|
||||
}
|
||||
if (output.id == "binary" || output.id == "braille" || output.id == "morse") {
|
||||
switch (output.id) {
|
||||
case "binary": newtext = this.string2binary(newtext); break;
|
||||
case "braille": newtext = this.string2braille(newtext); break;
|
||||
case "morse": newtext = this.string2morse(newtext); break;
|
||||
case "binary": newText = this.string2binary(newText); break;
|
||||
case "braille": newText = this.string2braille(newText); break;
|
||||
case "morse": newText = this.string2morse(newText); break;
|
||||
}
|
||||
finishTranslation(newtext);
|
||||
finishTranslation(newText);
|
||||
}
|
||||
else {
|
||||
if (translationEngines[engines.translator] && typeof this[translationEngines[engines.translator].funcName] == "function") {
|
||||
isTranslating = true;
|
||||
this[translationEngines[engines.translator].funcName].apply(this, [{input, output, text:newtext, specialcase, engine:translationEngines[engines.translator]}, finishTranslation]);
|
||||
this[translationEngines[engines.translator].funcName].apply(this, [{input, output, text:newText, specialcase, engine:translationEngines[engines.translator]}, finishTranslation]);
|
||||
}
|
||||
else finishTranslation();
|
||||
}
|
||||
|
@ -861,9 +885,9 @@ module.exports = (_ => {
|
|||
return string.trim();
|
||||
}
|
||||
|
||||
addExceptions (string, exceptions) {
|
||||
for (let count in exceptions) {
|
||||
let exception = exceptions[count].indexOf("!") == 0 ? exceptions[count].slice(1) : exceptions[count];
|
||||
addExceptions (string, excepts) {
|
||||
for (let count in excepts) {
|
||||
let exception = BDFDB.ArrayUtils.is(exceptions.wordStart) && exceptions.wordStart.some(n => excepts[count].indexOf(n) == 0) ? excepts[count].slice(1) : excepts[count];
|
||||
let newstring = string.replace(new RegExp(`\[/////[ ]*${count}\]`), exception);
|
||||
if (newstring == string) string = newstring + " " + exception;
|
||||
else string = newstring;
|
||||
|
@ -872,7 +896,7 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
removeExceptions (string, type) {
|
||||
let exceptions = {}, newString = [], count = 0;
|
||||
let excepts = {}, newString = [], count = 0;
|
||||
if (type == "context") {
|
||||
let text = [], i = 0;
|
||||
string.split("").forEach(chara => {
|
||||
|
@ -883,23 +907,24 @@ module.exports = (_ => {
|
|||
for (let j in text) {
|
||||
if (text[j].indexOf("<") == 0) {
|
||||
newString.push(`[/////${count}]`);
|
||||
exceptions[count] = text[j];
|
||||
excepts[count] = text[j];
|
||||
count++;
|
||||
}
|
||||
else newString.push(text[j]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let usedExceptions = BDFDB.ArrayUtils.is(exceptions.wordStart) ? exceptions.wordStart : [];
|
||||
string.split(" ").forEach(word => {
|
||||
if (word.indexOf("<@!") == 0 || word.indexOf("<#") == 0 || word.indexOf(":") == 0 || word.indexOf("<:") == 0 || word.indexOf("<a:") == 0 || word.indexOf("@") == 0 || word.indexOf("#") == 0 || (word.indexOf("!") == 0 && word.length > 1)) {
|
||||
if (word.indexOf("<@!") == 0 || word.indexOf("<#") == 0 || word.indexOf(":") == 0 || word.indexOf("<:") == 0 || word.indexOf("<a:") == 0 || word.indexOf("@") == 0 || word.indexOf("#") == 0 || usedExceptions.some(n => word.indexOf(n) == 0 && word.length > 1)) {
|
||||
newString.push(`[/////${count}]`);
|
||||
exceptions[count] = word;
|
||||
excepts[count] = word;
|
||||
count++;
|
||||
}
|
||||
else newString.push(word);
|
||||
});
|
||||
}
|
||||
return [newString.join(" "), exceptions, newString.length-count != 0];
|
||||
return [newString.join(" "), excepts, newString.length-count != 0];
|
||||
}
|
||||
|
||||
getGoogleTranslatePageURL (input, output, text) {
|
||||
|
|
Loading…
Reference in New Issue