1
0
Fork 0
Everything2Everything/src/Everything2Everything.Core/Ads/AdHtmlBuilder.cs
Yun Chan ab126a001a feat(ui): Windows 11 정통 네이티브 리디자인 + Google AdMob 광고 연동
- Mica 베이스 + 왼쪽 위 8px 라운드 콘텐츠 레이어 (탐색기·설정 앱 2계층 구조)
- 시스템 라이트/다크·강조색 자동 추종 (FsThemeService, FsPalette.Light/Dark)
- 강조색은 시스템 강조색에서 WCAG AA 대비를 보정해 파생 (FsAccentPalette)
- Segoe UI Variable 타입 램프, 최소 12px, 반경 4/8px, 카드 중첩 제거
- 네온 시안·더블 베젤·그라디언트 버튼·Inter 서체 폐기
- 전 창 적용: 메인·빠른 옵션/진행·설정·도구 설치·진단, 광고는 중립 카드로
- 결함 수정: 사이드바 체크박스 라벨 잘림, 행 체크박스 잘림, 입력란 이중 여백,
  제목 표시줄 아이콘 검게 렌더, '큐'/'대기열' 용어 혼용
- Google AdMob 광고 단위 연동 (AdHtmlBuilder, 설정 창 AdMob 카드)
- Win11NativeDesignTests 계약 테스트, VisualCaptureHarness 시각 E2E 캡처
2026-10-06 02:45:13 +09:00

180 lines
13 KiB
C#

using System;
using System.Text;
using System.Text.Encodings.Web;
namespace Everything2Everything.Core.Ads;
/// <summary>
/// Google AdMob / AdSense 실서비스 태그 및 리치 배너 HTML5 문서를 빌드하는 헬퍼
/// </summary>
public static class AdHtmlBuilder
{
public static string BuildBannerHtml(AdMobConfig config, AdItem ad)
{
var isTest = config.UseTestAds;
if (isTest)
{
var sbTest = new StringBuilder();
sbTest.AppendLine("<!DOCTYPE html>");
sbTest.AppendLine("<html lang=\"ko\">");
sbTest.AppendLine("<head>");
sbTest.AppendLine("<meta charset=\"utf-8\">");
sbTest.AppendLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
sbTest.AppendLine("<title>Google Official Test Ad</title>");
sbTest.AppendLine("<script async src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"></script>");
sbTest.AppendLine("<script>");
sbTest.AppendLine(" window.googletag = window.googletag || {cmd: []};");
sbTest.AppendLine(" googletag.cmd.push(function() {");
sbTest.AppendLine(" googletag.defineSlot('/21775744923/example/banner', [728, 90], 'google-test-ad-slot')");
sbTest.AppendLine(" .addService(googletag.pubads());");
sbTest.AppendLine(" googletag.enableServices();");
sbTest.AppendLine(" });");
sbTest.AppendLine("</script>");
sbTest.AppendLine("<style>");
sbTest.AppendLine(" * { box-sizing: border-box; margin: 0; padding: 0; }");
sbTest.AppendLine(" html, body { width: 100%; height: 100%; background: #0E1015; overflow: hidden; display: flex; justify-content: center; align-items: center; }");
sbTest.AppendLine(" .outer-wrap { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; overflow: hidden; }");
sbTest.AppendLine(" .scale-wrap { flex-shrink: 0; transform: scale(0.58); transform-origin: center center; display: flex; justify-content: center; align-items: center; }");
sbTest.AppendLine(" #google-test-ad-slot { width: 728px; height: 90px; }");
sbTest.AppendLine("</style>");
sbTest.AppendLine("</head>");
sbTest.AppendLine("<body>");
sbTest.AppendLine("<div class=\"outer-wrap\">");
sbTest.AppendLine(" <div class=\"scale-wrap\">");
sbTest.AppendLine(" <div id=\"google-test-ad-slot\">");
sbTest.AppendLine(" <script>");
sbTest.AppendLine(" googletag.cmd.push(function() { googletag.display('google-test-ad-slot'); });");
sbTest.AppendLine(" </script>");
sbTest.AppendLine(" </div>");
sbTest.AppendLine(" </div>");
sbTest.AppendLine("</div>");
sbTest.AppendLine("</body>");
sbTest.AppendLine("</html>");
return sbTest.ToString();
}
var pubId = config.PublisherId.Trim();
if (!pubId.StartsWith("pub-", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(pubId))
{
pubId = "pub-" + pubId;
}
var clientKey = string.IsNullOrEmpty(pubId) ? "ca-pub-3940256099942544" : "ca-" + pubId;
var slot = "6300978111"; // Google 공식 샘플 슬롯
if (!string.IsNullOrEmpty(config.BannerAdUnitId))
{
var slashIdx = config.BannerAdUnitId.LastIndexOf('/');
if (slashIdx >= 0 && slashIdx < config.BannerAdUnitId.Length - 1)
{
slot = config.BannerAdUnitId.Substring(slashIdx + 1);
}
else
{
slot = config.BannerAdUnitId;
}
}
var title = HtmlEncoder.Default.Encode(ad.Title ?? (isTest ? "Nice job! Google AdMob 공식 테스트 광고" : "Google AdMob 공식 배너"));
var desc = HtmlEncoder.Default.Encode(ad.Description ?? (isTest ? "[테스트 모드 활성] 단위: ca-app-pub-3940256099942544/6300978111" : "Everything2Everything 공식 후원 파트너십"));
var targetUrl = ad.TargetUrl ?? (isTest ? "https://developers.google.com/admob/android/test-ads" : "https://admob.google.com");
var ctaText = HtmlEncoder.Default.Encode(ad.CtaText ?? (isTest ? "테스트 안내" : "자세히 보기"));
var badge = HtmlEncoder.Default.Encode(ad.BadgeText ?? (isTest ? "TEST AD" : "Google AdMob"));
var testAttr = isTest ? " data-ad-test=\"on\"" : "";
var sb = new StringBuilder();
sb.AppendLine("<!DOCTYPE html>");
sb.AppendLine("<html lang=\"ko\">");
sb.AppendLine("<head>");
sb.AppendLine("<meta charset=\"utf-8\">");
sb.AppendLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
sb.AppendLine("<title>Google AdMob Live Banner</title>");
sb.AppendLine("<style>");
sb.AppendLine(" * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }");
sb.AppendLine(" html, body { width: 100%; height: 100%; background: #0E1015; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Display', 'Segoe UI', Roboto, 'Malgun Gothic', sans-serif; }");
sb.AppendLine(" .banner-wrap { width: 100%; height: 100%; position: relative; display: flex; align-items: center; justify-content: space-between; padding: 4px 10px; background: linear-gradient(90deg, #131722 0%, #1A2234 40%, #182030 100%); border: 1px solid rgba(0, 229, 255, 0.35); border-radius: 6px; cursor: pointer; transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 8px rgba(0, 0, 0, 0.4); }");
sb.AppendLine(" .banner-wrap:hover { border-color: #00E5FF; background: linear-gradient(90deg, #171E2D 0%, #202A40 40%, #1D2638 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 16px rgba(0, 229, 255, 0.2); }");
sb.AppendLine(" .banner-wrap.test-mode { border-color: rgba(255, 179, 0, 0.45); }");
sb.AppendLine(" .banner-wrap.test-mode:hover { border-color: #FFB300; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 16px rgba(255, 179, 0, 0.25); }");
sb.AppendLine(" .left-area { display: flex; align-items: center; gap: 8px; overflow: hidden; flex: 1; min-width: 0; }");
sb.AppendLine(" .brand-pill { display: flex; align-items: center; gap: 4px; background: rgba(0, 229, 255, 0.15); border: 1px solid rgba(0, 229, 255, 0.4); padding: 2px 5px; border-radius: 4px; flex-shrink: 0; }");
sb.AppendLine(" .brand-pill.test-mode { background: rgba(255, 179, 0, 0.2); border-color: #FFB300; }");
sb.AppendLine(" .brand-pill-text { color: #00E5FF; font-size: 9px; font-weight: 700; }");
sb.AppendLine(" .brand-pill.test-mode .brand-pill-text { color: #FFB300; font-weight: 800; }");
sb.AppendLine(" .google-logo { width: 18px; height: 18px; flex-shrink: 0; }");
sb.AppendLine(" .copy-wrap { display: flex; flex-direction: column; overflow: hidden; min-width: 0; flex: 1; justify-content: center; }");
sb.AppendLine(" .ad-headline { color: #FFFFFF; font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }");
sb.AppendLine(" .ad-subline { color: #94A3B8; font-size: 10px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; }");
sb.AppendLine(" .cta-btn.test-mode { background: #FFB300; color: #07090E; box-shadow: 0 2px 6px rgba(255, 179, 0, 0.35); }");
sb.AppendLine(" .banner-wrap.test-mode:hover .cta-btn.test-mode { background: #FFCA28; }");
sb.AppendLine(" .action-area { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: 8px; }");
sb.AppendLine(" .cta-btn { background: #00E5FF; color: #07090E; font-size: 10px; font-weight: 700; padding: 4px 9px; border-radius: 4px; display: flex; align-items: center; gap: 3px; border: none; box-shadow: 0 2px 6px rgba(0, 229, 255, 0.35); }");
sb.AppendLine(" .banner-wrap:hover .cta-btn { background: #33EBFF; transform: translateX(2px); }");
sb.AppendLine(" .adchoices-tag { display: flex; align-items: center; gap: 2px; color: #64748B; font-size: 8px; padding: 2px 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.04); flex-shrink: 0; }");
sb.AppendLine(" .adchoices-tag:hover { color: #94A3B8; }");
sb.AppendLine(" .live-ad-slot { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: auto; }");
sb.AppendLine(" @media (max-width: 480px) {");
sb.AppendLine(" .adchoices-tag span { display: none; }");
sb.AppendLine(" .brand-pill { display: none; }");
sb.AppendLine(" .ad-headline { font-size: 11px; }");
sb.AppendLine(" .ad-subline { font-size: 9.5px; }");
sb.AppendLine(" }");
sb.AppendLine("</style>");
sb.Append("<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=").Append(clientKey).AppendLine("\" crossorigin=\"anonymous\"></script>");
sb.AppendLine("</head>");
sb.AppendLine("<body onclick=\"handleAdClick()\">");
sb.Append("<div class=\"banner-wrap").Append(isTest ? " test-mode" : "").AppendLine("\" id=\"adContainer\">");
sb.AppendLine(" <div class=\"left-area\">");
sb.AppendLine(" <!-- Google 4-Color Logo SVG -->");
sb.AppendLine(" <svg class=\"google-logo\" viewBox=\"0 0 24 24\">");
sb.AppendLine(" <path fill=\"#4285F4\" d=\"M23.745 12.27c0-.7-.06-1.4-.19-2.07H12v4.51h6.6c-.29 1.52-1.14 2.82-2.4 3.68v3.05h3.88c2.27-2.09 3.66-5.17 3.66-9.17z\"/>");
sb.AppendLine(" <path fill=\"#34A853\" d=\"M12 24c3.24 0 5.95-1.08 7.93-2.91l-3.88-3.05c-1.08.72-2.45 1.16-4.05 1.16-3.12 0-5.77-2.1-6.72-4.93H1.24v3.15C3.26 21.36 7.33 24 12 24z\"/>");
sb.AppendLine(" <path fill=\"#FBBC05\" d=\"M5.28 14.27c-.25-.72-.38-1.49-.38-2.27s.13-1.55.38-2.27V6.58H1.24C.45 8.15 0 9.91 0 12s.45 3.85 1.24 5.42l4.04-3.15z\"/>");
sb.AppendLine(" <path fill=\"#EA4335\" d=\"M12 4.75c1.77 0 3.35.61 4.6 1.8l3.42-3.42C17.95 1.19 15.24 0 12 0 7.33 0 3.26 2.64 1.24 6.58l4.04 3.15c.95-2.83 3.6-4.98 6.72-4.98z\"/>");
sb.AppendLine(" </svg>");
sb.Append(" <div class=\"brand-pill").Append(isTest ? " test-mode" : "").AppendLine("\">");
sb.Append(" <span class=\"brand-pill-text\">").Append(badge).AppendLine("</span>");
sb.AppendLine(" </div>");
sb.AppendLine(" <div class=\"copy-wrap\">");
sb.Append(" <div class=\"ad-headline\">").Append(title).AppendLine("</div>");
sb.Append(" <div class=\"ad-subline\">").Append(desc).AppendLine("</div>");
sb.AppendLine(" </div>");
sb.AppendLine(" </div>");
sb.AppendLine(" <div class=\"action-area\">");
sb.Append(" <div class=\"cta-btn").Append(isTest ? " test-mode" : "").AppendLine("\">");
sb.Append(" <span>").Append(ctaText).AppendLine("</span>");
sb.AppendLine(" <svg width=\"11\" height=\"11\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\">");
sb.AppendLine(" <path d=\"M5 12h14M12 5l7 7-7 7\"/>");
sb.AppendLine(" </svg>");
sb.AppendLine(" </div>");
sb.AppendLine(" <div class=\"adchoices-tag\" title=\"Google AdChoices\">");
sb.AppendLine(" <span>AdChoices</span>");
sb.AppendLine(" <svg width=\"8\" height=\"8\" viewBox=\"0 0 24 24\" fill=\"currentColor\">");
sb.AppendLine(" <path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/>");
sb.AppendLine(" </svg>");
sb.AppendLine(" </div>");
sb.AppendLine(" </div>");
sb.AppendLine(" <!-- Google Live Ads Slot -->");
sb.AppendLine(" <div class=\"live-ad-slot\" id=\"googleAdSlot\">");
sb.Append(" <ins class=\"adsbygoogle\" style=\"display:block;width:100%;height:100%\" data-ad-client=\"").Append(clientKey).Append("\" data-ad-slot=\"").Append(slot).Append("\" data-ad-format=\"horizontal\"").Append(testAttr).AppendLine("></ins>");
sb.AppendLine(" </div>");
sb.AppendLine("</div>");
sb.AppendLine("<script>");
sb.AppendLine(" function handleAdClick(e) {");
sb.Append(" var url = \"").Append(targetUrl).AppendLine("\";");
sb.AppendLine(" if (window.chrome && window.chrome.webview) {");
sb.AppendLine(" window.chrome.webview.postMessage(JSON.stringify({ action: 'open_url', url: url }));");
sb.AppendLine(" } else {");
sb.AppendLine(" window.open(url, '_blank');");
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine(" try {");
sb.AppendLine(" (adsbygoogle = window.adsbygoogle || []).push({});");
sb.AppendLine(" var slot = document.getElementById('googleAdSlot');");
sb.AppendLine(" if (slot && slot.querySelector('iframe')) { slot.style.display = 'block'; }");
sb.AppendLine(" } catch (e) { }");
sb.AppendLine("</script>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
return sb.ToString();
}
}