# -*- coding: utf-8 -*-
import json, time, urllib.request, sys
sys.path.insert(0, r"C:\Users\Administrator\AppData\Local\Temp\jojo108")
from flow_batch_characters import call, ev, click_text, leaf_count

r1 = call("evaluate", {"code": "(() => { const old = document.getElementById('flowprobe'); if (old) old.removeAttribute('id'); const leaves = [...document.querySelectorAll('*')].filter(e => e.children.length === 0 && (e.textContent||'').trim() === '\u89d2\u8272'); if (!leaves.length) return JSON.stringify({ok:false,where:'nf'}); const el = leaves[leaves.length-1].closest('button,[role=\"button\"],a,[role=\"link\"],div,span') || leaves[leaves.length-1]; const r = el.getBoundingClientRect(); el.id='flowprobe'; return JSON.stringify({ok:true, tag: el.tagName, rect:[Math.round(r.x),Math.round(r.y),Math.round(r.width),Math.round(r.height)]}); })()"})
print("TAG:", json.dumps(r1, ensure_ascii=False)[:300])
time.sleep(0.3)
r2 = call("mouse_click", {"selector": "#flowprobe"})
print("CLICK:", json.dumps(r2, ensure_ascii=False)[:300])
time.sleep(3)
print("COUNT:", leaf_count("新角色"))
