import json import os import sys import time from selenium import webdriver from selenium.webdriver.chrome.options import Options target = sys.argv[1] if len(sys.argv) > 1 else "110" options = Options() options.add_experimental_option("debuggerAddress", os.environ.get("WEHAGO_CHROME_DEBUGGER_ADDRESS", "127.0.0.1:9225")) driver = webdriver.Chrome(options=options) info = driver.execute_script( r""" const code = arguments[0]; const out = []; for (const cell of document.querySelectorAll('.rg-data-cell, td[class*=rg-data-cell], [class*=rg-data-cell], td')) { const r = cell.getBoundingClientRect(); const text = (cell.textContent || '').trim(); if (text === code && r.left < 220 && r.top > 145 && r.width > 0 && r.height > 0) { out.push({left:r.left, top:r.top, width:r.width, height:r.height, text}); } } return out.sort((a,b)=>a.top-b.top)[0] || null; """, target, ) print("target", target, "info", json.dumps(info, ensure_ascii=False)) if info: x = info["left"] + info["width"] / 2 y = info["top"] + info["height"] / 2 for typ in ["mouseMoved", "mousePressed", "mouseReleased"]: payload = {"type": typ, "x": x, "y": y, "button": "left", "clickCount": 1} if typ == "mouseMoved": payload["button"] = "none" driver.execute_cdp_cmd("Input.dispatchMouseEvent", payload) time.sleep(0.5) visible = driver.execute_script( r""" const rows = []; const colorScore = (color) => { const m = String(color || '').match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); if (!m) return 0; const r = Number(m[1]), g = Number(m[2]), b = Number(m[3]); return Math.max(0, b - r) + Math.max(0, g - r) + (b > 120 ? 20 : 0); }; for (const cell of document.querySelectorAll('.rg-data-cell, td[class*=rg-data-cell], [class*=rg-data-cell], td')) { const r = cell.getBoundingClientRect(); const code = (cell.textContent || '').trim(); if (!/^\d{3,6}$/.test(code) || r.left > 220 || r.top < 145 || r.width <= 0 || r.height <= 0) continue; let node = cell, score = 0, cls = ''; while (node && node !== document.body) { const style = window.getComputedStyle(node); score = Math.max(score, colorScore(style.backgroundColor)); cls += ' ' + String(node.className || ''); node = node.parentElement; } if (/selected|select|focus|current|active|checked/i.test(cls)) score += 80; rows.push({code, top:r.top, score, cls: cls.slice(0,120)}); } rows.sort((a,b)=>(b.score-a.score)||(a.top-b.top)); return rows.slice(0,8); """ ) print(json.dumps(visible, ensure_ascii=False, indent=2)) driver.quit()