AtCoder Submisson Timer

AtCoderの問題画面にタイマーをセットして、指定時間後にコードを提出します。

2022-09-20 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name            AtCoder Submisson Timer
// @name:ja         AtCoder Submisson Timer
// @namespace       https://github.com/Coki628/ac-submisson-timer
// @version         1.0.0
// @description     AtCoderの問題画面にタイマーをセットして、指定時間後にコードを提出します。
// @description:ja  AtCoderの問題画面にタイマーをセットして、指定時間後にコードを提出します。
// @author          Coki628
// @license         MIT
// @match           https://atcoder.jp/contests/*/tasks/*
// ==/UserScript==

(function() {
    'use strict';

    $('#submit').after(`
        <button style="margin-left: 5px;" type="button" class="btn btn-secondary" id="ac-sub-timer-btn" data-toggle="modal" data-target="#ac-sub-timer-modal">
            Submisson Timer
        </button>
    `);
    $('#ac-sub-timer-btn').after(`
        <div class="modal fade" id="ac-sub-timer-modal" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span>×</span></button>
                        <h4 class="modal-title">AtCoder Submisson Timer</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <div>
                                <input style="width: 80px; display: inline-block; margin-left: 20px;" type="number" class="form-control" id="ac-sub-timer-value"> 分後に提出!
                            </div>
                            <div style="margin-top: 10px; margin-left: 20px;" id="ac-sub-timer-info-text">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button id="ac-sub-timer-set" type="button" class="btn btn-primary">セットする</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">閉じる</button>
                    </div>
                </div>
            </div>
        </div>
    `);

    let timerId = 0;
    $('#ac-sub-timer-set').on('click', function() {
        if (timerId > 0) {
            clearTimeout(timerId);
            timerId = 0;
            // console.log('timer cleared');
            $('#ac-sub-timer-info-text').text('タイマーをキャンセルしました。');
        }
        const min = $('#ac-sub-timer-value').val();
        if (min && min > 0) {
            const millisec = min * 60 * 1000;
            timerId = setTimeout(() => {
                $('#submit').trigger('click');
            }, millisec);
            // console.log('timer set');
            $('#ac-sub-timer-info-text').html(`タイマーを${min}分後にセットしました。<br>${min}分後にコードが提出されます。`);
        }
    });
})();