03-02-2024, 09:43 AM
// script ""
print.clear();
var w = wnd.find(1, "ChatGPT - Google Chrome", "Chrome_WidgetWin_1");
var e = w.Elm["web:GROUPING", prop: "@data-message-author-role=assistant", flags: EFFlags.Reverse].Find(1);
var s = e.GetInnerText();
print.it("---");
print.it(s);
static class Ext {
/// <summary>
/// Not perfect!
/// </summary>
public static string GetInnerText(this elm t) {
var ae = t.Elm[null].FindAll();
if (ae.Length == 0) return "";
//print.it(ae);
List<(string s, RECT r)> a = new();
foreach (var e in ae) {
if (e.GetProperties("nvr", out var p)) {
var s = p.Name; if (s.NE()) s = p.Value;
if (s.NE() || p.Rect.NoArea) continue;
//print.it(e);
if (a.Count > 0 && s == a[^1].s && a[^1].r.Contains(p.Rect)) a.RemoveAt(a.Count - 1);
//if (p.Role == "GROUPING") continue;
a.Add((s, p.Rect));
}
}
var b = new StringBuilder();
int i = -1, y = 0;
foreach (var (s, r) in a) {
i++;
//print.it(s, r);
if (b.Length > 0) if (r.top > y) b.AppendLine(); else b.Append(" ");
y = r.bottom;
b.Append(s);
}
return b.ToString();
}
}