View All Editorials

View all editorials of the AtCoder contest in one page.

当前为 2022-10-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name View All Editorials
  3. // @name:ja 解説ぜんぶ見る
  4. // @description View all editorials of the AtCoder contest in one page.
  5. // @description:ja AtCoderコンテストの解説ページに、すべての問題の解説をまとめて表示します。
  6. // @version 1.3.0
  7. // @icon https://www.google.com/s2/favicons?domain=atcoder.jp
  8. // @match https://atcoder.jp/contests/*/editorial
  9. // @match https://atcoder.jp/contests/*/editorial?*
  10. // @grant GM_addStyle
  11. // @namespace https://gitlab.com/w0mbat/user-scripts
  12. // @author w0mbat
  13. // ==/UserScript==
  14.  
  15. (async function () {
  16. 'use strict';
  17. console.log(`🐻 "View All Editorials" start execution. 🐻`)
  18.  
  19. async function addScript(src) {
  20. return new Promise((resolve) => {
  21. const script = document.createElement("script");
  22. script.type = "text/javascript";
  23. script.src = src;
  24. script.onload = resolve;
  25. document.getElementsByTagName("head")[0].appendChild(script);
  26. });
  27. }
  28.  
  29. async function addStyleSheet(src) {
  30. return new Promise((resolve) => {
  31. const link = document.createElement("link");
  32. link.rel = "stylesheet";
  33. link.href = src;
  34. link.onload = resolve;
  35. document.getElementsByTagName("head")[0].appendChild(link);
  36. });
  37. }
  38.  
  39. async function loadKaTex() {
  40. await addStyleSheet("https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/katex.min.css");
  41. await addScript("https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/katex.min.js");
  42. await addScript("https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/contrib/auto-render.min.js");
  43. var kaTexOptions = {
  44. delimiters: [
  45. { left: "$$", right: "$$", display: true },
  46. { left: "$", right: "$", display: false },
  47. { left: "\\(", right: "\\)", display: false },
  48. { left: "\\[", right: "\\]", display: true }
  49. ],
  50. ignoredTags: ["script", "noscript", "style", "textarea", "code", "option"],
  51. ignoredClasses: ["prettyprint", "source-code-for-copy"],
  52. throwOnError: false
  53. };
  54. renderMathInElement(document.body, kaTexOptions);
  55. }
  56.  
  57. async function loadMathJax() {
  58. await addScript("https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML");
  59. MathJax.Hub.Config({ messageStyle: "none", tex2jax: { skipTags: ["script", "noscript", "style", "textarea", "code"], inlineMath: [['$', '$'], ['\\(', '\\)']] } });
  60. }
  61.  
  62. async function loadPrettifier() {
  63. await addScript("https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js");
  64. }
  65.  
  66. async function getEditorial(link) {
  67. return new Promise((resolve) => {
  68. const xhr = new XMLHttpRequest()
  69. xhr.responseType = "document";
  70. xhr.onload = (response) => {
  71. const dom = response.target.responseXML;
  72. const editorialDom = dom.querySelector("#main-container > div.row > div:nth-child(2) > div:nth-of-type(1)");
  73. editorialDom && link.parentNode.appendChild(editorialDom);
  74. resolve();
  75. }
  76. xhr.open("GET", link.href);
  77. xhr.send();
  78. });
  79. }
  80.  
  81. async function getAllEditorials() {
  82. return Promise.all(Array.prototype.filter.call(document.getElementsByTagName('a'), e => e.href.match(/\/editorial\//))
  83. .map(e => getEditorial(e)));
  84. }
  85.  
  86. GM_addStyle("pre code { tab-size: 4; }");
  87. await getAllEditorials();
  88. // await loadMathJax();
  89. await loadKaTex();
  90. await loadPrettifier();
  91.  
  92. console.log(`🐻 "View All Editorials" end execution. 🐻`)
  93. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址