diff --git a/bin/triage.php b/bin/triage.php index 56f8175..df78e3a 100644 --- a/bin/triage.php +++ b/bin/triage.php @@ -449,12 +449,42 @@ function movePosition(){ } } + function getSelectedText() { + var text = ""; + if (window.getSelection) { + text = window.getSelection().toString(); + } else if (document.selection && document.selection.type !== "Control") { + text = document.selection.createRange().text; + } + return text; + } + + function countBytes(text) { + // Count the number of bytes using the TextEncoder API + var encoder = new TextEncoder(); + var bytes = encoder.encode(text); + return bytes.length; + } + + function updateTooltip() { + var selectedText = getSelectedText(); + var byteCount = countBytes(selectedText); + var tooltip = document.getElementById("tooltip"); + + if (byteCount > 0) { + tooltip.parentElement.style.visibility = "visible"; + tooltip.innerHTML = "=§('triage-counter')?>: " + byteCount; + } else { + tooltip.parentElement.style.visibility = "hidden"; + } + } var domReady = function(callback) { document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback); }; domReady(function() { - movePosition() + movePosition(); + document.getElementById("text-container").addEventListener("mouseup", updateTooltip); }); window.onresize = function(event) { @@ -712,7 +742,10 @@ class="w3-button w3-red w3-leftbar w3-rightbar w3-border-light-grey w3-block" =htmlspecialchars($output['compare']['tocomment']??'')?> -