EndPwn3Plugins/plugins/dblclickedit.js
2018-06-16 09:03:45 -06:00

34 lines
No EOL
1.5 KiB
JavaScript

exports.manifest = {
author: "Cynosphere, Jiiks",
name: "Double Click Edit",
description: "Double click messages to edit them. Hold ctrl while double clicking to copy message contents."
}
exports.start = function(){
document.addEventListener("dblclick", ev => {
let target = ev.target;
if(target && target.className && (target.className.includes("markup") || target.className.includes("hljs") || target.className.includes("inline"))) {
let msg = target;
if(!ev.ctrlKey){
let opt = msg.parentNode.parentNode.className.includes("markup") ? msg.parentNode.parentNode.parentNode.querySelector(".btn-option") : msg.parentNode.querySelector(".btn-option");
opt.click();
let options = document.querySelectorAll(".option-popout .btn-item");
for(i in options){
let o = options[i];
if(o.innerHTML == "Edit") o.click();
}
}else{
var range = document.createRange();
range.selectNode(msg);
window.getSelection().addRange(range);
try {
for(var i=0;i<5;i++){
document.execCommand('copy');
}
} catch (err) {
console.log(err);
}
window.getSelection().removeRange(range);
}
}
});
}