Created
May 14, 2024 05:56
-
-
Save sempr/cf228da1bbb9bea5dcd8e8d12744e808 to your computer and use it in GitHub Desktop.
Codeforces Data Donwloader
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 Codeforces Data Donwloader | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-05-14 | |
// @description Download Script For Codeforces | |
// @author Sempr | |
// @match https://codeforces.com/contest/*/problems | |
// @icon https://aowuucdn.oss-accelerate.aliyuncs.com/codeforces.png | |
// @grant GM_addStyle | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
var button = document.createElement('button'); | |
button.className = 'custom-button'; // Assigning a class to the button | |
button.innerHTML = 'Download samples'; | |
GM_addStyle(` .custom-button { position: fixed; top: 20px; right: 20px; background-color: #4CAF50; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 10px; } `); | |
const regex = /contest\/(\d+)\/problems/; | |
const match = window.location.href.match(regex); | |
const contestNumber = match ? match[1] : "codeforces"; | |
button.addEventListener('click', function () { | |
var zip = new JSZip(); | |
document.querySelectorAll("div.problem-frames>div").forEach( | |
e => { | |
let problem_num = e.querySelector(".title").innerText.split(".")[0].toLowerCase(); | |
let input = e.querySelectorAll(".input>pre").values().map(e => e.innerText).toArray(); | |
let output = e.querySelectorAll(".output>pre").values().map(e => e.innerText).toArray(); | |
for (let i = 0; i < input.length; i++) { | |
let idx=i+1; | |
let prefix = contestNumber + "/" + problem_num + "/"; | |
zip.file(prefix + "in" + idx + ".txt", input[i]); | |
zip.file(prefix + "ans" + idx + ".txt", output[i]); | |
} | |
} | |
); | |
zip.generateAsync({ type: "blob" }).then((content) => saveAs(content, contestNumber + ".zip")); | |
}); | |
document.body.appendChild(button); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Click here or the top left "Raw" button to install this script if you have Tampermonkey installed.