atcoder-virtual-quick-vst

AtCoderバーチャル参加ページの開始時刻入力の簡略化。

As of 2022-11-20. See the latest version.

  1. // ==UserScript==
  2. // @name atcoder-virtual-quick-vst
  3. // @namespace https://github.com/ilplrr
  4. // @version 1.0
  5. // @description AtCoderバーチャル参加ページの開始時刻入力の簡略化。
  6. // @author ilplrr
  7. // @match https://atcoder.jp/contests/*/virtual
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const vstInputTag = document.querySelector('#vst-tmp');
  16. if (!vstInputTag) return;
  17.  
  18. const div = document.createElement('div');
  19. div.style.textAlign = 'center';
  20. div.style.marginBottom = '15px';
  21. document.querySelector('#form-register').insertBefore(div, document.querySelectorAll('.form-group')[1]);
  22.  
  23. const createBtn = (text, sec) => {
  24. const btn = document.createElement('input');
  25. btn.type = 'button';
  26. btn.value = text;
  27. btn.style.marginRight = '1rem';
  28. btn.addEventListener('click',() => {
  29. const vst = new Date();
  30. vst.setSeconds(vst.getSeconds() + sec);
  31. let s = '';
  32. s += [vst.getFullYear(), vst.getMonth()+1, vst.getDate()].map((x) => x.toString().padStart(2, '0')).join('-'); // yyyy-mm-dd
  33. s += ' ';
  34. s += [vst.getHours(), vst.getMinutes(), vst.getSeconds()].map((x) => x.toString().padStart(2, '0')).join(':'); // hh:mm:ss
  35. vstInputTag.value = s;
  36. });
  37. return btn;
  38. };
  39.  
  40. div.appendChild(createBtn('10秒後', 10));
  41. div.appendChild(createBtn('1分後', 1*60));
  42. div.appendChild(createBtn('3分後', 3*60));
  43. div.appendChild(createBtn('5分後', 5*60));
  44. })();