ask scryfall

This commit is contained in:
Kyle
2020-02-23 15:33:41 -08:00
parent e3d4e999ff
commit b69c7ee8b1
11 changed files with 224 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
var fullAbilityList = new Array()
function loadAbilities() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
fullAbilityList = xhttp.responseText.split("$$$")
for (var i = 0; i < 3; i ++) {
fullAbilityList[i] = fullAbilityList[i].split(";")
}
}
}
xhttp.open("GET", "data/site/other/askScryfall/planeswalkerAbilities.txt", true);
xhttp.send();
}
function randomAbility(index) {
possibleAbilities = fullAbilityList[index]
document.getElementById("askScryfallResult").innerHTML = possibleAbilities[Math.floor(Math.random() * (possibleAbilities.length - 1))].replace(/\\"/g, '"')
}
loadAbilities()

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Ask Scryfall - Ability List Generator</title>
</head>
<body>
</body>
<script>
var plusAbilities = new Array()
var minusAbilities = new Array()
var ultimateAbilities = new Array()
function importPlaneswalkers(request) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var planeswalkerList = this.responseText.split('oracle_text":"')
var planeswalkerNameList = this.responseText.replace(/","name":"/g, "").split('"name":"')
//console.log(planeswalkerNameList)
var iAdjust = 0
for (var i = 1; i < planeswalkerList.length; i++) {
var planeswalkerAbilityList = planeswalkerList[i].split('",')[0].split(/\\n/g)
var planeswalkerName = planeswalkerNameList[i - iAdjust].split(/",/g)[0]
if (planeswalkerName.includes(" // ")) {
planeswalkerName = planeswalkerName.split(" // ")[1]
}
for (var n = 0; n < planeswalkerAbilityList.length; n++) {
if (planeswalkerAbilityList[n].includes(":")) {
var abilityText = planeswalkerAbilityList[n].substr(planeswalkerAbilityList[n].indexOf(": ") + 2)
if (abilityText != undefined) {
//console.log(abilityText, planeswalkerName, iAdjust)
abilityText = abilityText.replace(planeswalkerName, "Urza, Academy Headmaster")
var abilityType = planeswalkerAbilityList[n].split(":")[0]
if (!abilityType.includes("X")) {
if (abilityType.includes("+")) {
//plus
plusAbilities[plusAbilities.length] = abilityText
} else if (abilityType.includes("\u2212") && n == planeswalkerAbilityList.length - 1 && n > 1) {
//ult
ultimateAbilities[ultimateAbilities.length] = abilityText
} else if (abilityType.includes("\u2212") || abilityType == "0") {
//minus
minusAbilities[minusAbilities.length] = abilityText
} else {
//do nothing
}
}
}
}
}
if (i < planeswalkerList.length - 1 && planeswalkerList[i - 1].includes('"card_faces"')) {
iAdjust += 1
}
}
if (this.responseText.includes('"has_more":true')) {
importPlaneswalkers(this.responseText.split('"next_page":"')[1].split('","data"')[0].replace(/\\u0026/g, "&"))
} else {
var allAbilities = [plusAbilities, minusAbilities, ultimateAbilities]
let csvContent = "data:text/csv;charset=utf-8,";
allAbilities.forEach(function(rowArray) {
csvContent += rowArray.join(";") + "$$$";
})
var encodedUri = encodeURI(csvContent)
window.open(encodedUri)
}
} else if (this.readyState == 4 && this.status == 404) {
alert("An error occurred. Please try again.");
}
}
xhttp.open("GET", request, true);
xhttp.send();
}
importPlaneswalkers("https://api.scryfall.com/cards/search?order=released&q=type%3Dplaneswalker")
</script>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 KiB