o
    ߖi"                     @   sH   d dl Z e jjdd d dlmZ d dlZdd Zedkr"e  dS dS )    Nzutf-8)encoding)sync_playwrightc                  C   s  t  _} | jjdd}|jdddddd}| }td	 |jd
dd |d td |d |d td |j	ddddddd d}t| td t| |d}t| t| td t| |d}tt
j|ddd t| td t| |d }tt
j|ddd t| td! t| |d"}tt
j|ddd t| td# t| |d$}	tt
j|	ddd t| td% t| |d&}
t|
D ]\}}td'|| qt| td( t| |d)}tt
j|ddd t| td* t| |d+}|rO|  |d, |d-}tt
j|ddd |j	d.dddddd td/ |  |d, ntd0 |  td1 W d    d S 1 sgw   Y  d S )2NT)Zheadlessi  iL  )widthheight   zKMozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15)ZviewportZdevice_scale_factorZ
user_agentz!=== Navigating to kevinliu.tw ===zhttps://kevinliu.twZnetworkidle)Z
wait_untili  zSetting dark modez;document.documentElement.setAttribute('data-theme', 'dark')i  zTaking screenshotzCC:/Users/User/Documents/GitHub/Research_zoo/projects/mobile_nav.pngr      )xyr   r   )pathZclipzP================================================================================z=== .gh-head FULL HTML ===z_document.querySelector('.gh-head') ? document.querySelector('.gh-head').outerHTML : 'NOT FOUND'z === SEARCH BUTTON INSPECTION ===a1  () => {
            const sels = ['a[data-ghost-search]', '[data-ghost-search]', '.gh-search',
                'button[aria-label="search"]', '.gh-head-actions a', '.gh-head-actions button'];
            let r = {};
            for (const sel of sels) {
                const els = document.querySelectorAll(sel);
                if (els.length > 0) { r[sel] = [];
                    els.forEach((el) => {
                        const rect = el.getBoundingClientRect();
                        const cs = window.getComputedStyle(el);
                        r[sel].push({ tag: el.tagName, cls: el.className, id: el.id,
                            html: el.outerHTML.substring(0, 500),
                            parentCls: el.parentElement ? el.parentElement.className : null,
                            gpCls: el.parentElement && el.parentElement.parentElement ? el.parentElement.parentElement.className : null,
                            rect: {t: rect.top, l: rect.left, w: rect.width, h: rect.height},
                            vis: rect.width > 0 && rect.height > 0,
                            disp: cs.display, bg: cs.backgroundColor, color: cs.color,
                            border: cs.border, br: cs.borderRadius, pad: cs.padding, mar: cs.margin });
                    }); } }
            return r;
        }   F)indentZensure_asciiz=== .gh-head-actions ===a  () => {
            const el = document.querySelector('.gh-head-actions');
            if (!el) return 'NOT FOUND';
            const r = el.getBoundingClientRect(); const cs = window.getComputedStyle(el);
            return { html: el.outerHTML, cc: el.children.length,
                kids: Array.from(el.children).map(c => ({ tag: c.tagName, cls: c.className,
                    txt: c.textContent.trim().substring(0,50), h: c.outerHTML.substring(0,300) })),
                rect: {t:r.top,l:r.left,w:r.width,h:r.height}, vis: r.width>0 && r.height>0,
                disp: cs.display, pos: cs.position,
                pCls: el.parentElement ? el.parentElement.className : null,
                pDisp: el.parentElement ? window.getComputedStyle(el.parentElement).display : null };
        }z"=== HAMBURGER / MENU STRUCTURE ===ar  () => {
            const sels = ['.gh-burger','.gh-head-menu','.gh-head-brand','.gh-head-inner'];
            let r = {};
            for (const s of sels) { const el = document.querySelector(s);
                if (el) { const rect = el.getBoundingClientRect(); const cs = window.getComputedStyle(el);
                    r[s] = { html: el.outerHTML.substring(0,1500), cc: el.children.length,
                        rect: {t:rect.top,l:rect.left,w:rect.width,h:rect.height},
                        vis: rect.width>0&&rect.height>0, disp: cs.display, pos: cs.position, ov: cs.overflow }; } }
            return r;
        }z=== VISIBILITY MAP ===a  () => {
            const head = document.querySelector('.gh-head'); if (\!head) return [];
            let r = []; head.querySelectorAll('*').forEach(el => {
                const rect = el.getBoundingClientRect(); const cs = window.getComputedStyle(el);
                if (rect.width>0 && rect.height>0 && cs.display\!=='none' && cs.visibility\!=='hidden' && rect.top<200) {
                    r.push({ tag: el.tagName, cls: el.className.toString().substring(0,80),
                        txt: el.textContent.trim().substring(0,30),
                        rect: rect.left.toFixed(0)+','+rect.top.toFixed(0)+' '+rect.width.toFixed(0)+'x'+rect.height.toFixed(0),
                        bg: cs.backgroundColor }); } });
            return r;
        }z=== RELEVANT CSS RULES ===am  () => {
            const kw = ['gh-head-actions','gh-search','gh-head-btn','gh-burger'];
            let r = []; for (const s of document.styleSheets) {
                try { for (const rule of s.cssRules) {
                    if (kw.some(k => rule.cssText.includes(k))) r.push(rule.cssText.substring(0,500));
                } } catch(e) {} } return r;
        }z[{}] {}z%=== SEARCH BUTTON DEEP INSPECTION ===aa  () => {
            const se = document.querySelector('[data-ghost-search]') || document.querySelector('.gh-search');
            if (\!se) return 'NOT FOUND';
            const cs = window.getComputedStyle(se); let anc = []; let cur = se;
            while (cur && cur \!== document.body) {
                const acs = window.getComputedStyle(cur);
                anc.push({tag:cur.tagName, cls:cur.className.toString().substring(0,100), bg:acs.backgroundColor, color:acs.color, disp:acs.display, pad:acs.padding});
                cur = cur.parentElement; }
            const svg = se.querySelector('svg'); let svgS = null;
            if (svg) { const sc = window.getComputedStyle(svg); svgS = {fill:sc.fill,stroke:sc.stroke,color:sc.color,w:sc.width,h:sc.height}; }
            return { el: {tag:se.tagName, cls:se.className, inner:se.innerHTML, outer:se.outerHTML},
                st: {bg:cs.backgroundColor, background:cs.background, color:cs.color, fill:cs.fill, border:cs.border, br:cs.borderRadius, pad:cs.padding, w:cs.width, h:cs.height, shadow:cs.boxShadow},
                svg: svgS, anc: anc };
        }z=== HAMBURGER MENU OPEN ===z
.gh-burgeri  a  () => {
                const h = document.querySelector('.gh-head');
                const a = document.querySelector('.gh-head-actions');
                const m = document.querySelector('.gh-head-menu');
                return { hCls: h?h.className:null, open: h?h.classList.contains('is-open'):false,
                    aRect: a?(()=>{const r=a.getBoundingClientRect();return{t:r.top,l:r.left,w:r.width,h:r.height}})():null,
                    aVis: a?(()=>{const r=a.getBoundingClientRect();return r.width>0&&r.height>0})():false,
                    mRect: m?(()=>{const r=m.getBoundingClientRect();return{t:r.top,l:r.left,w:r.width,h:r.height}})():null };
            }zMC:/Users/User/Documents/GitHub/Research_zoo/projects/mobile_nav_menu_open.pngzMenu open screenshot savedzNo .gh-burger found!z=== DONE ===)r   ZchromiumZlaunchZnew_contextZnew_pageprintZgotoZwait_for_timeoutZevaluateZ
screenshotjsondumps	enumerateformatZquery_selectorZclickclose)pZbrowsercontextZpageZSEPZhtmlZsearch_infoZactZhinfoZvmapZrulesiZruleZdsZburgerZms r   JC:\Users\User\Documents\GitHub\Research_zoo\projects\inspect_mobile_nav.pymain   s   














	
 $r   __main__)sysstdoutreconfigureZplaywright.sync_apir   r   r   __name__r   r   r   r   <module>   s     (
