Spaces:
Running
Running
File size: 5,016 Bytes
5595595 b0767d7 5595595 b0767d7 5595595 b0767d7 b344137 5595595 b344137 5595595 cf653c1 8e00599 cf653c1 8e00599 5595595 cf653c1 8e00599 cf653c1 8e00599 5595595 cf653c1 8e00599 cf653c1 8e00599 5595595 | 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 |
// Main JavaScript for 2 Clean 2 Green
document.addEventListener('DOMContentLoaded', async function() {
try {
// Smooth scrolling for anchor links
const anchors = document.querySelectorAll('a[href^="#"]');
anchors.forEach(anchor => {
anchor.addEventListener('click', async function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
await new Promise(resolve => {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
setTimeout(resolve, 1000);
});
}
});
});
// Initialize language selector on all pages
const langSelector = document.getElementById('language-selector');
if (langSelector) {
langSelector.addEventListener('change', async function() {
const lang = this.value;
await updateTranslations(lang);
});
}
// Load translations if needed
if (!window.translations) {
await loadTranslations();
}
} catch (error) {
console.error('Initialization error:', error);
}
});
async function loadTranslations() {
try {
// In a real app, this would fetch from an API
window.translations = {
en: {
nav_how_it_works: "How It Works",
nav_features: "Features",
nav_pricing: "Pricing",
nav_dashboard: "Dashboard",
nav_single_player: "Single Player",
nav_simulator: "Simulator",
nav_signup: "Sign Up"
},
ru: {
nav_how_it_works: "Как это работает",
nav_features: "Функции",
nav_pricing: "Цены",
nav_dashboard: "Панель",
nav_single_player: "Одиночная игра",
nav_simulator: "Симулятор",
nav_signup: "Регистрация"
},
zh: {
nav_how_it_works: "工作原理",
nav_features: "特征",
nav_pricing: "价钱",
nav_dashboard: "仪表板",
nav_single_player: "单人游戏",
nav_simulator: "模拟器",
nav_signup: "注册"
}
};
} catch (error) {
console.error('Failed to load translations:', error);
}
}
async function updateTranslations(lang) {
try {
const elements = document.querySelectorAll('[data-i18n]');
for (const el of elements) {
const key = el.getAttribute('data-i18n');
if (window.translations[lang] && window.translations[lang][key]) {
el.textContent = window.translations[lang][key];
}
}
} catch (error) {
console.error('Translation update failed:', error);
}
}
// Waste types classification
window.wasteCategories = {
plastic: {
name: "Plastic",
color: "#3B82F6",
icon: "♻",
recyclingTip: "Rinse containers before recycling. Remove caps and labels."
},
paper: {
name: "Paper",
color: "#10B981",
icon: "📄",
recyclingTip: "Keep dry and clean. Remove any plastic or metallic parts."
},
glass: {
name: "Glass",
color: "#6366F1",
icon: "🍷",
recyclingTip: "Rinse thoroughly. Separate by color if required."
},
metal: {
name: "Metal",
color: "#F59E0B",
icon: "🔩",
recyclingTip: "Rinse cans. Remove paper labels if possible."
},
ewaste: {
name: "E-Waste",
color: "#EC4899",
icon: "🔌",
recyclingTip: "Do not throw in regular trash. Find specialized recycling."
},
organic: {
name: "Organic",
color: "#84CC16",
icon: "🍂",
recyclingTip: "Compost if possible. Do not mix with recyclables."
}
};
// Global translations object
window.translations = {
en: {
nav_how_it_works: "How It Works",
nav_features: "Features",
nav_pricing: "Pricing",
nav_dashboard: "Dashboard",
nav_single_player: "Single Player",
nav_simulator: "Simulator",
nav_signup: "Sign Up"
},
ru: {
nav_how_it_works: "Как это работает",
nav_features: "Функции",
nav_pricing: "Цены",
nav_dashboard: "Панель",
nav_single_player: "Одиночная игра",
nav_simulator: "Симулятор",
nav_signup: "Регистрация"
},
zh: {
nav_how_it_works: "工作原理",
nav_features: "特征",
nav_pricing: "价钱",
nav_dashboard: "仪表板",
nav_single_player: "单人游戏",
nav_simulator: "模拟器",
nav_signup: "注册"
}
};
|