AtCoder-Submission-RadioButton

AtCoderで提出時ラジオボタンを生成します

  1. // ==UserScript==
  2. // @name AtCoder-Submission-RadioButton
  3. // @namespace https://github.com/penicillin0/
  4. // @version 0.1.2
  5. // @description AtCoderで提出時ラジオボタンを生成します
  6. // @author penicillin0
  7. // @license MIT
  8. // @homepage https://github.com/penicillin0/AtCoder-Submission-RadioButton#readme
  9. // @match https://atcoder.jp/contests/*/submit*
  10. // @supportURL https://twitter.com/penicillin0at
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. // 問題名を配列に
  16. const problem_names_Elements = document.getElementById('select-task').children;
  17.  
  18. //問題ごとにループ
  19. for (var i = 0; i < problem_names_Elements.length; i++) {
  20. const problem_name = problem_names_Elements[i].innerHTML
  21.  
  22. // ボタンの作成
  23. const button_txt = `<input type="radio" value="ボタン2" name="quiz" onclick="clickBtn(${i});" />${problem_name}<br>`
  24. // ボタンの挿入位置
  25. const button_place = document.querySelector('div.col-sm-12 span.error');
  26. // ボタンの挿入
  27. button_place.insertAdjacentHTML('beforebegin', button_txt);
  28. };
  29.  
  30. // scriptの作成
  31. const script_elem = document.createElement("script");
  32. // scriptの中身
  33. script_elem.innerText = `function clickBtn(index) {
  34. document.getElementById('select-task').selectedIndex = index;
  35. };`
  36. // buttonの下の挿入
  37. const button_place = document.querySelector('div.col-sm-12 span.error');
  38. button_place.appendChild(script_elem);
  39. })();