Skip to content

Instantly share code, notes, and snippets.

@ZOI-dayo
Created May 29, 2023 15:36
Show Gist options
  • Save ZOI-dayo/36ba2b58ee3031232121a3d92422043f to your computer and use it in GitHub Desktop.
Save ZOI-dayo/36ba2b58ee3031232121a3d92422043f to your computer and use it in GitHub Desktop.
AtCoder未記入チェッカー
// ==UserScript==
// @name AtCoder未記入チェッカー
// @namespace https://github.com/ZOI-dayo
// @version 0.1
// @description AtCoderの参加登録メニューで未記入のものがあれば赤く表示します
// @author ZOI_dayo
// @supportURL https://twitter.com/ZOI_dayo
// @license MIT
// @match https://atcoder.jp/contests/*/register
// @icon https://www.google.com/s2/favicons?sz=64&domain=atcoder.jp
// ==/UserScript==
(() =>{
'use strict';
const warn = (elem) => {
elem.style.backgroundColor = "#FF000044"
}
const unwarn = (elem) => {
elem.style.backgroundColor = "unset"
}
const onChange = () => {
for(let elem of document.querySelectorAll('.form-group')) {
console.log(elem)
const inputs = elem.querySelectorAll('input');
if(inputs.length == 0) continue;
console.log(inputs[0].getAttribute('type'))
console.log(elem.querySelector('input[type="radio"][checked]'))
const type = inputs[0].getAttribute('type')
if(type == 'radio') {
// console.log(inputs[0].getAttribute('name'))
const checked = Array.from(inputs).find(i => i.checked)
if(checked.value == "No") warn(elem)
else unwarn(elem)
} else if(type == 'text') {
const value = inputs[0].value;
if(value == "") warn(elem)
else unwarn(elem)
} else if(type == 'checkbox') {
if(!Array.from(inputs).some(i => i.checked)) warn(elem)
else unwarn(elem)
}
}
}
document.forms[1].addEventListener('change', onChange);
onChange();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment