From 444e1dfbb5234f4b95ef947114a2ebb4b47da444 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 7 Mar 2025 21:27:19 -0800 Subject: [PATCH] add google ads to homepage --- src/client/GoogleAdElement.ts | 72 ++++++++++++++++++++++++++++------- src/client/Main.ts | 8 ++++ src/client/index.html | 72 ++++++++++++++++++++++++++++++++++- 3 files changed, 138 insertions(+), 14 deletions(-) diff --git a/src/client/GoogleAdElement.ts b/src/client/GoogleAdElement.ts index 08db8bfac..4ddc32b51 100644 --- a/src/client/GoogleAdElement.ts +++ b/src/client/GoogleAdElement.ts @@ -1,8 +1,30 @@ import { LitElement, html, css } from "lit"; -import { customElement } from "lit/decorators.js"; +declare global { + interface Window { + adsbygoogle: any[]; + } +} +import { customElement, property } from "lit/decorators.js"; + +/** + * Google AdSense integration component + * + * This component creates a configurable container for Google AdSense ads + * and properly initializes them after the component is rendered. + */ @customElement("google-ad") export class GoogleAdElement extends LitElement { + // Configurable properties + @property({ type: String }) adClient = "ca-pub-7035513310742290"; + @property({ type: String }) adSlot = "5220834834"; + @property({ type: String }) adFormat = "auto"; + @property({ type: Boolean }) fullWidthResponsive = true; + @property({ type: String }) adTest = "off"; // "on" for testing, remove or set to "off" for production + @property({ type: String }) backgroundColor = "rgba(255, 255, 255, 0.1)"; + @property({ type: String }) darkBackgroundColor = "rgba(0, 0, 0, 0.2)"; + + // Disable shadow DOM so AdSense can access the elements createRenderRoot() { return this; } @@ -10,33 +32,57 @@ export class GoogleAdElement extends LitElement { static styles = css` .google-ad-container { margin-top: 1rem; - background-color: rgba(255, 255, 255, 0.1); border-radius: 0.5rem; padding: 0.5rem; width: 100%; overflow: hidden; + transition: + opacity 0.3s ease, + height 0.3s ease; } - - .dark .google-ad-container { - background-color: rgba(0, 0, 0, 0.2); + .google-ad-container.hidden { + opacity: 0; + height: 0; + padding: 0; + margin: 0; + overflow: hidden; } `; render() { + // Apply background color dynamically + const containerStyle = ` + background-color: ${this.backgroundColor}; + `; + return html` -