AtCoder Show Me Score Table

コンテスト名を配点に置き換えちゃうスクリプト

目前為 2024-10-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        AtCoder Show Me Score Table
// @namespace   https://atcoder.jp/
// @version     0.3
// @description コンテスト名を配点に置き換えちゃうスクリプト
// @author      hayatroid
// @license     MIT
// @match       https://atcoder.jp/contests/*
// @exclude     https://atcoder.jp/contests/*/json
// ==/UserScript==

(async () => {
    // キャッシュを読み込む
    const cache = localStorage.getItem(`score_table_${contestScreenName}`);
    if (cache) {
        document.querySelector(".contest-title").textContent = cache;
        return;
    }

    // 配点 (e.g. "100 - 200 - 300 - 400 - 500 - 600") の取得
    const res = await fetch(`https://atcoder.jp/contests/${contestScreenName}`)
    .then((response) => {
        if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
        return response.text();
    })
    .then((text) => {
        const parser = new DOMParser();
        const doc = parser.parseFromString(text, "text/html");
        // 配点の書かれた table の取得
        const table = [...doc.querySelectorAll("#contest-statement > .lang > .lang-ja table")]
        .filter((element) => {
            const th = [...element.querySelectorAll("thead > tr > th")];
            return th.length === 2 && th[0].textContent === "問題" && th[1].textContent === "点数";
        });
        if (table.length !== 1) throw new Error("Scoreboard cannot be found.");
        return table[0];
    })
    .then((table) => {
        // table から配点を取り出し,ハイフンでつなぐ
        const res = [...table.querySelectorAll("tbody > tr > td")]
        .filter((element, index) => {
            return index % 2 === 1;
        })
        .map((element) => {
            return element.textContent;
        })
        .join(" - ");
        return res;
    });

    // キャッシュする
    localStorage.setItem(`score_table_${contestScreenName}`, res);

    // コンテスト名を配点に置き換える
    document.querySelector(".contest-title").textContent = res;
})();