This commit is contained in:
Kyle
2019-12-25 10:36:30 -08:00
parent 5101f9a592
commit b6c5e96e83
2 changed files with 26 additions and 17 deletions

View File

@@ -954,28 +954,35 @@ function inputCardNameTextImport(cardName) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var importCardTextResponse = this.responseText.split('{"object":"card"')[1].split('{"object":"related_card"')[0];
importText(beforeAfter(importCardTextResponse, '"name":"', '",'), "Title");
importText(beforeAfter(importCardTextResponse, '"type_line":"', '",'), "Type");
importText(beforeAfter(importCardTextResponse, '"oracle_text":"', '",').replace(/\\n/g, "{line}"), "Rules Text");
if (importCardTextResponse.includes('"power":"')) {
importText(beforeAfter(importCardTextResponse, '"power":"', '",') + "/" + beforeAfter(importCardTextResponse, '"toughness":"', '",'), "Power Toughness");
} else {
importText("", "Power Toughness");
}
document.getElementById("inputManaCost").value = beforeAfter(importCardTextResponse, '"mana_cost":"', '",');
document.getElementById("inputCardArtName").value = beforeAfter(importCardTextResponse, '"name":"', '",');
document.getElementById("inputSetCode").value = beforeAfter(importCardTextResponse, '"set":"', '",');
document.getElementById("inputSetRarity").value = beforeAfter(importCardTextResponse, '"rarity":"', '",')[0];
whiteToTransparent(setSymbol, "https://cors-anywhere.herokuapp.com/http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=" + document.getElementById("inputSetCode").value + "&size=large&rarity=" + document.getElementById("inputSetRarity").value)
inputCardArtName(beforeAfter(importCardTextResponse, '"name":"', '",'));
savedImportResponse = this.responseText.split('{"object":"card"');
inputCardNameNumberTextImport(1);
document.getElementById("inputCardNameNumberTextImport").max = savedImportResponse.length - 1;
document.getElementById("inputCardNameNumberTextImport").value = 1;
} else if (this.readyState == 4 && this.status == 404) {
savedImportResponse = ""
alert("Sorry, but we can't seem to find any card named '" + cardName + "'");
}
}
xhttp.open("GET", "https://api.scryfall.com/cards/search?order=released&q=name%3D" + cardName.replace(/ /g, "_"), true);
xhttp.open("GET", "https://api.scryfall.com/cards/search?order=released&q=name%3D" + cardName.replace(/ /g, "+"), true);
xhttp.send();
}
function inputCardNameNumberTextImport(index) {
var importCardTextResponse = savedImportResponse[index]//.split('{"object":"related_card"')[0]
importText(beforeAfter(importCardTextResponse, '"name":"', '",'), "Title");
importText(beforeAfter(importCardTextResponse, '"type_line":"', '",'), "Type");
importText(beforeAfter(importCardTextResponse, '"oracle_text":"', '",').replace(/\\n/g, "{line}").replace(/ \\"/g, ' \u201C').replace(/\\"/g, '\u201D'), "Rules Text");
if (importCardTextResponse.includes('"power":"')) {
importText(beforeAfter(importCardTextResponse, '"power":"', '",') + "/" + beforeAfter(importCardTextResponse, '"toughness":"', '",'), "Power Toughness");
} else {
importText("", "Power Toughness");
}
document.getElementById("inputManaCost").value = beforeAfter(importCardTextResponse, '"mana_cost":"', '",');
document.getElementById("inputCardArtName").value = beforeAfter(importCardTextResponse, '"name":"', '",');
document.getElementById("inputSetCode").value = beforeAfter(importCardTextResponse, '"set":"', '",');
document.getElementById("inputSetRarity").value = beforeAfter(importCardTextResponse, '"rarity":"', '",')[0];
whiteToTransparent(setSymbol, "https://cors-anywhere.herokuapp.com/http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=" + document.getElementById("inputSetCode").value + "&size=large&rarity=" + document.getElementById("inputSetRarity").value);
inputCardArtName(beforeAfter(importCardTextResponse, '"name":"', '",'));
}
function importText(text, target) {
for (var i = 0; i < version.textList.length; i++) {
if (version.textList[i][0] == target) {

View File

@@ -136,8 +136,10 @@
</div>
</div>
<div class="tabContent mainEditor" id="import">
Type in a card name to import its text! (Only works for regular cards)
Type in a card name to import it! (Only works for regular cards)
<input type="text" class="input text" id="inputCardNameTextImport" onchange="inputCardNameTextImport(this.value)" placeholder="Via Card Name">
Select which card to import:
<input type="number" class="input number" id="inputCardNameNumberTextImport" onchange="inputCardNameNumberTextImport(this.value)" value="1" min="1" max="1">
</div>
<!-- Card editor tabs end here! -->
<div class="bar"></div>