bump repo version, update charcount and dblclickedit

This commit is contained in:
Cynthia Foxwell 2018-05-30 16:33:14 -06:00
parent e39e5f596d
commit 98524a3c20
3 changed files with 91 additions and 71 deletions

View file

@ -1,20 +1,25 @@
function setupCharCount() { function setupCharCount() {
if (document.getElementById("charcounter")) return; if (document.body.contains(charcount)) return;
if (!document.querySelector("textarea[class*=\"textAreaEnabled-\"]")) return; if (!text || !document.body.contains(text)) {
text = document.querySelector('textarea[class^="textArea-"]');
}
if (!text) return;
let charcount = document.createElement("span"); text.parentNode.appendChild(charcount);
charcount.id = "charcounter";
charcount.innerHTML = "0/2000";
charcount.style.right = "40px";
charcount.style.bottom = "4px";
charcount.style.opacity = "0.5";
charcount.style.position = "absolute";
charcount.style.display = "block";
charcount.style["font-size"] = "85%";
document.querySelector("div[class*=\"channelTextAreaEnabled-\"]").appendChild(charcount);
} }
let charcount = document.createElement("span");
charcount.id = "charcounter";
charcount.innerHTML = "0/2000";
charcount.style.right = "40px";
charcount.style.bottom = "4px";
charcount.style.opacity = "0.5";
charcount.style.position = "absolute";
charcount.style.display = "block";
charcount.style["font-size"] = "85%";
let text = null;
exports = { exports = {
manifest: { manifest: {
author: "Cynosphere", author: "Cynosphere",
@ -23,30 +28,30 @@ exports = {
}, },
start: function(){ start: function(){
let charcount_mo = new MutationObserver(setupCharCount); let charcount_mo = new MutationObserver(setupCharCount);
charcount_mo.observe(document.querySelector("div[class*=\"app-\"]"), { charcount_mo.observe(document.querySelector(".app.flex-vertical"), {
childList: true, childList: true,
subtree: true subtree: true
}); });
document.addEventListener("keydown", ev => { document.addEventListener("keydown", ev => {
if (!document.getElementById("charcounter") || !document.querySelector("textarea[class*=\"textAreaEnabled-\"]")) return; if (!text) return;
setTimeout(()=>{ setImmediate(()=>{
let length = document.querySelector("textarea[class*=\"textAreaEnabled-\"]").value.length; let length = text.value.length;
document.getElementById("charcounter").innerHTML = `${length}/2000`; charcount.innerHTML = `${length}/2000`;
if (length > 1999) { if (length > 1999) {
document.getElementById("charcounter").style.color = "#FF0000"; charcount.style.color = "#FF0000";
} else if (length > 1899) { } else if (length > 1899) {
document.getElementById("charcounter").style.color = "#FF4500"; charcount.style.color = "#FF4500";
} else if (length > 1499) { } else if (length > 1499) {
document.getElementById("charcounter").style.color = "#FFA500"; charcount.style.color = "#FFA500";
} else if (length > 999) { } else if (length > 999) {
document.getElementById("charcounter").style.color = "#F1C40F"; charcount.style.color = "#F1C40F";
} else { } else {
document.getElementById("charcounter").style.color = "#FFFFFF"; charcount.style.color = "#FFFFFF";
} }
}, 50); });
}); });
} }
} }

View file

@ -1,20 +1,35 @@
exports.manifest = { exports.manifest = {
author: "Cynosphere, Jiiks", author: "Cynosphere, Jiiks",
name: "Double Click Edit", name: "Double Click Edit",
description: "Double click messages to edit them." description: "Double click messages to edit them. Hold ctrl while double clicking to copy message contents."
} }
exports.start = function(){ exports.start = function(){
document.addEventListener("dblclick", ev => { document.addEventListener("dblclick", ev => {
let target = ev.target; let target = ev.target;
if(target && target.className && target.className.includes("markup")) { console.log(target);
if(target && target.className && (target.className.includes("markup") || target.className.includes("hljs") || targe.className.includes("inline"))) {
let msg = target; let msg = target;
let opt = msg.parentNode.querySelector(".btn-option"); 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(); opt.click();
let options = document.querySelectorAll(".option-popout .btn-item"); let options = document.querySelectorAll(".option-popout .btn-item");
for(i in options){ for(i in options){
let o = options[i]; let o = options[i];
if(o.innerHTML == "Edit") o.click(); 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);
}
} }
}); });
} }

View file

@ -16,7 +16,7 @@ exports = {
author: "Cynosphere", author: "Cynosphere",
name: "Plugins Repo", name: "Plugins Repo",
description: "Download plugins.", description: "Download plugins.",
_version: 2 _version: 3
}, },
getInfo: async function(plugin){ getInfo: async function(plugin){