mirror of
https://github.com/cfultz/mtgcsv.git
synced 2024-11-22 01:10:02 +01:00
Updated code
This commit is contained in:
parent
3c621c7aad
commit
175e62ef60
50
app.js
50
app.js
@ -48,39 +48,59 @@ async function fetchCardSuggestions(query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchCardDetails(cardName, setCode) {
|
async function fetchCardDetails(cardName, setCode) {
|
||||||
|
// Use the Scryfall 'named' endpoint to fetch the exact card by name and set code
|
||||||
const response = await fetch(`https://api.scryfall.com/cards/named?exact=${encodeURIComponent(cardName)}&set=${encodeURIComponent(setCode)}`);
|
const response = await fetch(`https://api.scryfall.com/cards/named?exact=${encodeURIComponent(cardName)}&set=${encodeURIComponent(setCode)}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
console.log('Fetched Data:', data); // Debugging: Log the fetched data
|
||||||
|
|
||||||
|
// Return the relevant card details
|
||||||
return {
|
return {
|
||||||
|
set: data.set.toUpperCase(),
|
||||||
|
card_id: data.collector_number,
|
||||||
mana_cost: data.mana_cost || 'N/A',
|
mana_cost: data.mana_cost || 'N/A',
|
||||||
power: data.power || 'N/A',
|
power: data.power || 'N/A',
|
||||||
toughness: data.toughness || 'N/A',
|
toughness: data.toughness || 'N/A',
|
||||||
type: data.type_line.split('—')[0].trim(), // Remove anything after em dash
|
type: data.type_line.split('—')[0].trim(),
|
||||||
rarity: data.rarity || 'N/A',
|
rarity: data.rarity || 'N/A',
|
||||||
price: data.prices.usd || '0.00', // Fetching the price in USD
|
price: data.prices.usd || '0.00',
|
||||||
imageUrl: data.image_uris ? data.image_uris.small : null
|
imageUrl: data.image_uris ? data.image_uris.small : null,
|
||||||
|
name: data.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addCard() {
|
async function addCard() {
|
||||||
const cardName = document.getElementById('card-name').value;
|
const cardName = document.getElementById('card-name').value;
|
||||||
const setCode = document.getElementById('set-code').value;
|
const setCode = document.getElementById('set-code').value;
|
||||||
const cardId = document.getElementById('card-id').value;
|
|
||||||
|
// Fetch card details using the card name and set code
|
||||||
|
const cardDetails = await fetchCardDetails(cardName, setCode);
|
||||||
|
|
||||||
|
if (cardDetails) {
|
||||||
|
updateCardDetails(cardDetails);
|
||||||
|
} else {
|
||||||
|
alert("Card not found with the given name and set code.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCardDetails(printing) {
|
||||||
|
document.getElementById('set-code').value = printing.set;
|
||||||
|
document.getElementById('card-id').value = printing.card_id;
|
||||||
|
|
||||||
const quantity = document.getElementById('quantity').value;
|
const quantity = document.getElementById('quantity').value;
|
||||||
const foil = document.getElementById('foil').value;
|
const foil = document.getElementById('foil').value;
|
||||||
|
|
||||||
const cardDetails = await fetchCardDetails(cardName, setCode);
|
|
||||||
|
|
||||||
const cardData = {
|
const cardData = {
|
||||||
name: cardName,
|
name: document.getElementById('card-name').value,
|
||||||
set: setCode,
|
set: printing.set,
|
||||||
card_id: cardId,
|
card_id: printing.card_id,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
foil: foil,
|
foil: foil,
|
||||||
mana_type: cardDetails.mana_cost,
|
mana_type: printing.mana_cost,
|
||||||
power: cardDetails.power,
|
power: printing.power,
|
||||||
toughness: cardDetails.toughness,
|
toughness: printing.toughness,
|
||||||
type: cardDetails.type,
|
type: printing.type,
|
||||||
rarity: cardDetails.rarity
|
rarity: printing.rarity
|
||||||
};
|
};
|
||||||
|
|
||||||
cardList.push(cardData);
|
cardList.push(cardData);
|
||||||
@ -90,7 +110,7 @@ async function addCard() {
|
|||||||
document.getElementById('csv-output').value = csvContent;
|
document.getElementById('csv-output').value = csvContent;
|
||||||
|
|
||||||
// Show the card image, name, and price in the dissolving popup
|
// Show the card image, name, and price in the dissolving popup
|
||||||
showCardPopup(cardName, cardDetails.imageUrl, cardDetails.price);
|
showCardPopup(cardData.name, printing.imageUrl, printing.price);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateCSVContent() {
|
function generateCSVContent() {
|
||||||
|
20
styles.css
20
styles.css
@ -17,7 +17,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: 'Sorts Mill Goudy', serif;
|
||||||
background-color: var(--background-color);
|
background-color: var(--background-color);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -36,7 +36,6 @@ body {
|
|||||||
h1 {
|
h1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
font-family: 'Sorts Mill Goudy', serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
form div {
|
form div {
|
||||||
@ -113,6 +112,7 @@ button:hover {
|
|||||||
max-width: 60%;
|
max-width: 60%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -121,25 +121,25 @@ button:hover {
|
|||||||
.hamburger-menu {
|
.hamburger-menu {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
color: var(--text-color, black); /* Ensure the color follows the theme */
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-content {
|
.menu-content {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 40px;
|
top: 40px;
|
||||||
left: 0; /* Change to left for opposite direction */
|
left: 0;
|
||||||
background-color: var(--background-color, white); /* Background color follows the theme */
|
background-color: var(--background-color);
|
||||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
min-width: 150px;
|
min-width: 150px;
|
||||||
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-content label,
|
.menu-content label,
|
||||||
.menu-content input {
|
.menu-content input {
|
||||||
color: var(--text-color, black); /* Text color follows the theme */
|
color: var(--text-color);
|
||||||
font-family: 'Sorts Mill Goudy', serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-content.show {
|
.menu-content.show {
|
||||||
@ -148,13 +148,11 @@ button:hover {
|
|||||||
|
|
||||||
/* Dark mode styles */
|
/* Dark mode styles */
|
||||||
body.dark-mode .menu-content {
|
body.dark-mode .menu-content {
|
||||||
background-color: #333; /* Dark background for dark mode */
|
background-color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.dark-mode .hamburger-menu,
|
body.dark-mode .hamburger-menu,
|
||||||
body.dark-mode .menu-content label,
|
body.dark-mode .menu-content label,
|
||||||
body.dark-mode .menu-content input {
|
body.dark-mode .menu-content input {
|
||||||
color: white; /* White text for dark mode */
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user