JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="page-header">Tagaya Version Query</h1>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<form id="queryForm" class="form-inline">
<div class="form-group">
<label for="region">Region</label>
<select id="region" class="form-control">
<option value="EUR/EU">Europe</option>
<option value="USA/US">USA</option>
<option value="JAP/JP">Japan</option>
</select>
</div>
<div class="form-group">
<label for="titleID">Title ID</label>
<input id="titleID" type="text" class="form-control" placeholder="0005000E10145000" />
</div>
<button type="submit" class="btn btn-primary">Get latest version</button>
</form>
</div>
</div>
<div class="row hidden">
<div class="col-xs-12">
<table id="result" class="table table-bordered table-striped">
<thead>
<tr>
<td>Region</td>
<td>Title ID</td>
<td>Version</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
CSS
.row {
margin-bottom: 20px;
}
JavaScript
var cache = {
versionListVersion: { },
versionList: { }
};
var fetchLatestVersionListVersion = function (region, callback) {
if (cache.versionListVersion[region]) {
return callback(cache.versionListVersion[region]);
}
$.ajax("https://crossorigin.me/https://tagaya.wup.shop.nintendo.net/tagaya/versionlist/"+region+"/latest_version", {
dataType: 'xml'
}).done(function (data) {
var latest = data.querySelectorAll('version')[0].textContent;
cache.versionListVersion[region] = latest;
callback(latest);
});
};
var fetchLatestVersionList = function (region, callback) {
fetchLatestVersionListVersion(region, function (latest) {
if (cache.versionList[region]) {
return callback(cache.versionList[region]);
}
$.ajax("https://crossorigin.me/https://tagaya.wup.shop.nintendo.net/tagaya/versionlist/"+region+"/list/"+latest+".versionlist", {
dataType: 'xml'
}).done(function (data) {
var versionList = [].slice.call(data.querySelectorAll('titles > title'));
cache.versionList[region] = versionList;
callback(versionList);
});
});
}
var getLatestVersionForTitleId = function (region, titleID, callback) {
fetchLatestVersionList(region, function (versionList) {
for (var key in versionList) {
var title = versionList[key];
var id = title.querySelector('id').textContent;
if (id == titleID) {
return callback(title.querySelector('version').textContent);
}
}
return callback(null);
});
};
$('#queryForm').submit(function (event) {
event.preventDefault();
var region = $('#region').val();
var titleID = $('#titleID').val().trim();
if (!!titleID.match(/^[a-f0-9]{8}-?[a-f0-9]{8}$/i)) {
titleID = titleID.replace(/-/, '');
$('#titleID').parent().removeClass('has-error');
var id = region.replace(/\//, '-').toLowerCase() + titleID.toLowerCase();
if ($('#'+id).length) return;
getLatestVersionForTitleId(region, titleID,...