File size: 11,352 Bytes
46c1ea0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | // Telegram Mini-Game Development Research Page Interactivity
class TelegramGameResearch {
constructor() {
this.sections = document.querySelectorAll('.research-section');
this.init();
}
init() {
this.initializeIntersectionObserver();
this.initializeCountUpAnimations();
this.initializeTooltips();
this.initializeCopyCodeBlocks();
this.initializeProgressTracker();
this.initializeKeywordHighlighter();
}
initializeIntersectionObserver() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
// Animate child elements with staggered delay
const childElements = entry.target.querySelectorAll('.animate-child');
childElements.forEach((el, index) => {
el.style.transitionDelay = `${index * 0.1}s`;
el.classList.add('animated');
});
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
this.sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
}
initializeCountUpAnimations() {
const stats = [
{ element: '.stat-1', value: 15000000, suffix: '+' },
{ element: '.stat-2', value: 800000000, suffix: '+' },
{ element: '.stat-3', value: 94, suffix: '%' },
{ element: '.stat-4', value: 2.3, suffix: 'B' }
];
stats.forEach(stat => {
const element = document.querySelector(stat.element);
if (!element) return;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
this.animateCountUp(element, stat.value, stat.suffix);
observer.unobserve(element);
}
});
});
observer.observe(element);
});
}
animateCountUp(element, target, suffix) {
const duration = 2000;
const startTime = Date.now();
const startValue = 0;
const animate = () => {
const currentTime = Date.now();
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
let currentValue;
if (suffix === '%' || suffix === 'B') {
currentValue = startValue + (target - startValue) * progress;
element.textContent = currentValue.toFixed(suffix === 'B' ? 1 : 0) + suffix;
} else {
currentValue = Math.floor(startValue + (target - startValue) * progress);
element.textContent = this.formatNumber(currentValue) + suffix;
}
if (progress < 1) {
requestAnimationFrame(animate);
}
};
requestAnimationFrame(animate);
}
formatNumber(num) {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
} else if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
}
initializeTooltips() {
// Initialize tooltips for technical terms
const tooltips = document.querySelectorAll('[data-tooltip]');
tooltips.forEach(element => {
const tooltipText = element.getAttribute('data-tooltip');
const tooltip = document.createElement('div');
tooltip.className = 'absolute hidden bg-gray-900 text-white px-3 py-2 rounded-lg text-sm z-50 whitespace-nowrap';
tooltip.textContent = tooltipText;
// Position calculation
const updatePosition = () => {
const rect = element.getBoundingClientRect();
tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`;
tooltip.style.top = `${rect.top - tooltip.offsetHeight - 10}px`;
};
element.addEventListener('mouseenter', () => {
document.body.appendChild(tooltip);
tooltip.classList.remove('hidden');
updatePosition();
});
element.addEventListener('mouseleave', () => {
tooltip.remove();
});
});
}
initializeCopyCodeBlocks() {
const codeBlocks = document.querySelectorAll('.code-snippet pre');
codeBlocks.forEach(block => {
const copyButton = document.createElement('button');
copyButton.className = 'absolute top-4 right-4 text-gray-400 hover:text-white transition-colors';
copyButton.innerHTML = '<i data-feather="copy" class="w-5 h-5"></i>';
block.parentNode.style.position = 'relative';
block.parentNode.appendChild(copyButton);
copyButton.addEventListener('click', async () => {
const code = block.textContent;
try {
await navigator.clipboard.writeText(code);
// Visual feedback
const originalIcon = copyButton.innerHTML;
copyButton.innerHTML = '<i data-feather="check" class="w-5 h-5 text-green-500"></i>';
setTimeout(() => {
copyButton.innerHTML = originalIcon;
feather.replace();
}, 2000);
} catch (err) {
console.error('Failed to copy code:', err);
}
});
});
}
initializeProgressTracker() {
const progressBar = document.createElement('div');
progressBar.className = 'fixed top-0 left-0 h-1 bg-gradient-to-r from-primary-500 to-secondary-500 z-50 transition-all duration-150';
progressBar.style.width = '0%';
document.body.appendChild(progressBar);
window.addEventListener('scroll', () => {
const windowHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (window.scrollY / windowHeight) * 100;
progressBar.style.width = `${scrolled}%`;
});
}
initializeKeywordHighlighter() {
// SEO-related keyword highlighting
const keywords = [
'Telegram Mini-Game', 'Bot API', 'Web App', 'HTML5 Games',
'JavaScript', 'Phaser', 'PixiJS', 'Monetization',
'Telegram Features', 'Gaming SEO', 'Real-time', 'Multiplayer'
];
const content = document.querySelector('.research-content');
if (!content) return;
keywords.forEach(keyword => {
const regex = new RegExp(`\\b(${keyword})\\b`, 'gi');
content.innerHTML = content.innerHTML.replace(regex,
`<span class="keyword-highlight">$1</span>`
);
});
}
// Utility function for API data fetching (example)
async fetchTelegramStats() {
try {
// This would be a real API call in production
// const response = await fetch('https://api.telegram.org/stats');
// return await response.json();
// Mock data for demonstration
return {
dailyUsers: 15000000,
retentionRate: 94,
revenuePotential: 2.3
};
} catch (error) {
console.error('Failed to fetch Telegram stats:', error);
return null;
}
}
// Initialize search functionality
initializeSearch() {
const searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.placeholder = 'Search topics (e.g., API, Monetization, SEO)...';
searchInput.className = 'fixed top0 right-4 z-50 bg-white shadow-xl border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500';
document.body.appendChild(searchInput);
searchInput.addEventListener('input', (e) => {
const searchTerm = e.target.value.toLowerCase();
this.sections.forEach(section => {
const text = section.textContent.toLowerCase();
const isMatch = text.includes(searchTerm);
section.style.opacity = isMatch ? '1' : '0.3';
section.style.pointerEvents = isMatch ? 'auto' : 'none';
});
});
}
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
const researchPage = new TelegramGameResearch();
// Initialize search if needed
// researchPage.initializeSearch();
// Update stats from mock API
researchPage.fetchTelegramStats().then(stats => {
if (stats) {
console.log('Telegram Gaming Stats:', stats);
}
});
// Add keyboard shortcuts
document.addEventListener('keydown', (e) => {
// Ctrl/Cmd + F focuses search
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
e.preventDefault();
// Focus search input if exists
const searchInput = document.querySelector('input[placeholder*="Search"]');
if (searchInput) searchInput.focus();
}
// Escape to clear search
if (e.key === 'Escape') {
const searchInput = document.querySelector('input[placeholder*="Search"]');
if (searchInput) searchInput.value = '';
}
});
});
// Enhanced analytics tracking
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-XXXXX'); // Replace with actual Analytics ID
// Performance monitoring
if ('performance' in window) {
const timing = performance.timing;
const pageLoadTime = timing.loadEventEnd - timing.navigationStart;
console.log(`Page loaded in ${pageLoadTime}ms`);
// Send to analytics if needed
gtag('event', 'page_load_time', {
value: pageLoadTime,
metric_id: 'page_load'
});
}
// Lazy loading for images
document.addEventListener('DOMContentLoaded', () => {
const lazyImages = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
observer.unobserve(img);
}
});
});
lazyImages.forEach(img => imageObserver.observe(img));
}); |