From cbb67f49de54f1317aa4c7c4fe11cde415c2056f Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 14 Oct 2022 13:02:20 -0500 Subject: [PATCH 1/3] Recolor tokens on theme switch --- static/koboldai.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 0c99e4a6..59a59ac1 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2664,6 +2664,7 @@ function Change_Theme(theme) { element.selected = false; } } + recolorTokens(); } function palette_color(item) { @@ -2898,6 +2899,24 @@ function distortColor(rgb) { return rgb; } +function dec2Hex2(number) { + // Two padded hex number hack + let x = number.toString(16); + if (x.length === 1) return `0${x}`; + return x; +} + +function recolorTokens() { + for (const contextContainer of document.querySelectorAll(".context-block")) { + let rgb = window.getComputedStyle(contextContainer)["background-color"].match(/(\d+), (\d+), (\d+)/).slice(1, 4).map(Number); + for (const tokenEl of contextContainer.querySelectorAll(".context-token")) { + let tokenColor = distortColor(rgb); + tokenColor = "#" + (tokenColor.map(dec2Hex2).join("")); + tokenEl.style.backgroundColor = tokenColor; + } + } +} + function update_context(data) { $(".context-block").remove(); @@ -2935,7 +2954,7 @@ function update_context(data) { for (const [tokenId, token] of entry.tokens) { let tokenColor = distortColor(rgb); - tokenColor = "#" + (tokenColor.map((x) => x.toString(16)).join("")); + tokenColor = "#" + (tokenColor.map(dec2Hex2).join("")); let tokenEl = $e("span", el, { classes: ["context-token"], From 6ff16ac808d9990a68eff5ce229fab17904402dd Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 14 Oct 2022 13:16:58 -0500 Subject: [PATCH 2/3] Fix tooltips in some places --- static/koboldai.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 59a59ac1..586411ab 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -260,7 +260,7 @@ function create_options(action) { icon.setAttribute('data-glyph', "loop-circular"); iconcell.append(icon); delete_icon = $e("span", iconcell, {"classes": ["material-icons-outlined", "cursor", 'delete_option_icon'], - "title": "delete option", 'option_id': i, + "tooltip": "Delete Option", 'option_id': i, 'option_chunk': action.id, 'textContent': 'delete'}); delete_icon.onclick = function () { socket.emit("delete_option", {"chunk": this.getAttribute("option_chunk"), "option": this.getAttribute("option_id")}); @@ -1658,9 +1658,9 @@ function world_info_entry(data) { delete_icon = world_info_card.querySelector('#world_info_delete_'); delete_icon.id = "world_info_delete_"+data.uid; delete_icon.setAttribute("uid", data.uid); - delete_icon.setAttribute("title", data.title); + delete_icon.setAttribute("wi-title", data.title); delete_icon.onclick = function () { - if (confirm("This will delete world info "+this.getAttribute("title"))) { + if (confirm("This will delete world info "+this.getAttribute("wi-title"))) { if (parseInt(this.getAttribute("uid")) < 0) { this.parentElement.parentElement.remove(); } else { From e28c862007f2c4fcc49804baccfbcd89d4d78ae2 Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 14 Oct 2022 13:29:48 -0500 Subject: [PATCH 3/3] Remove debug text --- static/koboldai.js | 1 - 1 file changed, 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 586411ab..057b2ef8 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -5103,7 +5103,6 @@ function initalizeTooltips() { function registerElement(el) { // el should have attribute "tooltip" let text = el.getAttribute("tooltip"); - el.setAttribute("wawawa", "yeah") el.addEventListener("mouseenter", function(event) { tooltip.innerText = text;