#!/usr/bin/env python3
"""DMark: ukur ulang judul kutipan yang sudah diubah jadi h2 — apakah ukuran 17px terjaga?"""
import asyncio


async def main():
    from playwright.async_api import async_playwright
    async with async_playwright() as pw:
        br = await pw.chromium.launch()
        hal = await br.new_page(viewport={"width": 1440, "height": 1000})
        await hal.goto("https://www.dmark.id/", wait_until="domcontentloaded", timeout=120000)
        await hal.wait_for_timeout(6000)
        hasil = await hal.evaluate("""
        () => Array.from(document.querySelectorAll('h1,h2,h3,h4,h5,h6')).map(el => {
            const cs = getComputedStyle(el);
            return {tag: el.tagName.toLowerCase(), text: (el.innerText||'').replace(/\\s+/g,' ').trim().slice(0,44),
                    size: cs.fontSize, weight: cs.fontWeight};
        })""")
        print(f"total judul: {len(hasil)}")
        for h in hasil[:8]:
            print(f"   <{h['tag']}> {h['text'][:44]:<46} {h['size']:>7} / {h['weight']}")
        kutipan = [h for h in hasil if "Creativity" in h["text"]]
        print(f"\njudul kutipan: {kutipan}")
        angka = [int(h["tag"][1]) for h in hasil]
        lompat = [(hasil[i-1]['tag'], hasil[i]['tag']) for i in range(1, len(angka)) if angka[i] - angka[i-1] > 1]
        print(f"lompatan level tersisa: {len(lompat)} → {lompat[:8]}")
        await br.close()


asyncio.run(main())
