Created
January 19, 2018 14:36
-
-
Save Element118/4d08b8fcef0331bf6f37c3c40d04bf0b 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
// ==UserScript== | |
// @name dunjudge time sorting | |
// @namespace dunjudgeTimeSort | |
// @version 1.0 | |
// @description Sorting submissions by time | |
// @author Element118 | |
// @match https://dunjudge.me/analysis/problems/*/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let xhttp = new XMLHttpRequest(); | |
let href = window.location.href.split("/"); | |
let problemID = href[href.length-2]; | |
let userID = document.getElementsByClassName("btn btn-default btn-flat")[0].href; | |
userID = userID.substring("https://dunjudge.me/users/".length, userID.length-1); | |
let subTable = (function() { | |
let pastSub = document.getElementsByClassName("box box-")[0]; | |
let box = document.createElement("div"); box.className = "box box-success"; | |
let header = document.createElement("div"); header.className = "box-header"; | |
let headerText = document.createElement("h3"); headerText.className = "box-title"; headerText.textContent = "Submissions by Time"; | |
header.appendChild(headerText); | |
box.appendChild(header); | |
let boxBody = document.createElement("div"); | |
// display: none; to hide | |
boxBody.className = "box-body no-padding scrollbar"; boxBody.style="height: 200px; overflow: auto; display: block;"; boxBody.id="ac_time_subbox"; | |
let boxTable = document.createElement("table"); | |
boxTable.className = "table table-bordered center table-hover"; boxTable.id = "ac_time_subs"; | |
boxTable.innerHTML = "<thead><tr><th>Rank</th><th>subID</th><th>User</th><th>Time</th><th>Max Time</th></tr></thead>"; | |
let boxTableBody = document.createElement("tbody"); | |
boxTable.appendChild(boxTableBody); | |
boxBody.appendChild(boxTable); | |
box.appendChild(boxBody); | |
pastSub.parentNode.insertBefore(box, pastSub); | |
return boxTableBody; | |
})(); | |
let addData = function(data) { | |
subTable.innerHTML += '<tr><td>'+data.rank+'</td><td><a href="/analysis/submissions/'+data.subID+'/">'+data.subID+'</a></td><td><a href="/users/'+data.userID+'/">'+data.userID+'</a></td><td>'+data.subTime+'</td><td>'+data.maxTime+'</td></tr>'; | |
}; | |
let submissions = []; | |
let currentSub = 1000000000; | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
let newData = JSON.parse(xhttp.responseText).moresub; | |
submissions = submissions.concat(newData); | |
if (newData.length > 0) { | |
currentSub = newData[newData.length-1].subID; | |
xhttp.open("GET", "https://dunjudge.me/ui/submissions_list.php?query_type=accepted&problemID="+problemID+"&botsub="+currentSub+"&lastupd=0", true); | |
xhttp.send(); | |
} else { | |
let hashTable = {}; // name -> subid, time | |
for (let i=0;i<submissions.length;i++) { | |
// <td><a href='/analysis/submissions/SUB_ID/'>SUB_ID</a></td><td><a href='/users/USER_ID/'>USER_ID</a></td><td>SUB_TIME</td><td>MAX_TIME</td> | |
let subID = submissions[i].subID; | |
let tokens = submissions[i].str.split("<td>"); // assuming <td> doesn't appear anywhere else | |
// 0: [empty string] | |
// 1: <a href='/analysis/submissions/SUB_ID/'>SUB_ID</a></td> | |
// 2: <a href='/users/USER_ID/'>USER_ID</a></td> | |
// 3: SUB_TIME</td> | |
// 4: MAX_TIME</td> | |
let userID = tokens[2].substring(tokens[2].indexOf(">")+1); // SUB_ID</a></td> | |
userID = userID.substring(0, userID.indexOf("<")); // SUB_ID | |
let subTime = tokens[3].substring(0, tokens[3].indexOf("<")); // SUB_TIME | |
let maxTime = +tokens[4].substring(0, tokens[4].indexOf("<")); // MAX_TIME | |
if (!hashTable[userID] || hashTable[userID].maxTime > maxTime) { | |
hashTable[userID] = { | |
subID: subID, | |
userID: userID, | |
subTime: subTime, | |
maxTime: maxTime, | |
rank: 0 | |
}; | |
} | |
} | |
let sortedSubs = []; | |
for (let i in hashTable) { | |
sortedSubs.push(hashTable[i]); | |
} | |
sortedSubs.sort(function(a, b) { | |
if (a.maxTime !== b.maxTime) return a.maxTime - b.maxTime; | |
return (+a.subID) - (+b.subID); | |
}); | |
let prevRank = 0, prevTime = -1, userPosition = 0; | |
for (let i=0;i<sortedSubs.length;i++) { | |
if (sortedSubs[i].maxTime > prevTime) { | |
prevRank = i+1; | |
prevTime = sortedSubs[i].maxTime; | |
} | |
sortedSubs[i].rank = prevRank; | |
// unused? | |
if (sortedSubs[i].userID == userID) { | |
userPosition = i; | |
} | |
addData(sortedSubs[i]); | |
} | |
} | |
} | |
}; | |
xhttp.open("GET", "https://dunjudge.me/ui/submissions_list.php?query_type=accepted&problemID="+problemID+"&botsub="+currentSub+"&lastupd=0", true); | |
xhttp.send(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment