This commit is contained in:
Mirco Wittrien 2021-03-09 15:47:58 +01:00
parent b3e0dfda57
commit 687a912636
2 changed files with 6 additions and 45 deletions

View File

@ -65,55 +65,18 @@ module.exports = (_ => {
return template.content.firstElementChild; return template.content.firstElementChild;
} }
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var settings = {};
return class CopyRawMessage extends Plugin { return class CopyRawMessage extends Plugin {
onLoad () { onLoad () {}
this.defaults = {
settings: {
copyOnlySelected: {value: true, description: "Only copy selected text of a message"}
}
};
}
onStart () { onStart () {}
this.forceUpdateAll();
}
onStop () { onStop () {}
this.forceUpdateAll();
}
getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = [];
for (let key in settings) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
}
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
}
onMessageContextMenu (e) { onMessageContextMenu (e) {
if (e.instance.props.message) { if (e.instance.props.message) {
let content = e.instance.props.message.content; let content = e.instance.props.message.content;
let messageString = [e.instance.props.message.content, BDFDB.ArrayUtils.is(e.instance.props.message.attachments) && e.instance.props.message.attachments.map(n => n.url)].flat(10).filter(n => n).join("\n"); let messageString = [e.instance.props.message.content, BDFDB.ArrayUtils.is(e.instance.props.message.attachments) && e.instance.props.message.attachments.map(n => n.url)].flat(10).filter(n => n).join("\n");
let selectedText = settings.copyOnlySelected && document.getSelection().toString().trim(); let selectedText = document.getSelection().toString().trim();
if (selectedText) messageString = BDFDB.StringUtils.extractSelection(messageString, selectedText); if (selectedText) messageString = BDFDB.StringUtils.extractSelection(messageString, selectedText);
let embed = BDFDB.DOMUtils.getParent(BDFDB.dotCN.embedwrapper, e.instance.props.target); let embed = BDFDB.DOMUtils.getParent(BDFDB.dotCN.embedwrapper, e.instance.props.target);
let embedData = e.instance.props.message.embeds[embed ? Array.from(embed.parentElement.querySelectorAll(BDFDB.dotCN.embedwrapper)).indexOf(embed) : -1]; let embedData = e.instance.props.message.embeds[embed ? Array.from(embed.parentElement.querySelectorAll(BDFDB.dotCN.embedwrapper)).indexOf(embed) : -1];

View File

@ -115,10 +115,8 @@ module.exports = (_ => {
this.defaults = { this.defaults = {
general: { general: {
quoteOnlySelected: {value: true, description: "Only insert selected Text in a Quoted Message"},
holdShiftToolbar: {value: false, description: "Need to hold Shift on a Message to show Quick Quote"}, holdShiftToolbar: {value: false, description: "Need to hold Shift on a Message to show Quick Quote"},
alwaysCopy: {value: false, description: "Always copy Quote to Clipboard without holding Shift"}, alwaysCopy: {value: false, description: "Always copy Quote to Clipboard without holding Shift"},
ignoreMentionInDM: {value: true, description: "Do not add a mention in Direct Messages"},
forceZeros: {value: false, description: "Force leading Zeros"} forceZeros: {value: false, description: "Force leading Zeros"}
} }
}; };
@ -401,7 +399,7 @@ module.exports = (_ => {
} }
let content = message.content; let content = message.content;
let selectedText = this.settings.general.quoteOnlySelected && document.getSelection().toString().trim(); let selectedText = document.getSelection().toString().trim();
if (selectedText) content = BDFDB.StringUtils.extractSelection(content, selectedText); if (selectedText) content = BDFDB.StringUtils.extractSelection(content, selectedText);
if (content) { if (content) {
content = content.replace(/(@everyone|@here)/g, "`$1`").replace(/``(@everyone|@here)``/g, "`$1`"); content = content.replace(/(@everyone|@here)/g, "`$1`").replace(/``(@everyone|@here)``/g, "`$1`");
@ -419,7 +417,7 @@ module.exports = (_ => {
let quotedLines = unquotedLines.slice(unquotedLines.findIndex(line => line.trim().length > 0)).map(line => "> " + line + "\n").join(""); let quotedLines = unquotedLines.slice(unquotedLines.findIndex(line => line.trim().length > 0)).map(line => "> " + line + "\n").join("");
return BDFDB.StringUtils.insertNRST(quoteFormat) return BDFDB.StringUtils.insertNRST(quoteFormat)
.replace("$mention", this.settings.general.ignoreMentionInDM && channel.isDM() ? "" : `<@!${message.author.id}>`) .replace("$mention", channel.isDM() ? "" : `<@!${message.author.id}>`)
.replace("$link", `<https://discordapp.com/channels/${guild.id}/${channel.id}/${message.id}>`) .replace("$link", `<https://discordapp.com/channels/${guild.id}/${channel.id}/${message.id}>`)
.replace("$authorName", member && member.nick || message.author.username || "") .replace("$authorName", member && member.nick || message.author.username || "")
.replace("$authorAccount", `${message.author.username}#${message.author.discriminator}`) .replace("$authorAccount", `${message.author.username}#${message.author.discriminator}`)