﻿from pathlib import Path

news_dir = Path(r"C:\Users\poc\Downloads\WebScrapBook\data\20260429163450072\news")
css = """
<style id=\"news-only-mode\">
header, .header_primary, .header_secondary, .site-header, .gh-head,
footer, .footer, .footer-sitemap,
aside, .sidebar, .post-sidebar, .searchModal,
#newsletter, #sidebar-newsletter, .newsletterRow,
.social-links, .social-mobile, .cta-social-card_social-links,
.post__share, .post-share, .related-posts, .post-footer,
form[action], .gh-subscribe, .kg-signup-card, .subscribe,
.navigation, nav:not(.post__content nav){display:none !important;}
main, .main, .post, .post__content, article{max-width:900px !important; margin:0 auto !important;}
body{background:#0c0c0f !important;}
</style>
"""

for f in news_dir.glob('news-*.html'):
    s = f.read_text(encoding='utf-8', errors='ignore')
    if 'id="news-only-mode"' not in s:
        if '</head>' in s:
            s = s.replace('</head>', css + '</head>', 1)
        else:
            s = css + s
    f.write_text(s, encoding='utf-8')
print('done')
