AtCoder Show Result

check and show AC

目前為 2025-01-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @license      MIT
// @name         AtCoder Show Result
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  check and show AC
// @author       twil3akine
// @match        https://atcoder.jp/contests/*/tasks
// @grant        none
// ==/UserScript==

'use strict'

const GREEN = "rgba(92,184,92,0.75)";
const YELLOW = "rgba(240,173,78,0.75)";

const getResult = async (url) => {
    const formatInfo = (cells) => {
        const name = cells[1].querySelector("a").textContent.trim().split(" ")[0];
        const lang = cells[3].querySelector("a").textContent.trim();
        const result = cells[6].querySelector("span").textContent.trim();

        return {
            name: name,
            lang: lang,
            result: result,
        }
    }

    let count = 0
    let contents = [];

    while (true) {
        try {
            count++;

            const response = await fetch(`${url}?page=${count}`);
            const text = await response.text();
            const parser = new DOMParser();
            const doc = parser.parseFromString(text, 'text/html');

            if (doc.querySelector(".panel-body")) {
                return contents;
            }

            const trs = doc.querySelectorAll("tr");

            trs.forEach((tr, idx) => {
                if (idx === 0) return ;

                let cells = tr.querySelectorAll("td");

                contents.push(formatInfo(cells));
            });
        } catch (e) {
            console.error(`Error fetching the page: ${e}`);
            return [];
        }
    }
}

const getQuestions = () => {
    const questions = [""];
    const trs = document.querySelectorAll("tr");
    trs.forEach((tr, idx) => {
        if (idx === 0) return;
        let questName = tr.querySelector("td").querySelector("a").textContent.trim();
        questions.push(questName);
    })
    return questions;
}

const adaptResult = (questions, results) => {
    const trs = document.querySelectorAll("tr");
    results.reverse().forEach(result => {
        const targetElement = trs[questions.indexOf(result.name)];
        targetElement.style.backgroundColor = (result.result === "AC") ? GREEN : YELLOW;
        targetElement.style.filter = "brightness(1.25)";
    })
}

const app = async () => {
    const currentURL = window.location.href;
    const fetchPage = currentURL.replace("tasks", "submissions/me");
    const results = await getResult(fetchPage);
    const questions = getQuestions(currentURL);

    adaptResult(questions, results);
}

app();