Check Constraints

Add checkboxes to constraints of an AtCoder problem.

Fra 31.10.2021. Se den seneste versjonen.

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 or Violentmonkey 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!)

  1. // ==UserScript==
  2. // @name Check Constraints
  3. // @name:ja 制約をチェックする
  4. // @description Add checkboxes to constraints of an AtCoder problem.
  5. // @description:ja AtCoderの問題ページの制約にチェックボックスを追加します。
  6. // @version 1.0.0
  7. // @icon https://www.google.com/s2/favicons?domain=atcoder.jp
  8. // @author w0mbat
  9. // @match https://atcoder.jp/contests/*/tasks/*
  10. // @grant GM_addStyle
  11. // @namespace https://greatest.deepsurf.us/users/754798
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. console.log('😼<「制約をチェックする」を実行します。');
  18.  
  19. async function addStyle(src) {
  20. return new Promise((resolve) => {
  21. const link = document.createElement("link");
  22. link.rel = "stylesheet";
  23. link.href = src;
  24. document.getElementsByTagName("head")[0].appendChild(link);
  25. });
  26. }
  27. addStyle('https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css');
  28. addStyle('https://cdn.jsdelivr.net/npm/@mdi/font@6.4.95/css/materialdesignicons.min.css');
  29. GM_addStyle(`
  30. .pretty.p-icon .state .icon { top: calc(((100% - 1em) - 2px) / 3) !important }
  31. .pretty .state label:after,.pretty .state label:before { top: calc(((100% - 1em) - 2px) / 3) !important }
  32. `);
  33.  
  34. function* getConstraintsSections() {
  35. // <h3>制約</h3>を子要素に持つsectionを取得
  36. for (const section of document.getElementsByTagName('section')) {
  37. for (const child of section.children) {
  38. if (child.tagName.toLowerCase() !== 'h3') continue;
  39. const text = child.textContent;
  40. if (text === '制約' || text === 'Constraints') yield section;
  41. }
  42. }
  43. }
  44.  
  45. function createCheckBox() {
  46. const checkbox = document.createElement('input');
  47. checkbox.type = 'checkbox';
  48. return checkbox;
  49. }
  50.  
  51. /**
  52. * @param {HTMLLIElement} li
  53. */
  54. function insertCheckBox(li) {
  55. // https://lokesh-coder.github.io/pretty-checkbox/
  56. const div = document.createElement('div');
  57. div.className = 'pretty p-icon p-round p-pulse';
  58. div.appendChild(createCheckBox());
  59. const state = div.appendChild(document.createElement('div'));
  60. state.className = 'state p-success';
  61. const icon = state.appendChild(document.createElement('i'));
  62. icon.className = 'icon mdi mdi-check';
  63. const label = state.appendChild(document.createElement('label'));
  64. [...li.childNodes].forEach(e => label.appendChild(e));
  65. li.appendChild(div);
  66. li.style.listStyleType = 'none';
  67. }
  68.  
  69. for (const section of getConstraintsSections()) {
  70. const ul = [...section.getElementsByTagName('ul')].shift();
  71. if (ul) {
  72. ul.style.paddingLeft = '1em';
  73. [...ul.querySelectorAll('li')].forEach(li => insertCheckBox(li));
  74. }
  75. }
  76.  
  77. console.log('😼<「制約をチェックする」を実行しました。');
  78. })();