AtCoder Sample Downloader

AtCoderのサンプルをダウンロードするボタンを追加

Version vom 05.05.2021. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         AtCoder Sample Downloader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  AtCoderのサンプルをダウンロードするボタンを追加
// @author       y-i
// @match        https://atcoder.jp/contests/*/tasks/*
// @grant        none
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js
// ==/UserScript==

(function() {
    'use strict';

    const problemName = location.href.split('/').pop();

    const titleElem = document.querySelector('.row > div > .h2');
    if (!titleElem) return;

    const dlBtn = document.createElement('a');
    dlBtn.classList.add('btn', 'btn-default', 'btn-sm');
    dlBtn.textContent = 'Sample DL';
    titleElem.appendChild(dlBtn);

    dlBtn.addEventListener('click', async e => {
        e.preventDefault();

        const samples = Array.from(document.querySelectorAll('[id^="pre-sample"]')).map(el => el.innerText);
        const n = samples.length / 2;

        const zip = new JSZip();

        for (let i = 0; i < n; ++i) {
            const sampleNum = (i - i % 2) / 2;
            const inOut = i % 2 ? 'out' : 'in';
            const filename = `sample-${sampleNum}.${inOut}`;

            zip.file(filename, samples[i]);
        }

        const content = await zip.generateAsync({type:"blob"});
        saveAs(content,`${problemName}.zip`);
    });
})();