Update CopyRawMessage.plugin.js
This commit is contained in:
parent
65679d5942
commit
411f0e1f63
|
@ -3,20 +3,34 @@
|
|||
class CopyRawMessage {
|
||||
getName () {return "CopyRawMessage";}
|
||||
|
||||
getVersion () {return "1.0.0";}
|
||||
getVersion () {return "1.0.1";}
|
||||
|
||||
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.";}
|
||||
|
||||
initConstructor () {
|
||||
this.messageContextEntryMarkup =
|
||||
this.changelog = {
|
||||
"added":[["Message 3-dot entry","Added the copy entry to the message 3-dot menu"]]
|
||||
};
|
||||
|
||||
this.patchModules = {
|
||||
"Message":"componentDidMount",
|
||||
"MessageOptionPopout":"componentDidMount"
|
||||
};
|
||||
|
||||
this.messageCopyRawEntryMarkup =
|
||||
`<div class="${BDFDB.disCN.contextmenuitemgroup}">
|
||||
<div class="${BDFDB.disCN.contextmenuitem} copyrawmessage-item">
|
||||
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">Copy Raw Message</div></span>
|
||||
<div class="${BDFDB.disCN.contextmenuhint}"></div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
this.popoutCopyRawEntryMarkup =
|
||||
`<button role="menuitem" type="button" class="${BDFDB.disCNS.optionpopoutitem + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookblank + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCN.buttongrow} copyrawmessage-itembtn">
|
||||
<div class="${BDFDB.disCN.buttoncontents}">Copy raw</div>
|
||||
</button>`;
|
||||
}
|
||||
|
||||
//legacy
|
||||
|
@ -75,15 +89,37 @@ class CopyRawMessage {
|
|||
|
||||
onMessageContextMenu (instance, menu) {
|
||||
if (instance.props && instance.props.message && instance.props.message.content && instance.props.target && !menu.querySelector(".copyrawmessage-item")) {
|
||||
let messageContextEntry = BDFDB.htmlToElement(this.messageContextEntryMarkup);
|
||||
let messageCopyRawEntry = BDFDB.htmlToElement(this.messageCopyRawEntryMarkup);
|
||||
let devgroup = BDFDB.getContextMenuDevGroup(menu);
|
||||
if (devgroup) devgroup.parentElement.insertBefore(messageContextEntry, devgroup);
|
||||
else menu.appendChild(messageContextEntry, menu);
|
||||
let copyrawmessageitem = messageContextEntry.querySelector(".copyrawmessage-item");
|
||||
if (devgroup) devgroup.parentElement.insertBefore(messageCopyRawEntry, devgroup);
|
||||
else menu.appendChild(messageCopyRawEntry, menu);
|
||||
let copyrawmessageitem = messageCopyRawEntry.querySelector(".copyrawmessage-item");
|
||||
copyrawmessageitem.addEventListener("click", () => {
|
||||
BDFDB.closeContextMenu(menu);
|
||||
require("electron").clipboard.write({text:instance.props.message.content});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
processMessage (instance, wrapper) {
|
||||
if (instance.props && typeof instance.props.renderButtons == "function" && !wrapper.querySelector(BDFDB.dotCN.optionpopoutbutton) && BDFDB.getReactValue(instance, "props.message.author.id") != 1) {
|
||||
let buttonwrap = wrapper.querySelector(BDFDB.dotCN.messagebuttoncontainer);
|
||||
if (buttonwrap) {
|
||||
let optionPopoutButton = BDFDB.htmlToElement(`<div class="${BDFDB.disCN.optionpopoutbutton}"></div>`);
|
||||
optionPopoutButton.addEventListener("click", () => {BDFDB.createMessageOptionPopout(optionPopoutButton);});
|
||||
buttonwrap.appendChild(optionPopoutButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processMessageOptionPopout (instance, wrapper) {
|
||||
if (instance.props.message && instance.props.channel && instance._reactInternalFiber.memoizedProps.target && !wrapper.querySelector(".copyrawmessage-itembtn")) {
|
||||
let popoutCopyRawEntry = BDFDB.htmlToElement(this.popoutCopyRawEntryMarkup);
|
||||
wrapper.appendChild(popoutCopyRawEntry);
|
||||
popoutCopyRawEntry.addEventListener("click", () => {
|
||||
require("electron").clipboard.write({text:instance.props.message.content});
|
||||
instance.props.onClose();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue