AtCoder Show Result

check and show AC

11.01.2025 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();