forked from GithubMirrors/cardconjurer
		
	ask scryfall
This commit is contained in:
		
							
								
								
									
										22
									
								
								data/site/other/askScryfall/askScryfall.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								data/site/other/askScryfall/askScryfall.js
									
									
									
									
									
										Normal 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()
 | 
			
		||||
@@ -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>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								data/site/other/askScryfall/minus.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/site/other/askScryfall/minus.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 47 KiB  | 
							
								
								
									
										1
									
								
								data/site/other/askScryfall/planeswalkerAbilities.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								data/site/other/askScryfall/planeswalkerAbilities.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								data/site/other/askScryfall/plus.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/site/other/askScryfall/plus.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 44 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								data/site/other/askScryfall/ultimate.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/site/other/askScryfall/ultimate.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 49 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								data/site/other/askScryfall/urzaBlank.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/site/other/askScryfall/urzaBlank.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 653 KiB  | 
		Reference in New Issue
	
	Block a user