BetterDiscordAddons/Plugins/CopyRawMessage/CopyRawMessage.plugin.js

109 lines
5.2 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"CopyRawMessage"}*//
2019-07-22 08:59:33 +02:00
class CopyRawMessage {
getName () {return "CopyRawMessage";}
2019-09-11 12:14:43 +02:00
getVersion () {return "1.0.2";}
2019-07-22 08:59:33 +02:00
getAuthor () {return "DevilBro";}
getDescription () {return "Adds a entry in the contextmenu when you right click a message that allows you to copy the raw contents of a message.";}
2019-09-04 12:34:02 +02:00
constructor () {
2019-08-19 19:22:49 +02:00
this.changelog = {
2019-09-11 12:14:43 +02:00
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
2019-08-19 19:22:49 +02:00
};
this.patchModules = {
2019-09-11 12:14:43 +02:00
"Message":"componentDidMount"
2019-08-19 19:22:49 +02:00
};
2019-09-04 12:34:02 +02:00
}
2019-07-22 08:59:33 +02:00
//legacy
load () {}
start () {
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("id", "BDFDBLibraryScript");
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-07-22 08:59:33 +02:00
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", () => {this.initialize();});
document.head.appendChild(libraryScript);
}
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-07-22 08:59:33 +02:00
}
2019-10-22 18:55:25 +02:00
else console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
2019-07-22 08:59:33 +02:00
}
stop () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2019-07-22 08:59:33 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-07-22 08:59:33 +02:00
// begin of own functions
2019-09-04 12:34:02 +02:00
2019-09-11 12:14:43 +02:00
onMessageContextMenu (instance, menu, returnvalue) {
if (instance.props && instance.props.message && instance.props.message.content && instance.props.target && !menu.querySelector(`${this.name}-contextMenuItem`)) {
2019-10-22 19:38:25 +02:00
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
2019-10-22 18:55:25 +02:00
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItemGroup, {
2019-09-11 12:14:43 +02:00
className: `BDFDB-contextMenuItemGroup ${this.name}-contextMenuItemGroup`,
children: [
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-10-19 11:41:39 +02:00
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
2019-10-23 11:10:01 +02:00
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("Copy_Raw") : null,
2019-09-11 12:14:43 +02:00
className: `BDFDB-contextMenuItem ${this.name}-contextMenuItem ${this.name}-copyraw-contextMenuItem`,
action: e => {
BDFDB.closeContextMenu(menu);
BDFDB.LibraryRequires.electron.clipboard.write({text:instance.props.message.content});
}
})
]
2019-07-22 08:59:33 +02:00
});
2019-09-11 12:14:43 +02:00
if (index > -1) children.splice(index, 0, itemgroup);
else children.push(itemgroup);
2019-07-22 08:59:33 +02:00
}
}
2019-08-19 19:22:49 +02:00
2019-09-11 12:14:43 +02:00
onMessageOptionPopout (instance, popout, returnvalue) {
if (instance.props.message && instance.props.channel && instance._reactInternalFiber.memoizedProps.target && !popout.querySelector(".copyrawmessage-itembtn")) {
2019-10-22 19:38:25 +02:00
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {props:[["label", BDFDB.LanguageUtils.LanguageStrings.DELETE]]});
2019-10-22 18:55:25 +02:00
const copyItem = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-10-19 11:41:39 +02:00
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
2019-09-11 12:14:43 +02:00
className: `${BDFDB.disCN.optionpopoutitem} BDFDB-popoutMenuItem ${this.name}-popoutMenuItem ${this.name}-copyraw-popoutMenuItem`,
action: e => {
BDFDB.LibraryRequires.electron.clipboard.write({text:instance.props.message.content});
instance.props.onClose();
}
});
children.splice(index, 0, copyItem);
}
}
processMessage (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
if (instance.props && typeof instance.props.renderButtons == "function" && !wrapper.querySelector(BDFDB.dotCN.optionpopoutbutton) && BDFDB.ReactUtils.getValue(instance, "props.message.author.id") != 1) {
2019-08-19 19:22:49 +02:00
let buttonwrap = wrapper.querySelector(BDFDB.dotCN.messagebuttoncontainer);
if (buttonwrap) {
2019-10-23 11:10:01 +02:00
let optionPopoutButton = BDFDB.DOMUtils.create(`<div tabindex="0" class="${BDFDB.disCN.optionpopoutbutton}" aria-label="More Options" role="button"><svg name="OverflowMenu" class="${BDFDB.disCN.optionpopoutbuttonicon}" aria-hidden="false" width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><path d="M24 0v24H0V0z"></path><path fill="currentColor" d="M12 16c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2zm0-6c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2zm0-6c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2z"></path></g></svg></div>`);
2019-08-19 19:22:49 +02:00
optionPopoutButton.addEventListener("click", () => {BDFDB.createMessageOptionPopout(optionPopoutButton);});
buttonwrap.appendChild(optionPopoutButton);
}
}
}
2019-07-22 08:59:33 +02:00
}