ac-register-checker

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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();
})();