IDK what i was going here

This commit is contained in:
Finn
2026-01-04 17:27:37 +01:00
parent d69677559e
commit 9e475ba4f1
3 changed files with 69 additions and 3 deletions

View File

@@ -88,7 +88,6 @@ public class HtmlApp {
</script>
</body>
</html>
""";
// Erstelle das GUI und lade das Beispiel

View File

@@ -0,0 +1,38 @@
package org.openautonomousconnection.htmlparser.script;
import org.openautonomousconnection.htmlparser.dom.*;
import org.openautonomousconnection.htmlparser.events.Event;
public final class DomAdapter {
private final Document document;
public DomAdapter(Document document) {
this.document = document;
}
public Document document() { return document; }
// expose: document.querySelector(...)
public Element querySelector(String sel) { return document.querySelector(sel); }
public Element getElementById(String id) { return document.getElementById(id); }
public Element createElement(String tag) { return document.createElement(tag); }
public TextNode createTextNode(String text) { return document.createTextNode(text); }
public void appendChild(Element parent, Object child) {
if (parent == null || child == null) return;
if (child instanceof Element e) parent.appendChild(e);
else if (child instanceof TextNode t) parent.appendChild(t);
}
public void setText(Element el, String text) { if (el != null) el.setText(text); }
public void setAttr(Element el, String k, String v) { if (el != null) el.setAttribute(k, v); }
public String getAttr(Element el, String k) { return el == null ? null : el.getAttribute(k); }
public void styleSet(Element el, String k, String v) { if (el != null) el.style().set(k, v); }
public void click(Element el) {
if (el == null) return;
el.dispatchEvent(new Event("click", true));
}
}

View File

@@ -0,0 +1,29 @@
package org.openautonomousconnection.htmlparser.script;
import org.openautonomousconnection.htmlparser.dom.*;
import java.util.Objects;
public final class ScriptEngine implements AutoCloseable {
private final PythonInterpreter py;
private final PyDomAdapter dom;
public ScriptEngine(Document document) {
this.py = new PythonInterpreter();
this.dom = new PyDomAdapter(Objects.requireNonNull(document));
// expose "document" + "dom"
py.set("dom", dom);
py.set("document", document);
}
public void exec(String code) {
if (code == null) return;
py.exec(code);
}
@Override
public void close() {
try { py.close(); } catch (Exception ignored) {}
}
}