File size: 4,361 Bytes
5d166b9 | 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 | // Shared JavaScript across all pages
console.log('BlockCraft Pro - Minecraft Hosting loaded');
// Initialize theme
function initTheme() {
if (localStorage.getItem('theme') === 'light') {
document.documentElement.classList.remove('dark');
} else {
document.documentElement.classList.add('dark');
}
}
// Smooth scrolling for anchor links
document.addEventListener('DOMContentLoaded', function() {
// Initialize theme
initTheme();
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add intersection observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
}, observerOptions);
// Observe all cards and features
document.querySelectorAll('.card, .feature-item').forEach(item => {
observer.observe(item);
});
}
// Price calculator functionality
class PriceCalculator {
constructor() {
this.discountRates = {
'1': 0,
'3': 0.05,
'12': 0.15,
'24': 0.20,
'36': 0.30
};
}
calculatePrice(basePrice, duration) {
const discount = this.discountRates[duration] || 0;
const discountedPrice = basePrice * (1 - discount);
return {
original: basePrice,
discounted: discountedPrice,
savings: basePrice - discountedPrice
};
}
}
// Initialize price calculator
const priceCalculator = new PriceCalculator();
// Cookie consent management
function handleCookieConsent() {
const consent = localStorage.getItem('cookieConsent');
if (!consent) {
// Show cookie consent banner
console.log('Cookie consent needed');
}
}
// Form validation
function validateForm(form) {
const inputs = form.querySelectorAll('input[required], select[required], textarea[required]');
let isValid = true;
inputs.forEach(input => {
if (!input.value.trim()) {
isValid = false;
input.classList.add('border-red-500');
} else {
input.classList.remove('border-red-500');
}
});
return isValid;
}
// API integration for server status
async function fetchServerStatus() {
try {
// This would be replaced with actual API endpoint
const response = await fetch('/api/server-status');
const data = await response.json();
return data;
} catch (error) {
console.error('Failed to fetch server status:', error);
return { status: 'unknown', uptime: 0 };
}
}
// Currency converter
class CurrencyConverter {
constructor() {
this.rates = {
'EUR': 1,
'USD': 1.08,
'GBP': 0.85,
'PLN': 4.32
};
}
convert(amount, fromCurrency, toCurrency) {
const fromRate = this.rates[fromCurrency] || 1;
const toRate = this.rates[toCurrency] || 1;
return (amount / fromRate) * toRate;
}
}
// Initialize currency converter
const currencyConverter = new CurrencyConverter();
// Performance monitoring
function monitorPerformance() {
if ('performance' in window) {
const navigationTiming = performance.getEntriesByType('navigation')[0];
console.log('Page load time:', navigationTiming.loadEventEnd - navigationTiming.navigationStart);
}
// Export functions for use in other modules
window.BlockCraftPro = {
initTheme,
priceCalculator,
currencyConverter,
validateForm,
fetchServerStatus,
monitorPerformance
};
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initTheme);
} else {
initTheme();
} |