ac-register-checker

AtCoder における企業コンテストの登録フォームにて、日本在住になっていない場合に警告を表示します。

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

You will need to install an extension such as Tampermonkey 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.

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

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

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        ac-register-checker
// @namespace   https://su8ru.dev
// @version     0.1.0
// @description AtCoder における企業コンテストの登録フォームにて、日本在住になっていない場合に警告を表示します。
// @author      subaru <[email protected]>
// @supportURL  https://twitter.com/su8ru_
// @license     MIT
// @match       https://atcoder.jp/contests/*/register
// ==/UserScript==

(() => {
  'use strict';
  const registerForm = document.forms[1];
  const insertAlert = () => {
    const alertHtml = (n) => `<div id="ac-register-checker-alert-${n}" class="alert alert-danger" role="alert"><p style="font-weight:bold;">「日本国内在住か?」が「はい」になっていません!</p></div>`;
    registerForm.querySelector('button').insertAdjacentHTML('beforebegin', alertHtml(1));
    document.querySelector('.form-group').insertAdjacentHTML('afterend', alertHtml(2));
    registerForm.querySelector('button').classList.replace('btn-primary', 'btn-danger');
  }
  const removeAlert = () => {
    document.querySelector('#ac-register-checker-alert-1').remove();
    document.querySelector('#ac-register-checker-alert-2').remove();
    registerForm.querySelector('button').classList.replace('btn-danger', 'btn-primary')
  }
  const onFormChange = (e) => {
    const value = registerForm['日本国内在住か?'].value;
    if (value === 'No') insertAlert();
    else removeAlert();
  };
  registerForm.addEventListener('change', onFormChange);
  onFormChange();
})();