Skip to content

Commit 8468ec9

Browse files
authored
Merge pull request #922 from rahuldkjain/rahuldkjain/full-revamp
chore: fix BMC widget
2 parents d3d2227 + f42abc5 commit 8468ec9

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import localFont from 'next/font/local';
44
import './globals.css';
55
import { ThemeProvider } from '@/components/layout/theme-provider';
66
import { ToastProvider } from '@/components/ui/toast';
7-
import { BuyMeCoffeeWidget } from '@/components/ui/buy-me-coffee';
7+
import { BuyMeACoffeeWidget } from '@/components/ui/buy-me-coffee';
88
import { ConditionalAnalytics } from '@/components/analytics/conditional-analytics';
99
import { CookieConsent } from '@/components/ui/cookie-consent';
1010

@@ -147,7 +147,7 @@ export default function RootLayout({
147147
<ThemeProvider>
148148
<ToastProvider>{children}</ToastProvider>
149149
</ThemeProvider>
150-
<BuyMeCoffeeWidget />
150+
<BuyMeACoffeeWidget />
151151
<ConditionalAnalytics />
152152
<CookieConsent />
153153
</body>

src/components/ui/buy-me-coffee.tsx

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,38 @@
22

33
import { useEffect } from 'react';
44

5-
export function BuyMeCoffeeWidget() {
5+
export function BuyMeACoffeeWidget() {
66
useEffect(() => {
7-
// Remove any existing BMC scripts first
8-
const existingScripts = document.querySelectorAll('script[data-name="BMC-Widget"]');
9-
existingScripts.forEach((script) => script.remove());
10-
11-
// Create and append the script element
127
const script = document.createElement('script');
138
script.setAttribute('data-name', 'BMC-Widget');
14-
script.setAttribute('data-cfasync', 'false');
15-
script.setAttribute('src', 'https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js');
9+
script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js';
1610
script.setAttribute('data-id', 'rahuldkjain');
17-
script.setAttribute('data-description', 'Support me on Buy me a coffee!');
18-
script.setAttribute('data-message', 'Loved the tool🚀. Buy me a coffee to support the work!');
19-
script.setAttribute('data-color', '#FF813F');
11+
script.setAttribute('data-description', 'Support rahuldkjain on Buy me a coffee!');
12+
script.setAttribute('data-message', '');
13+
script.setAttribute('data-color', '#ffdd00');
2014
script.setAttribute('data-position', 'Right');
2115
script.setAttribute('data-x_margin', '18');
2216
script.setAttribute('data-y_margin', '18');
23-
24-
// Add onload handler to check if widget loaded
25-
script.onload = () => {
26-
console.log('BMC Widget script loaded successfully');
27-
// Try to trigger widget initialization if needed
28-
setTimeout(() => {
29-
if (typeof window.BMC !== 'undefined') {
30-
console.log('BMC Widget initialized');
31-
} else {
32-
console.log('BMC Widget not initialized, checking DOM...');
33-
}
34-
}, 1000);
35-
};
36-
37-
script.onerror = () => {
38-
console.error('BMC Widget script failed to load');
17+
script.async = true;
18+
19+
script.onload = function () {
20+
const event = new CustomEvent('DOMContentLoaded', {
21+
bubbles: true,
22+
cancelable: true,
23+
});
24+
window.dispatchEvent(event);
3925
};
4026

4127
document.head.appendChild(script);
4228

43-
// Cleanup function
4429
return () => {
45-
// Remove the script when component unmounts
46-
const scriptToRemove = document.querySelector('script[data-name="BMC-Widget"]');
47-
if (scriptToRemove) {
48-
scriptToRemove.remove();
30+
document.head.removeChild(script);
31+
const widget = document.getElementById('bmc-wbtn');
32+
if (widget) {
33+
document.body.removeChild(widget);
4934
}
5035
};
5136
}, []);
5237

53-
return null; // This component doesn't render anything visible
38+
return null;
5439
}

0 commit comments

Comments
 (0)