AtCoder for Large Display

サンプルなどを二列に並べます。

目前為 2022-01-25 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name AtCoder for Large Display
  3. // @namespace http://atcoder.jp/
  4. // @version 0.1
  5. // @description サンプルなどを二列に並べます。
  6. // @author magurofly
  7. // @match https://atcoder.jp/contests/*/tasks/*
  8. // @icon https://www.google.com/s2/favicons?domain=atcoder.jp
  9. // @grant unsafeWindow
  10. // @license CC0 1.0 Universal
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function hasHeadingMatching(e, pattern) {
  17. for (const heading of e.querySelectorAll("h1,h2,h3,h4,h5,h6")) {
  18. if (heading.textContent.match(pattern)) return true;
  19. }
  20. return false;
  21. }
  22.  
  23. function moveTo(container, elements) {
  24. for (const element of elements) {
  25. if (element.parentElement) element.parentElement.removeChild(element);
  26. container.appendChild(element);
  27. }
  28. }
  29.  
  30. for (const container of document.querySelectorAll(".lang>span")) {
  31. container.classList.add("row");
  32. const testcases = [];
  33. let inputStyle, outputStyle;
  34. for (const col of container.querySelectorAll(".part,.io-style")) {
  35. if (col.querySelector(".btn-copy")) {
  36. testcases.push(col);
  37. col.classList.add("col-md-6");
  38. } else if (hasHeadingMatching(col, /入力|Input/i)) {
  39. inputStyle = col;
  40. col.classList.add("col");
  41. } else if (hasHeadingMatching(col, /出力|Output/i)) {
  42. outputStyle = col;
  43. col.classList.add("col");
  44. } else {
  45. col.classList.add("col");
  46. }
  47. }
  48. if (inputStyle && outputStyle) {
  49. inputStyle.classList.remove("col");
  50. inputStyle.classList.add("col-xs-6");
  51. outputStyle.classList.remove("col");
  52. outputStyle.classList.add("col-xs-6");
  53. const row = document.createElement("div");
  54. row.className = "row";
  55. inputStyle.parentElement.appendChild(row);
  56. moveTo(row, [inputStyle, outputStyle]);
  57. }
  58. for (let i = 0; i < testcases.length; i += 2) {
  59. const input = testcases[i];
  60. const output = testcases[i + 1];
  61. const row = document.createElement("div");
  62. row.className = "row";
  63. input.parentElement.appendChild(row);
  64. moveTo(row, [input, output]);
  65. }
  66. }
  67. })();