From 98524a3c20884d3d9192a265ec50f44bb111eb1d Mon Sep 17 00:00:00 2001 From: Flex Date: Wed, 30 May 2018 16:33:14 -0600 Subject: [PATCH] bump repo version, update charcount and dblclickedit --- plugins/charcount.js | 107 +++++++++++++++++++++------------------- plugins/dblclickedit.js | 53 +++++++++++++------- pluginsrepo.js | 2 +- 3 files changed, 91 insertions(+), 71 deletions(-) diff --git a/plugins/charcount.js b/plugins/charcount.js index c4d9fa3..9141e6b 100644 --- a/plugins/charcount.js +++ b/plugins/charcount.js @@ -1,52 +1,57 @@ -function setupCharCount() { - if (document.getElementById("charcounter")) return; - if (!document.querySelector("textarea[class*=\"textAreaEnabled-\"]")) return; - - 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%"; - - document.querySelector("div[class*=\"channelTextAreaEnabled-\"]").appendChild(charcount); -} - -exports = { - manifest: { - author: "Cynosphere", - name: "Character Counter", - description: "Counts characters in the chatbox." - }, - start: function(){ - let charcount_mo = new MutationObserver(setupCharCount); - charcount_mo.observe(document.querySelector("div[class*=\"app-\"]"), { - childList: true, - subtree: true - }); - - document.addEventListener("keydown", ev => { - if (!document.getElementById("charcounter") || !document.querySelector("textarea[class*=\"textAreaEnabled-\"]")) return; - - setTimeout(()=>{ - let length = document.querySelector("textarea[class*=\"textAreaEnabled-\"]").value.length; - document.getElementById("charcounter").innerHTML = `${length}/2000`; - - if (length > 1999) { - document.getElementById("charcounter").style.color = "#FF0000"; - } else if (length > 1899) { - document.getElementById("charcounter").style.color = "#FF4500"; - } else if (length > 1499) { - document.getElementById("charcounter").style.color = "#FFA500"; - } else if (length > 999) { - document.getElementById("charcounter").style.color = "#F1C40F"; - } else { - document.getElementById("charcounter").style.color = "#FFFFFF"; - } - }, 50); - }); - } +function setupCharCount() { + if (document.body.contains(charcount)) return; + if (!text || !document.body.contains(text)) { + text = document.querySelector('textarea[class^="textArea-"]'); + } + if (!text) return; + + text.parentNode.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 = { + manifest: { + author: "Cynosphere", + name: "Character Counter", + description: "Counts characters in the chatbox." + }, + start: function(){ + let charcount_mo = new MutationObserver(setupCharCount); + charcount_mo.observe(document.querySelector(".app.flex-vertical"), { + childList: true, + subtree: true + }); + + document.addEventListener("keydown", ev => { + if (!text) return; + + setImmediate(()=>{ + let length = text.value.length; + charcount.innerHTML = `${length}/2000`; + + if (length > 1999) { + charcount.style.color = "#FF0000"; + } else if (length > 1899) { + charcount.style.color = "#FF4500"; + } else if (length > 1499) { + charcount.style.color = "#FFA500"; + } else if (length > 999) { + charcount.style.color = "#F1C40F"; + } else { + charcount.style.color = "#FFFFFF"; + } + }); + }); + } } \ No newline at end of file diff --git a/plugins/dblclickedit.js b/plugins/dblclickedit.js index 1f382f8..04f58a2 100644 --- a/plugins/dblclickedit.js +++ b/plugins/dblclickedit.js @@ -1,20 +1,35 @@ -exports.manifest = { - author: "Cynosphere, Jiiks", - name: "Double Click Edit", - description: "Double click messages to edit them." -} -exports.start = function(){ - document.addEventListener("dblclick", ev => { - let target = ev.target; - if(target && target.className && target.className.includes("markup")) { - let msg = target; - let opt = 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(); - } - } - }); +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; + console.log(target); + if(target && target.className && (target.className.includes("markup") || target.className.includes("hljs") || targe.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); + } + } + }); } \ No newline at end of file diff --git a/pluginsrepo.js b/pluginsrepo.js index 4469d6e..c6fedc0 100644 --- a/pluginsrepo.js +++ b/pluginsrepo.js @@ -16,7 +16,7 @@ exports = { author: "Cynosphere", name: "Plugins Repo", description: "Download plugins.", - _version: 2 + _version: 3 }, getInfo: async function(plugin){