Skip to content

Instantly share code, notes, and snippets.

@xmrig
Last active February 13, 2024 08:54
Show Gist options
  • Save xmrig/c75fdd1f8e0f3bac05500be2ab718f8e to your computer and use it in GitHub Desktop.
Save xmrig/c75fdd1f8e0f3bac05500be2ab718f8e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha512-MoRNloxbStBcD8z3M/2BmnT+rg4IsMxPkXaGh2zD6LGNNFE80W3onsAhRcMAMrSoyWL9xD7Ert0men7vR8LUZg==" crossorigin="anonymous" />
<title>XMRig API test</title>
</head>
<body>
<div class="container">
<form style="margin-top: 12px">
<div class="form-group">
<label for="address">API address and endpoint</label>
<input type="text" class="form-control" id="address" required placeholder="http://127.0.0.1:<port>/2/summary">
</div>
<div class="form-group">
<label for="token">Access Token</label>
<input type="password" class="form-control" id="token" placeholder="Optional">
</div>
<button id="submit" type="submit" class="btn btn-primary">Get API data</button>
</form>
<pre id="result" style="margin-top: 12px; border: 1px solid rgba(0,0,0,.15); padding: 12px"></pre>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script>
$(function() {
$('#address').val(localStorage.getItem('address'));
$('#token').val(localStorage.getItem('token'));
$('#submit').on('click', function(event) {
var address = $('#address').val();
if (!address) {
return;
}
event.preventDefault();
getData(address, $('#token').val());
});
function getData(address, token) {
var headers = {};
if (token) {
headers.Authorization = 'Bearer ' + token
}
$.ajax({
method: 'get',
url: address,
headers: headers
})
.done(function(data, textStatus, jqXHR) {
$('#result').text(jqXHR.responseText);
localStorage.setItem('address', address);
localStorage.setItem('token', token);
})
.fail(function(jqXHR, textStatus) {
$('#result').text('Failed to get data (' + jqXHR.status + ')');
});
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment