aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/messageActions.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
committerVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
commitf60ccb766f30e7518bc348013b72f071f86ecbc6 (patch)
tree5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/plugins/messageActions.ts
parentbac8a648b6012e221fd2150062d2080b9ed0d702 (diff)
downloadVencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.gz
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.bz2
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.zip
Add Plugin.start, make Settings actually start/stop plugins
Diffstat (limited to 'src/plugins/messageActions.ts')
-rw-r--r--src/plugins/messageActions.ts23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts
index db4b808..961be12 100644
--- a/src/plugins/messageActions.ts
+++ b/src/plugins/messageActions.ts
@@ -1,12 +1,17 @@
-import { addClickListener } from "../api/MessageEvents";
+import { addClickListener, removeClickListener } from '../api/MessageEvents';
import definePlugin from "../utils/types";
import { find, findByProps } from "../webpack";
+let isDeletePressed = false;
+const keydown = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = true);
+const keyup = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = false);
+
export default definePlugin({
name: "MessageQuickActions",
description: "Quick Delete, Quick edit",
author: "Vendicated",
dependencies: ["MessageEventsAPI"],
+
start() {
const { deleteMessage, startEditMessage } = findByProps("deleteMessage");
const { can } = findByProps("can", "initialize");
@@ -14,14 +19,10 @@ export default definePlugin({
const { getCurrentUser } = findByProps("getCurrentUser");
let isDeletePressed = false;
- document.addEventListener("keydown", e => {
- if (e.key === "Backspace") isDeletePressed = true;
- });
- document.addEventListener("keyup", e => {
- if (e.key === "Backspace") isDeletePressed = false;
- });
+ document.addEventListener("keydown", keydown);
+ document.addEventListener("keyup", keyup);
- addClickListener((msg, chan, event) => {
+ this.onClick = addClickListener((msg, chan, event) => {
const isMe = msg.author.id === getCurrentUser().id;
if (!isDeletePressed) {
if (isMe && event.detail >= 2) {
@@ -33,5 +34,11 @@ export default definePlugin({
event.preventDefault();
}
});
+ },
+
+ stop() {
+ removeClickListener(this.onClick);
+ document.removeEventListener("keydown", keydown);
+ document.removeEventListener("keyup", keyup);
}
}); \ No newline at end of file