Last active
December 7, 2022 15:50
-
-
Save NovaSagittarii/3f18edf329a3931d084a74ff1b77e5da to your computer and use it in GitHub Desktop.
CodeForces submissions scraper (JS)
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
// Yoink all AC solution from the Standings page of codeforces, using JS to interact with the site | |
// Submissions are output as {contestantName}-{submissionId}.txt | |
/** HOW TO USE | |
* 1. Go to standings page - https://codeforces.com/group/----/contest/----/standings | |
* 2. Open JS console (three dots in top right -> [More Tools] -> [Developer Tools] -> [Console]) | |
* 3. Paste code snippet into JS console | |
* 4. [ALLOW] multiple file downloads | |
* 5. Hold [Enter] on your keyboard so the file is saved immediately once the prompt shows up (filename should be highlighted), there is likely to be many submissions | |
*/ | |
(async function(){ | |
for(const node of [...document.querySelectorAll(".cell-accepted,.cell-passed-system-test")]){ // .slice(12,16) | |
// console.log(node); | |
const authorUsername = node.parentNode.parentNode.querySelector(".contestant-cell").innerText; | |
node.parentNode.dispatchEvent(new MouseEvent("click", { | |
ctrlKey: true | |
})); | |
const sources = await new Promise(res => { | |
let int = setInterval(() => { | |
if(document.getElementsByClassName("showSource").length > 0){ | |
clearInterval(int); | |
res([...document.getElementsByClassName("showSource")]); | |
} | |
}, 100); | |
}); | |
const submissionId = sources[sources.length-1].innerText; | |
console.log(authorUsername, submissionId) | |
sources[sources.length-1].click(); | |
const lines = await new Promise(res => { | |
let int = setInterval(() => { | |
const query = document.getElementsByTagName("code"); | |
if(query.length >= 2){ | |
clearInterval(int); | |
res(query); | |
} | |
}, 100); | |
}); | |
// console.log(lines[1].innerText); | |
// console.log(lines[1].innerText.split('\r').slice(0,5).join('\r')); // consolelog code result to console | |
(function(data, filename, type){ // https://stackoverflow.com/a/30832210 | |
var file = new Blob([data], {type: type}); | |
var a = document.createElement("a"), | |
url = URL.createObjectURL(file); | |
a.href = url; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function() { | |
document.body.removeChild(a); | |
window.URL.revokeObjectURL(url); | |
}, 0); | |
})(lines[1].innerText, `${authorUsername}-${submissionId}.txt`, "text/plain"); | |
document.getElementsByClassName("close")[0].click(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sad news, this dies on AC submitted during a freeze for frozen standings. it still works otherwise though!