Improve ad loading and video title formatting for better user experience
Add a delay and width check for AdSense ad initialization in `adsense-ad.tsx` and clean video titles by removing `.mp4` extensions in `bunny.ts`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c5d5630c-85af-4c2b-bf4e-7e8006d34256 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/60d372ff-2c10-46c7-b01b-10c3435136b0/c5d5630c-85af-4c2b-bf4e-7e8006d34256/HcYyIPk
This commit is contained in:
parent
2a67922121
commit
04999a38cd
@ -18,15 +18,25 @@ export default function AdSenseAd({
|
|||||||
const adRef = useRef<HTMLDivElement>(null);
|
const adRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
const timer = setTimeout(() => {
|
||||||
// Ensure adsbygoogle is loaded
|
try {
|
||||||
if (typeof window !== 'undefined') {
|
// Ensure adsbygoogle is loaded
|
||||||
// @ts-ignore
|
if (typeof window !== 'undefined' && adRef.current) {
|
||||||
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
// Check if element has width before initializing ad
|
||||||
|
const elementWidth = adRef.current.offsetWidth;
|
||||||
|
if (elementWidth > 0) {
|
||||||
|
// @ts-ignore
|
||||||
|
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||||
|
} else {
|
||||||
|
console.warn('AdSense element has no width, skipping initialization');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('AdSense initialization error:', error);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}, 100); // Small delay to ensure DOM is rendered
|
||||||
console.error('AdSense initialization error:', error);
|
|
||||||
}
|
return () => clearTimeout(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const adStyle: React.CSSProperties = {
|
const adStyle: React.CSSProperties = {
|
||||||
@ -42,7 +52,7 @@ export default function AdSenseAd({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`adsense-wrapper ${className}`} ref={adRef}>
|
<div className={`adsense-wrapper ${className}`} ref={adRef} style={{ minWidth: '300px', minHeight: '250px' }}>
|
||||||
<ins
|
<ins
|
||||||
className="adsbygoogle"
|
className="adsbygoogle"
|
||||||
style={adStyle}
|
style={adStyle}
|
||||||
|
|||||||
@ -100,9 +100,15 @@ export class BunnyService {
|
|||||||
// No tags from Bunny.net - keeping tags empty
|
// No tags from Bunny.net - keeping tags empty
|
||||||
const tags: string[] = [];
|
const tags: string[] = [];
|
||||||
|
|
||||||
|
// Clean up title by removing .mp4 extension if present
|
||||||
|
let cleanTitle = bunnyVideo.title || 'Untitled Video';
|
||||||
|
if (cleanTitle.toLowerCase().endsWith('.mp4')) {
|
||||||
|
cleanTitle = cleanTitle.slice(0, -4);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: bunnyVideo.guid,
|
id: bunnyVideo.guid,
|
||||||
title: bunnyVideo.title || 'Untitled Video',
|
title: cleanTitle,
|
||||||
artist: null, // No artist data from Bunny.net
|
artist: null, // No artist data from Bunny.net
|
||||||
description: description,
|
description: description,
|
||||||
filename: null, // No filename data from Bunny.net
|
filename: null, // No filename data from Bunny.net
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user