AtCoder Beautiful Code View

AtCoderの提出コードをMonaco Editorを使用した表示にします

Verze ze dne 01. 05. 2022. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name AtCoder Beautiful Code View
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description AtCoderの提出コードをMonaco Editorを使用した表示にします
  6. // @author Chippppp
  7. // @license MIT
  8. // @match https://atcoder.jp/contests/*/submissions/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. "use strict";
  13.  
  14. (function() {
  15. // Monaco Editor in cdnjs
  16. // Copyright (c) 2016 - present Microsoft Corporation
  17. let script = document.createElement("script");
  18. script.src = "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js";
  19. document.head.prepend(script);
  20.  
  21. let header = document.createElement("script");
  22. header.innerHTML = `
  23. document.getElementsByClassName("linenums")[0].style.display = "none";
  24. document.getElementsByClassName("btn-text toggle-btn-text source-code-expand-btn")[0].style.display = "none";
  25. document.getElementsByClassName("btn-copy btn-pre")[0].style.zIndex = "1";
  26. document.getElementsByClassName("btn-copy btn-pre")[0].style.borderRadius = "0";
  27. document.getElementsByClassName("btn-copy btn-pre")[1].style.zIndex = "1";
  28. document.getElementsByClassName("btn-copy btn-pre")[1].style.borderRadius = "0";
  29. `
  30. document.head.prepend(header);
  31.  
  32. let div = document.createElement("div");
  33. div.style.height = "500px";
  34. div.style.marginTop = "10px";
  35. div.style.marginBottom = "30px";
  36. document.getElementById("submission-code").after(div);
  37.  
  38. let arr = new Array;
  39. for (let i = 0; i < 10; ++i) {
  40. arr.push(document.getElementsByClassName("L" + i.toString()));
  41. }
  42. let str = ""
  43. for (let idx = 0; ; ++idx) {
  44. if (Math.floor(idx / 10) < arr[idx % 10].length) {
  45. str += arr[idx % 10][Math.floor(idx / 10)].innerText;
  46. str += "\n";
  47. } else break;
  48. }
  49.  
  50. let lang = document.getElementsByClassName("text-center")[3].innerText;
  51. lang = lang.slice(0, lang.indexOf(" ")).toLocaleLowerCase();
  52. if (lang.startsWith("pypy")) lang = "python";
  53. else if (lang == "c++") lang = "cpp";
  54.  
  55. script.onload = function() {
  56. require.config({ paths: { "vs": "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs" } });
  57.  
  58. require(["vs/editor/editor.main"], function() {
  59. monaco.editor.create(div, {
  60. value: str,
  61. language: lang,
  62. theme: "vs-dark",
  63. readOnly: true,
  64. lineHeight: 21,
  65. });
  66. document.getElementsByClassName("monaco-editor")[0].style.paddingTop = "20px";
  67. });
  68. };
  69. })();