Last active
July 6, 2024 19:54
-
-
Save phit/030d8185bcc95d28203e801e5b9f9be6 to your computer and use it in GitHub Desktop.
better discord double click edit plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like it broke