BetterDiscordAddons/Plugins/CopyRawMessage/CopyRawMessage.plugin.js

94 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-02-03 10:41:26 +01:00
//META{"name":"CopyRawMessage","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CopyRawMessage","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CopyRawMessage/CopyRawMessage.plugin.js"}*//
2019-07-22 08:59:33 +02:00
class CopyRawMessage {
getName () {return "CopyRawMessage";}
2019-11-03 19:21:41 +01:00
getVersion () {return "1.0.3";}
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-11-03 19:21:41 +01:00
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
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 () {
2020-01-17 19:50:31 +01:00
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
2020-01-21 12:56:26 +01:00
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
2019-07-22 08:59:33 +02:00
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());
2020-01-14 00:06:07 +01:00
libraryScript.addEventListener("load", _ => {this.initialize();});
2019-07-22 08:59:33 +02:00
document.head.appendChild(libraryScript);
}
2020-01-17 19:50:31 +01:00
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2020-01-14 00:06:07 +01:00
this.startTimeout = setTimeout(_ => {
2019-11-01 10:27:07 +01:00
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2019-07-22 08:59:33 +02:00
}
initialize () {
2020-01-17 19:50:31 +01:00
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-07-22 08:59:33 +02:00
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-11-01 10:14:50 +01: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 () {
2020-01-17 19:50:31 +01:00
if (window.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-11-03 19:21:41 +01:00
onMessageContextMenu (e) {
2019-11-11 10:48:30 +01:00
if (e.instance.props.message && e.instance.props.message.content) {
2019-11-03 19:21:41 +01:00
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
2019-12-05 09:10:14 +01:00
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
2019-09-11 12:14:43 +02:00
children: [
2019-12-05 09:10:14 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
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-11-03 19:21:41 +01:00
action: _ => {
BDFDB.ContextMenuUtils.close(e.instance);
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
2019-09-11 12:14:43 +02:00
}
})
]
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-11-03 19:21:41 +01:00
onMessageOptionPopout (e) {
2019-11-11 10:48:30 +01:00
if (e.instance.props.message) {
2019-11-03 19:21:41 +01:00
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["label", BDFDB.LanguageUtils.LanguageStrings.DELETE]]});
2019-12-05 09:10:14 +01:00
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
2019-10-19 11:41:39 +02:00
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
2019-11-07 22:33:27 +01:00
className: BDFDB.disCN.optionpopoutitem,
2019-11-03 19:21:41 +01:00
action: _ => {
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
e.instance.props.onClose();
2019-09-11 12:14:43 +02:00
}
2019-11-07 10:52:58 +01:00
}));
2019-09-11 12:14:43 +02:00
}
2019-08-19 19:22:49 +02:00
}
2019-07-22 08:59:33 +02:00
}