Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Keep a space between a page's badge and the next word in a pointed chip

AdityaUmale04be26940b2d
diff --git a/shared/app-frame/point.test.ts b/shared/app-frame/point.test.ts
index 9cc93ed242..23460c1927 100644
--- a/shared/app-frame/point.test.ts
+++ b/shared/app-frame/point.test.ts
@@ -85,6 +85,15 @@ describe("the page's point script", () => {
expect(posted).toHaveLength(1);
});
+ it("keeps a space between a badge and the words after it, so the chip label reads as the page does", () => {
+ const { say } = boot();
+ document.body.innerHTML = `<div class="card"><span style="display:inline-block">Cloud</span>Restore <b>fin</b>ishes<script>ignored()</script>
+ <i style="visibility:hidden">tooltip</i><details><summary>More</summary>folded</details></div>`;
+ say(pointMessage(true));
+ click(document.querySelector(".card")!);
+ expect(posted.at(-1)).toMatchObject({ params: { tag: "div", text: "Cloud Restore finishes More" } });
+ });
+
it("names a keyed part by its key, and Escape ends point mode with word to the parent", () => {
const { say } = boot();
say(pointMessage(true));
diff --git a/shared/app-frame/point.ts b/shared/app-frame/point.ts
index df94850519..ed79faedfd 100644
--- a/shared/app-frame/point.ts
+++ b/shared/app-frame/point.ts
@@ -121,9 +121,22 @@ export const APP_POINT_SOURCE = `(function () {
}
return parts.join(" > ");
};
+ // innerText runs a badge (an inline-block span) into the next word ("CloudRestore"): any box that is not plain inline
+ // is a word break on screen, so it is one here too.
+ var wordsOf = function (node) {
+ if (node.nodeType === 3) return node.data;
+ if (node.nodeType !== 1 || /^(script|style|noscript|template)$/i.test(node.tagName)) return "";
+ var style = window.getComputedStyle(node);
+ var display = style.display;
+ if (display === "none" || style.visibility === "hidden" || style.visibility === "collapse") return "";
+ var shown = node.tagName === "DETAILS" && !node.open
+ ? Array.prototype.filter.call(node.children, function (child) { return child.tagName === "SUMMARY"; }) : node.childNodes;
+ var words = Array.prototype.map.call(shown, wordsOf).join("");
+ return /^(inline|contents)?$/.test(display) && node.tagName !== "BR" ? words : " " + words + " ";
+ };
var describe = function (element) {
var tag = element.tagName.toLowerCase();
- var text = element.innerText || element.textContent || element.getAttribute("aria-label") || element.getAttribute("alt") ||
+ var text = wordsOf(element).trim() || element.getAttribute("aria-label") || element.getAttribute("alt") ||
element.getAttribute("placeholder") || element.getAttribute("title") || "";
return { tag: tag, role: element.getAttribute("role") || ROLES[tag] || "", text: clip(text, 200), selector: clip(selectorOf(element), 300),
html: clip(element.outerHTML, 600) };