};
// Initialize Firebase
if (typeof firebase !== 'undefined' && !firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
// PART 2: REACTION BUTTONS LOGIC
function handleReactions() {
const reactionBox = document.querySelector('.reactions');
if (!reactionBox) return;
const postId = reactionBox.getAttribute('data-post-id');
const reactionButtons = reactionBox.querySelectorAll('.reaction-btn');
const db = firebase.database();
const reactionsRef = db.ref('reactions/' + postId);
reactionsRef.on('value', (snapshot) => {
const counts = snapshot.val() || {};
reactionButtons.forEach(btn => {
const reactionType = btn.getAttribute('data-reaction');
const countEl = btn.querySelector('.reaction-count');
countEl.textContent = counts[reactionType] || 0;
});
});
reactionButtons.forEach(btn => {
btn.addEventListener('click', () => {
const reactionType = btn.getAttribute('data-reaction');
const transaction = (currentCount) => {
return (currentCount || 0) + 1;
};
db.ref('reactions/' + postId + '/' + reactionType).transaction(transaction);
reactionButtons.forEach(b => b.classList.remove('selected'));
btn.classList.add('selected');
});
});
}
// PART 3: ANIMATED POPUP LOGIC
function handleAnimatedPopup() {
const dailyUpdates = {
"2024-05-22": "Dharms Pro Theme में आपका स्वागत है! यह पॉपअप अब हमेशा काम करेगा।",
"2024-05-23": "आज IPL का फाइनल मैच है! कौन जीतेगा?"
};
const popup = document.getElementById('dharms-animated-popup');
const closeBtn = document.getElementById('dharms-popup-close');
const messageEl = document.getElementById('dharms-popup-message');
if (!popup || !closeBtn || !messageEl) return;
const today = new Date(), todayString = today.toISOString().slice(0, 10);
const lastPopupDateKey = 'lastAnimatedPopupDateV2', lastShownDate = localStorage.getItem(lastPopupDateKey);
if (dailyUpdates[todayString] && lastShownDate !== todayString) {
messageEl.innerHTML = dailyUpdates[todayString];
setTimeout(() => { popup.classList.add('popup-visible'); }, 2000);
localStorage.setItem(lastPopupDateKey, todayString);
}
closeBtn.addEventListener('click', () => { popup.classList.remove('popup-visible'); });
}
// Run all scripts after the page is ready
document.addEventListener('DOMContentLoaded', function() {
handleReactions();
handleAnimatedPopup();
});
//]]>