BetterDiscordAddons/Plugins/CopyRawMessage/CopyRawMessage.plugin.js

94 lines
3.7 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-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 () {
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();
2019-11-01 10:27:07 +01:00
this.startTimeout = setTimeout(() => {
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 () {
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-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 () {
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-11-03 19:21:41 +01:00
onMessageContextMenu (e) {
if (e.instance.props && e.instance.props.message && e.instance.props.message.content) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.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
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-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) {
if (e.instance.props && e.instance.props.message) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["label", BDFDB.LanguageUtils.LanguageStrings.DELETE]]});
2019-11-07 10:52:58 +01:00
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
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
}