AtCoder Show Result

check and show AC

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. // @license MIT
  3. // @name AtCoder Show Result
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.0.0
  6. // @description check and show AC
  7. // @author twil3akine
  8. // @match https://atcoder.jp/contests/*/tasks
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. 'use strict'
  13.  
  14. const GREEN = "rgba(92,184,92,0.75)";
  15. const YELLOW = "rgba(240,173,78,0.75)";
  16.  
  17. const getResult = async (url) => {
  18. const formatInfo = (cells) => {
  19. const name = cells[1].querySelector("a").textContent.trim().split(" ")[0];
  20. const lang = cells[3].querySelector("a").textContent.trim();
  21. const result = cells[6].querySelector("span").textContent.trim();
  22.  
  23. return {
  24. name: name,
  25. lang: lang,
  26. result: result,
  27. }
  28. }
  29.  
  30. let count = 0
  31. let contents = [];
  32.  
  33. while (true) {
  34. try {
  35. count++;
  36.  
  37. const response = await fetch(`${url}?page=${count}`);
  38. const text = await response.text();
  39. const parser = new DOMParser();
  40. const doc = parser.parseFromString(text, 'text/html');
  41.  
  42. if (doc.querySelector(".panel-body")) {
  43. return contents;
  44. }
  45.  
  46. const trs = doc.querySelectorAll("tr");
  47.  
  48. trs.forEach((tr, idx) => {
  49. if (idx === 0) return ;
  50.  
  51. let cells = tr.querySelectorAll("td");
  52.  
  53. contents.push(formatInfo(cells));
  54. });
  55. } catch (e) {
  56. console.error(`Error fetching the page: ${e}`);
  57. return [];
  58. }
  59. }
  60. }
  61.  
  62. const getQuestions = () => {
  63. const questions = [""];
  64. const trs = document.querySelectorAll("tr");
  65. trs.forEach((tr, idx) => {
  66. if (idx === 0) return;
  67. let questName = tr.querySelector("td").querySelector("a").textContent.trim();
  68. questions.push(questName);
  69. })
  70. return questions;
  71. }
  72.  
  73. const adaptResult = (questions, results) => {
  74. const trs = document.querySelectorAll("tr");
  75. results.reverse().forEach(result => {
  76. const targetElement = trs[questions.indexOf(result.name)];
  77. targetElement.style.backgroundColor = (result.result === "AC") ? GREEN : YELLOW;
  78. targetElement.style.filter = "brightness(1.25)";
  79. })
  80. }
  81.  
  82. const app = async () => {
  83. const currentURL = window.location.href;
  84. const fetchPage = currentURL.replace("tasks", "submissions/me");
  85. const results = await getResult(fetchPage);
  86. const questions = getQuestions(currentURL);
  87.  
  88. adaptResult(questions, results);
  89. }
  90.  
  91. app();