133 lines
No EOL
3.6 KiB
HTML
133 lines
No EOL
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>MonkeyType Profile Data</title>
|
|
<style>
|
|
body {
|
|
background-color: #1e1e1e;
|
|
color: #f0f0f0;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
th,
|
|
td {
|
|
padding: 12px;
|
|
text-align: center;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
|
|
th {
|
|
background-color: #333;
|
|
color: #f0f0f0;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>MonkeyType Profile Data</h1>
|
|
<table id="profileTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Added At</th>
|
|
<th>Completed tests</th>
|
|
<th>Started tests</th>
|
|
<th>Time Typing</th>
|
|
<th>Best 15s</th>
|
|
<th>Best 30s</th>
|
|
<th>Best 60s</th>
|
|
<th>Best 120s</th>
|
|
<th>Best 10w</th>
|
|
<th>Best 25w</th>
|
|
<th>Best 50w</th>
|
|
<th>Best 100w</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
|
|
<script>
|
|
|
|
const users = (new URLSearchParams(window.location.search)).get('users');
|
|
|
|
// no users passed => ask for them and reload
|
|
if (users == null || users == '') {
|
|
var names = prompt('Please provide user names, delimited by \',\'');
|
|
window.location.replace(location.protocol + '//' + location.host + location.pathname + '?users=' + names);
|
|
}
|
|
|
|
const urls = users.split(",").map(user => 'https://api.monkeytype.com/users/' + user.replace(' ', '') + '/profile');
|
|
|
|
const table = document.querySelector('#profileTable tbody');
|
|
|
|
for (url of urls) {
|
|
fetch(url)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const { name, addedAt, typingStats, personalBests } = data.data;
|
|
const { completedTests, startedTests, timeTyping } = typingStats;
|
|
const { time, words } = personalBests;
|
|
|
|
function maxReducer({ prev_wpm, prev_acc }, { current_wpm, current_acc }) {
|
|
return (prev_wpm > current_wpm) ? { prev_wpm, prev_acc } : { current_wpm, current_acc }
|
|
}
|
|
|
|
function getMaxWpmAcc(stats) {
|
|
var max_acc = 0.0; var max_wpm = 0.0;
|
|
for ({ wpm, acc } of stats) {
|
|
if (wpm > max_wpm) {
|
|
max_wpm = wpm;
|
|
max_acc = acc;
|
|
}
|
|
}
|
|
return max_wpm + ' | ' + max_acc + '%';
|
|
}
|
|
|
|
const best15s = getMaxWpmAcc(time['15']);
|
|
|
|
function maxReducer(prev, current) {
|
|
return (prev > current) ? prev : current
|
|
}
|
|
|
|
const best30s = getMaxWpmAcc(time['30']);
|
|
const best60s = getMaxWpmAcc(time['60']);
|
|
const best120s = getMaxWpmAcc(time['120']);
|
|
const best10w = getMaxWpmAcc(words['10']);
|
|
const best25w = getMaxWpmAcc(words['25']);
|
|
const best50w = getMaxWpmAcc(words['50']);
|
|
const best100w = getMaxWpmAcc(words['100']);
|
|
|
|
const row = `
|
|
<tr>
|
|
<td>${name}</td>
|
|
<td>${new Date(addedAt).toLocaleDateString()}</td>
|
|
<td>${completedTests}</td>
|
|
<td>${startedTests}</td>
|
|
<td>${new Date(timeTyping * 1000).toISOString().substr(11, 8)}</td>
|
|
<td>${best15s}</td>
|
|
<td>${best30s}</td>
|
|
<td>${best60s}</td>
|
|
<td>${best120s}</td>
|
|
<td>${best10w}</td>
|
|
<td>${best25w}</td>
|
|
<td>${best50w}</td>
|
|
<td>${best100w}</td>
|
|
</tr>
|
|
`;
|
|
|
|
table.insertAdjacentHTML('beforeend', row);
|
|
})
|
|
.catch(error => { alert(error); console.error(error); });
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |