Last active
February 12, 2016 20:58
-
-
Save arctic5/1e68f9db53cde7fb2a9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>idk wtf im doing</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> | |
<script> | |
function setCookie(cname, cvalue, exdays) { | |
var d = new Date(); | |
d.setTime(d.getTime() + (exdays*24*60*60*1000)); | |
var expires = "expires="+d.toUTCString(); | |
document.cookie = cname + "=" + cvalue + "; " + expires; | |
} | |
function getCookie(cname) { | |
var name = cname + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0; i<ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1); | |
if (c.indexOf(name) == 0) return c.substring(name.length, c.length); | |
} | |
return ""; | |
} | |
window.addEventListener("load", function() { | |
var mapId; | |
var c = getCookie("api"); | |
if (c != "") { | |
document.getElementById("apiKey").value = c; | |
} | |
document.getElementById("submit").addEventListener("click", function(){ | |
var scoreReqStr = "https://osu.ppy.sh/api/get_scores?k="; | |
mapId = document.getElementById("beatmapId").value.split("/"); | |
if (mapId.length != 5 || mapId[3] != "b") { | |
alert("Invalid beatmap url"); | |
return -1; | |
} | |
mapId = mapId[4].split("&")[0]; | |
scoreReqStr += document.getElementById("apiKey").value + "&b="; | |
scoreReqStr += mapId + "&u="; | |
scoreReqStr += document.getElementById("user").value; | |
var mapReqStr = "https://osu.ppy.sh/api/get_beatmaps?k="; | |
mapReqStr += document.getElementById("apiKey").value + "&b="; | |
mapReqStr += mapId; | |
var scoreReq = new XMLHttpRequest(); | |
var mapReq = new XMLHttpRequest(); | |
scoreReq.onreadystatechange = function() { | |
if (scoreReq.readyState == XMLHttpRequest.DONE) { | |
} | |
} | |
mapReq.onreadystatechange = function() { | |
if (mapReq.readyState == XMLHttpRequest.DONE) { | |
var mapData = JSON.parse(mapReq.responseText)[0]; | |
//console.log(mapData) | |
document.getElementById("mapName").textContent = mapData.title + " [" + mapData.version + "]"; | |
document.getElementById("totalCombo").textContent = " / " + mapData.max_combo; | |
} | |
} | |
scoreReq.open("GET", scoreReqStr, true); | |
$.get(scoreReqStr, function(d){ | |
var scoreData = JSON.parse(d)[0]; | |
//console.log(scoreData); | |
// accuracy formula: https://osu.ppy.sh/wiki/Accuracy | |
var countmiss = parseInt(scoreData.countmiss); | |
var count50 = parseInt(scoreData.count50); | |
var count100 = parseInt(scoreData.count100); | |
var count300 = parseInt(scoreData.count300); | |
var pointsOfHit = ((count50 * 50) + (count100 * 100) + (count300 * 300)) | |
var numOfHit = (countmiss + count50 + count100 + count300); | |
$("userName").text(scoreData.username); | |
$("date").text(scoreData.date); | |
$("mapRank").text(scoreData.rank); | |
$("score").text(parseInt(scoreData.score).toLocaleString()); | |
$("acc").text(parseFloat(((pointsOfHit / (numOfHit * 300)) * 100).toFixed(2)) + "%"); | |
$("maxCombo").text(scoreData.maxcombo); | |
$("pp").text(scoreData.pp); | |
}); | |
scoreReq.send(); | |
mapReq.open("GET", mapReqStr, true); | |
mapReq.send(); | |
setCookie("api", document.getElementById("apiKey").value, 14); | |
}); | |
// document.getElementById("downloadReplay").addEventListener("click", function(){ | |
// var replayReq = new XMLHttpRequest(); | |
// var replayReqStr = "https://osu.ppy.sh/api/get_replay?k="; | |
// replayReqStr += document.getElementById("apiKey").value + "&b="; | |
// replayReqStr += mapId + "&u="; | |
// replayReqStr += document.getElementById("user").value + "&m="; | |
// replayReqStr += "0" | |
// | |
// }); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>what the fuck am i doing</h1> | |
You'll need an api key which you can obtain <a href="https://osu.ppy.sh/p/api">here</a>. Name it whatever you want.<br> | |
<form id = "idkform" onsubmit="return false"> | |
Api Key: <input type="password" id = apiKey></input><br> | |
Beatmap link: <input id = beatmapId value = https://osu.ppy.sh/b/486513?m=0></input> | |
<span style="font-size: 12px">Example: https://osu.ppy.sh/b/123456</span><br> | |
User: <input id = user value = icyarctic></input><br> | |
<input id = "submit" type="submit" value="Submit"></input> | |
</form> | |
<br><br> | |
<div id = scoreData> | |
<b>Map:</b> <span id = mapName></span><br> | |
<b>User:</b> <span id = userName></span><br> | |
<b>Date:</b> <span id = date></span><br> | |
<b>Rank:</b> <span id = mapRank></span><br> | |
<b>Score:</b> <span id = score></span><br> | |
<b>Accuracy:</b> <span id = acc></span><br> | |
<b>Combo:</b> <span id = maxCombo></span><span id = totalCombo></span><br> | |
<b>PP:</b> <span id = pp></span> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment