Spaces:
Running
Running
Download script.js from Gearlock/cardcraft-wizardry: direct link, hf CLI and curl.
- Browser
- Download file 5.07 kB
-
https://huggingface.co/spaces/Gearlock/cardcraft-wizardry/resolve/main/script.js
- Command line
-
hf download hf://spaces/Gearlock/cardcraft-wizardry/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Gearlock/cardcraft-wizardry/resolve/main/script.js
5.07 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // DOM Elements | |
| const cardSearch = document.getElementById('cardSearch'); | |
| const searchBtn = document.getElementById('searchBtn'); | |
| const cardResults = document.getElementById('cardResults'); | |
| const resultsSection = document.getElementById('resultsSection'); | |
| const deckSuggestions = document.getElementById('deckSuggestions'); | |
| const suggestionsList = document.getElementById('suggestionsList'); | |
| // Event Listeners | |
| searchBtn.addEventListener('click', searchCards); | |
| document.getElementById('searchByNameBtn').addEventListener('click', () => searchCards('name')); | |
| document.getElementById('searchByTypeBtn').addEventListener('click', () => searchCards('type')); | |
| document.getElementById('searchByColorBtn').addEventListener('click', () => searchCards('color')); | |
| // Mock data for demonstration | |
| const mockCards = [ | |
| { name: "Lightning Bolt", type: "Instant", color: "Red", image: "http://static.photos/red/320x240/1" }, | |
| { name: "Counterspell", type: "Instant", color: "Blue", image: "http://static.photos/blue/320x240/2" }, | |
| { name: "Llanowar Elves", type: "Creature", color: "Green", image: "http://static.photos/green/320x240/3" }, | |
| { name: "Swords to Plowshares", type: "Instant", color: "White", image: "http://static.photos/white/320x240/4" }, | |
| { name: "Dark Ritual", type: "Instant", color: "Black", image: "http://static.photos/black/320x240/5" }, | |
| { name: "Sol Ring", type: "Artifact", color: "Colorless", image: "http://static.photos/minimal/320x240/6" } | |
| ]; | |
| const mockDecks = [ | |
| { name: "Red Deck Wins", description: "Aggressive red deck with lots of direct damage", cards: ["Lightning Bolt", "Goblin Guide", "Monastery Swiftspear"] }, | |
| { name: "Blue Control", description: "Control the game with counterspells and card draw", cards: ["Counterspell", "Serum Visions", "Snapcaster Mage"] }, | |
| { name: "Green Ramp", description: "Ramp into big creatures quickly", cards: ["Llanowar Elves", "Cultivate", "Primeval Titan"] } | |
| ]; | |
| // Functions | |
| function searchCards(mode = 'name') { | |
| const searchTerm = cardSearch.value.trim(); | |
| if (!searchTerm) return; | |
| // Show loading state | |
| cardResults.innerHTML = '<div class="col-span-3 text-center py-8"><div class="inline-block spinner border-4 border-red-500 border-t-transparent rounded-full w-12 h-12"></div></div>'; | |
| resultsSection.classList.remove('hidden'); | |
| deckSuggestions.classList.add('hidden'); | |
| // Simulate API call with timeout | |
| setTimeout(() => { | |
| displayCards(mockCards); | |
| generateDeckSuggestions(); | |
| }, 1000); | |
| } | |
| function displayCards(cards) { | |
| cardResults.innerHTML = ''; | |
| if (cards.length === 0) { | |
| cardResults.innerHTML = '<div class="col-span-3 text-center py-8 text-gray-500">No cards found in your collection</div>'; | |
| return; | |
| } | |
| cards.forEach(card => { | |
| const cardElement = document.createElement('div'); | |
| cardElement.className = 'card-item bg-white rounded-lg shadow-md overflow-hidden border border-gray-200'; | |
| cardElement.innerHTML = ` | |
| <img src="${card.image}" alt="${card.name}" class="w-full h-48 object-cover"> | |
| <div class="p-4"> | |
| <h3 class="font-bold text-lg text-gray-800">${card.name}</h3> | |
| <div class="flex items-center mt-2"> | |
| <span class="inline-block w-3 h-3 rounded-full mr-2 bg-${card.color.toLowerCase()}-500"></span> | |
| <span class="text-sm text-gray-600">${card.type}</span> | |
| </div> | |
| </div> | |
| `; | |
| cardResults.appendChild(cardElement); | |
| }); | |
| } | |
| function generateDeckSuggestions() { | |
| deckSuggestions.classList.remove('hidden'); | |
| suggestionsList.innerHTML = ''; | |
| mockDecks.forEach(deck => { | |
| const deckElement = document.createElement('div'); | |
| deckElement.className = 'deck-suggestion bg-gray-50 p-4 rounded-lg'; | |
| deckElement.innerHTML = ` | |
| <h3 class="font-bold text-xl text-red-600 mb-2">${deck.name}</h3> | |
| <p class="text-gray-700 mb-3">${deck.description}</p> | |
| <div class="flex flex-wrap gap-2 mb-3"> | |
| ${deck.cards.map(card => `<span class="bg-orange-100 text-orange-800 px-2 py-1 rounded-full text-sm">${card}</span>`).join('')} | |
| </div> | |
| <button class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="plus" class="mr-2"></i> Build This Deck | |
| </button> | |
| `; | |
| suggestionsList.appendChild(deckElement); | |
| }); | |
| feather.replace(); | |
| } | |
| // Initialize feather icons | |
| feather.replace(); | |
| }); |