-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspell-donwloader.html
More file actions
41 lines (36 loc) · 1.1 KB
/
spell-donwloader.html
File metadata and controls
41 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
dnd api downloader (open in firefox)
<a id="downloadAnchorElem" style="display:none"></a>
<script type="text/javascript">
//https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
function downloadObjectAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
for(let i=1; i<=319; i++) {
$.ajax({
url: 'http://www.dnd5eapi.co/api/spells/' + i,
dataType: 'json',
method: 'GET',
success: function(data){
downloadObjectAsJson(data, i);
},
error: function(e){
console.warn('Error retrieving data');
console.warn(e);
}
});
}
</script>
</body>
</html>