AtCoder Editorial Collector

View editorials of all problems in one page.

当前为 2020-11-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AtCoder Editorial Collector
  3. // @name:ja AtCoder Editorial Collector
  4. // @description View editorials of all problems in one page.
  5. // @description:ja 全問題の解説を1ページに表示します。
  6. // @version 1.2.1
  7. // @match https://atcoder.jp/contests/*/editorial
  8. // @match https://atcoder.jp/contests/*/editorial?*
  9. // @grant GM_addStyle
  10. // @namespace https://github.com/w0mbat-kyopro/user-scripts
  11. // @author w0mbat
  12. // ==/UserScript==
  13.  
  14. (async function () {
  15. 'use strict';
  16. console.log(`🐻 "AtCoder Editorial Collector" start execution. 🐻`)
  17.  
  18. async function addScript(src, onload = () => { }) {
  19. return new Promise((resolve) => {
  20. const script = document.createElement("script");
  21. script.type = "text/javascript";
  22. script.src = src;
  23. script.onload = () => { onload(); resolve(); };
  24. document.getElementsByTagName("head")[0].appendChild(script);
  25. });
  26. }
  27.  
  28. async function loadMathjax() {
  29. await addScript("https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML", () => {
  30. MathJax.Hub.Config({ messageStyle: "none", tex2jax: { skipTags: ["script", "noscript", "style", "textarea", "code"], inlineMath: [['$', '$'], ['\\(', '\\)']] } });
  31. });
  32. }
  33.  
  34. async function loadPrettifier() {
  35. await addScript("https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js");
  36. }
  37.  
  38. async function getEditorial(link) {
  39. return new Promise((resolve) => {
  40. const xhr = new XMLHttpRequest()
  41. xhr.responseType = "document";
  42. xhr.onload = (response) => {
  43. const dom = response.target.responseXML;
  44. const editorialDom = dom.querySelector("#main-container > div.row > div:nth-child(2) > div:nth-child(3)");
  45. editorialDom && link.parentNode.appendChild(editorialDom);
  46. resolve();
  47. }
  48. xhr.open("GET", link.href);
  49. xhr.send();
  50. });
  51. }
  52.  
  53. async function getAllEditorials() {
  54. return Promise.all(Array.prototype.filter.call(document.getElementsByTagName('a'), e => e.href.match(/\/editorial\//))
  55. .map(e => getEditorial(e)));
  56. }
  57.  
  58. GM_addStyle("pre code { tab-size: 4; }");
  59. await getAllEditorials();
  60. await loadMathjax();
  61. await loadPrettifier();
  62.  
  63. console.log(`🐻 "AtCoder Editorial Collector" end execution. 🐻`)
  64. })();

QingJ © 2025

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