Skip to content

Instantly share code, notes, and snippets.

@phit
Last active July 6, 2024 19:54
Show Gist options
  • Save phit/030d8185bcc95d28203e801e5b9f9be6 to your computer and use it in GitHub Desktop.
Save phit/030d8185bcc95d28203e801e5b9f9be6 to your computer and use it in GitHub Desktop.
better discord double click edit plugin
//META{"name":"dblClickEdit"}*//
var dblClickEdit = function () {};
dblClickEdit.prototype.start = function () {
document.addEventListener("dblclick", dblClickEventListener);
};
dblClickEdit.prototype.load = function () {};
dblClickEdit.prototype.unload = function () {
document.removeEventListener("dblclick", dblClickEventListener);
};
dblClickEdit.prototype.stop = function () {
document.removeEventListener("dblclick", dblClickEventListener);
};
dblClickEdit.prototype.getName = function () {
return "Double click edit";
};
dblClickEdit.prototype.getDescription = function () {
return "Double click messages to edit them";
};
dblClickEdit.prototype.getVersion = function () {
return "1.1.0";
};
dblClickEdit.prototype.getAuthor = function () {
return "phit";
};
function dblClickEventListener(e) {
var parents = getParents(e.target, "message_d5deea")
if (parents.length > 0) {
var msg = parents[parents.length - 1];
var opt = msg.querySelectorAll(".button_ef319f");
for (i = 0; i < opt.length; i++) {
if (opt[i].getAttribute('aria-label') == 'Edit') {
opt[i].click();
break;
}
}
}
}
function getParents(el, untilClass) {
var parents = [];
var p = el.parentNode;
var iter = 0;
while (iter < 5 && p !== undefined && p.classList !== undefined && !p.classList.contains(untilClass)) {
var o = p;
if (p.classList.contains(untilClass)) {
parents.push(o);
}
p = o.parentNode;
iter++;
}
if (p.classList.contains(untilClass)) {
var o = p;
parents.push(o);
}
return parents;
}
@phit
Copy link
Author

phit commented Jul 29, 2021

@Arjun-Anubis hold shift when doubleclicking and it will actually work with replying to yourself

@ArchWand
Copy link

For clarification to those looking for a Double Click to Reply plugin, it worked for me to just change the 'Edit' on line 36 to 'Reply'.

Tbh I'd love if this plugin had a settings menu and you could choose whether double-clicking edits or replies, but I don't know enough code to do that.

@Arjun-Anubis
Copy link

Getting this notification like 5 months later, but yes shift while double clicking works! Thanks!

@Vexadros
Copy link

Seems like it broke

@phit
Copy link
Author

phit commented Jan 30, 2022

@Vexadros I just updated it for the latest discord changes!

@Vexadros
Copy link

@phit Wow that was fast, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment