Download script.js from pedagophys/shocking-volt-adventures: direct link, hf CLI and curl.
- Browser
- Download file 10.3 kB
-
https://huggingface.co/spaces/pedagophys/shocking-volt-adventures/resolve/main/script.js
- Command line
-
hf download hf://spaces/pedagophys/shocking-volt-adventures/script.js
-
curl -L -o script.js https://huggingface.co/spaces/pedagophys/shocking-volt-adventures/resolve/main/script.js
10.3 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Load crystal details if on details page | |
| if (window.location.pathname.includes('details.html')) { | |
| loadCrystalDetails(); | |
| } | |
| // Calculator functionality | |
| const radioButtons = document.querySelectorAll('input[name="crystal-structure"]'); | |
| const resultsContainer = document.getElementById('calculator-results'); | |
| radioButtons.forEach(radio => { | |
| radio.addEventListener('change', function() { | |
| if (this.checked) { | |
| updateCalculator(this.value); | |
| } | |
| function loadCrystalDetails() { | |
| const params = new URLSearchParams(window.location.search); | |
| const structure = params.get('structure'); | |
| const detailsContainer = document.getElementById('crystal-details'); | |
| if (!structure) { | |
| detailsContainer.innerHTML = ` | |
| <div class="text-center py-8"> | |
| <i data-feather="alert-triangle" class="w-12 h-12 text-yellow-500 mx-auto mb-4"></i> | |
| <h2 class="text-2xl font-bold text-indigo-800 mb-2">Structure non spécifiée</h2> | |
| <p class="text-gray-600 mb-4">Aucune structure cristalline n'a été spécifiée.</p> | |
| <a href="index.html" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-md inline-flex items-center"> | |
| <i data-feather="home" class="mr-2"></i> | |
| Retour à l'accueil | |
| </a> | |
| </div> | |
| `; | |
| feather.replace(); | |
| return; | |
| } | |
| // Simulate loading while we fetch data | |
| setTimeout(() => { | |
| const details = getCrystalDetails(structure); | |
| if (details) { | |
| detailsContainer.innerHTML = ` | |
| <div class="flex flex-col md:flex-row gap-8"> | |
| <div class="md:w-1/2"> | |
| <img src="${details.image}" alt="${details.title}" class="w-full rounded-lg shadow-md mb-4"> | |
| <div class="grid grid-cols-2 gap-4 mb-4"> | |
| <div class="bg-blue-50 p-3 rounded-lg"> | |
| <p class="text-sm text-blue-600 font-medium">Atomes/maille</p> | |
| <p class="text-xl font-bold text-blue-800">${details.atomsPerCell}</p> | |
| </div> | |
| <div class="bg-purple-50 p-3 rounded-lg"> | |
| <p class="text-sm text-purple-600 font-medium">Compacité</p> | |
| <p class="text-xl font-bold text-purple-800">${details.compactness}</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="md:w-1/2"> | |
| <h2 class="text-2xl font-bold text-indigo-800 mb-4">${details.title}</h2> | |
| <div class="prose prose-indigo max-w-none"> | |
| ${details.description} | |
| </div> | |
| <div class="mt-6"> | |
| <h3 class="font-semibold text-lg text-indigo-700 mb-2">Métaux exemplaires</h3> | |
| <div class="flex flex-wrap gap-2"> | |
| ${details.examples.map(ex => ` | |
| <span class="bg-gray-100 text-gray-800 text-sm px-3 py-1 rounded-full">${ex}</span> | |
| `).join('')} | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| } else { | |
| detailsContainer.innerHTML = ` | |
| <div class="text-center py-8"> | |
| <i data-feather="alert-circle" class="w-12 h-12 text-red-500 mx-auto mb-4"></i> | |
| <h2 class="text-2xl font-bold text-indigo-800 mb-2">Structure inconnue</h2> | |
| <p class="text-gray-600 mb-4">La structure "${structure}" n'est pas reconnue.</p> | |
| <a href="index.html" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-md inline-flex items-center"> | |
| <i data-feather="home" class="mr-2"></i> | |
| Retour à l'accueil | |
| </a> | |
| </div> | |
| `; | |
| } | |
| feather.replace(); | |
| }, 1000); | |
| } | |
| function getCrystalDetails(structure) { | |
| const details = { | |
| 'cubique-simple': { | |
| title: 'Cubique Simple', | |
| image: 'http://static.photos/science/640x360/1', | |
| atomsPerCell: 1, | |
| compactness: '52%', | |
| examples: ['Polonium'], | |
| description: ` | |
| <p>La structure cubique simple (CS) est la plus élémentaire des structures cristallines. Elle se compose d'un atome à chaque sommet d'un cube.</p> | |
| <p>Dans cette structure, chaque atome a 6 voisins immédiats (coordination 6). La compacité est relativement faible (52%), ce qui signifie que 52% du volume de la maille est occupé par les atomes.</p> | |
| <p>Le paramètre de maille (a) est égal à deux fois le rayon atomique (r) : a = 2r</p> | |
| ` | |
| }, | |
| 'cubique-centree': { | |
| title: 'Cubique Centrée', | |
| image: 'http://static.photos/science/640x360/2', | |
| atomsPerCell: 2, | |
| compactness: '68%', | |
| examples: ['Fer α', 'Chrome', 'Tungstène'], | |
| description: ` | |
| <p>La structure cubique centrée (CC) possède un atome à chaque sommet du cube et un atome au centre de la maille.</p> | |
| <p>Chaque atome a 8 voisins immédiats (coordination 8). La compacité est de 68%, plus élevée que la structure cubique simple.</p> | |
| <p>Relation entre le paramètre de maille (a) et le rayon atomique (r) : a√3 = 4r</p> | |
| ` | |
| }, | |
| 'cubique-faces-centrees': { | |
| title: 'Cubique Faces Centrées', | |
| image: 'http://static.photos/science/640x360/3', | |
| atomsPerCell: 4, | |
| compactness: '74%', | |
| examples: ['Cuivre', 'Aluminium', 'Or', 'Argent'], | |
| description: ` | |
| <p>La structure cubique faces centrées (CFC) possède des atomes aux sommets et au centre de chaque face du cube.</p> | |
| <p>Chaque atome a 12 voisins immédiats (coordination 12). C'est l'une des structures les plus compactes avec une compacité de 74%.</p> | |
| <p>Relation entre le paramètre de maille (a) et le rayon atomique (r) : a√2 = 4r</p> | |
| ` | |
| }, | |
| 'hexagonale-compacte': { | |
| title: 'Hexagonale Compacte', | |
| image: 'http://static.photos/science/640x360/4', | |
| atomsPerCell: 6, | |
| compactness: '74%', | |
| examples: ['Magnésium', 'Zinc', 'Titane α'], | |
| description: ` | |
| <p>La structure hexagonale compacte (HC) est formée par l'empilement compact de couches d'atomes disposés selon un réseau hexagonal.</p> | |
| <p>Comme la CFC, chaque atome a 12 voisins immédiats (coordination 12) et la compacité est de 74%. La différence réside dans la séquence d'empilement des plans atomiques.</p> | |
| <p>La maille élémentaire est un prisme droit à base losange (maille rhomboédrique).</p> | |
| ` | |
| } | |
| }; | |
| return details[structure.toLowerCase()]; | |
| } | |
| }); | |
| }); | |
| function updateCalculator(structure) { | |
| let resultsHTML = ''; | |
| let atomsPerCell = 0; | |
| let compactness = 0; | |
| let description = ''; | |
| switch(structure) { | |
| case 'cubique-simple': | |
| atomsPerCell = 1; | |
| compactness = 0.52; | |
| description = "Chaque atome aux sommets est partagé entre 8 mailles."; | |
| break; | |
| case 'cubique-centree': | |
| atomsPerCell = 2; | |
| compactness = 0.68; | |
| description = "Contient un atome central en plus des atomes aux sommets."; | |
| break; | |
| case 'cubique-faces-centrees': | |
| atomsPerCell = 4; | |
| compactness = 0.74; | |
| description = "Atomes aux sommets et centres des faces du cube."; | |
| break; | |
| case 'hexagonale-compacte': | |
| atomsPerCell = 6; | |
| compactness = 0.74; | |
| description = "Empilement compact de couches hexagonales."; | |
| break; | |
| } | |
| resultsHTML = ` | |
| <div class="w-full"> | |
| <h3 class="text-xl font-semibold text-indigo-700 mb-2">${structure.replace('-', ' ').toUpperCase()}</h3> | |
| <div class="space-y-2"> | |
| <div> | |
| <span class="font-medium">Atomes par maille:</span> | |
| <span class="ml-2 bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-sm">${atomsPerCell}</span> | |
| </div> | |
| <div> | |
| <span class="font-medium">Compacité:</span> | |
| <span class="ml-2 bg-purple-100 text-purple-800 px-2 py-1 rounded-full text-sm">${compactness}</span> | |
| </div> | |
| <p class="text-gray-600 text-sm mt-2">${description}</p> | |
| </div> | |
| </div> | |
| `; | |
| resultsContainer.innerHTML = resultsHTML; | |
| } | |
| // Navigation for crystal cards - each card will navigate to its detail page | |
| const crystalCards = document.querySelectorAll('.crystal-card'); | |
| crystalCards.forEach(card => { | |
| card.addEventListener('click', function() { | |
| const structure = this.getAttribute('data-structure'); | |
| window.location.href = `details.html?structure=${structure}`.toLowerCase(); | |
| }); | |
| }); | |
| }); |