$files = Get-ChildItem -Path "site\*.html", "site\tools\*.html", "site\blog\articles\*.html"

$adCode = @"
<div class="ad-container" data-noprint>
  <!-- Google AdSense -->
  <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXX" crossorigin="anonymous"></script>
  <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXX" data-ad-slot="1234567890" data-ad-format="auto" data-full-width-responsive="true"></ins>
  <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
"@

$mobileStickyAd = @"
<!-- Mobile Sticky Ad -->
<div class="ad-container-mobile-sticky" data-noprint>
  <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXX" crossorigin="anonymous"></script>
  <ins class="adsbygoogle" style="display:inline-block;width:320px;height:50px" data-ad-client="ca-pub-XXXXX" data-ad-slot="0987654321"></ins>
  <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
</body>
"@

foreach ($file in $files) {
    $content = Get-Content $file.FullName -Raw
    
    # Replace existing ad slots
    $content = $content -replace '(?s)<div class="ad-slot"[^>]*>.*?</div>', $adCode
    
    # Add mobile sticky ad if not already present
    if ($content -notmatch "ad-container-mobile-sticky") {
        $content = $content -replace '(?i)</body>', $mobileStickyAd
    }
    
    Set-Content -Path $file.FullName -Value $content -Encoding UTF8
}
Write-Host "Google Ads implemented across all HTML files."
