CF Hide Test Number

Hide “on test X” suffix in Codeforces verdicts

// ==UserScript==
// @name         CF Hide Test Number
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hide “on test X” suffix in Codeforces verdicts
// @author       SanguineChameleon
// @match        https://codeforces.com/*
// @grant        unsafeWindow
// @grant        GM_addStyle
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    GM_addStyle(`
span[class='verdict-format-judged'] {
    display: none !important;
}
td[class^='time-consumed-cell'] {
    font-size: 0px !important;
}
td[class^='memory-consumed-cell'] {
    font-size: 0px !important;
}
`)
})();

(function() {
    'use strict';

    const css = `
.verdict-format-judged,
.diagnosticsHint {
  display: none !important;
}`;
    if (typeof GM_addStyle === 'function') {
        GM_addStyle(css);
    } else {
        const s = document.createElement('style');
        s.textContent = css;
        (document.head || document.documentElement).appendChild(s);
    }

    const pluckRE = / on (pre)?test ?\d*$/;
    function pluck(s) {
        return s.replace(pluckRE, '');
    }

    const CF = (unsafeWindow || window).Codeforces;
    if (CF && CF.showMessage) {
        const _old = CF.showMessage;
        CF.showMessage = msg => _old(pluck(msg));
    }

    function stripNode(el) {
        try {
            const txt = el.childNodes[0];
            txt.nodeValue = pluck(txt.nodeValue);
        } catch {}
    }

    document.addEventListener('DOMContentLoaded', () => {
        document.querySelectorAll('.verdict-rejected span, .verdict-waiting span')
                .forEach(stripNode);

        const catcher = (unsafeWindow || window).submissionsEventCatcher;
        if (catcher && catcher.subscribe) {
            const channel = catcher.channels[0];
            catcher.subscribe(channel, data => {
                if (data.t === 's') {
                    const sel = `[data-a='${data.d[0]}'] .status-verdict-cell span`;
                    const el = document.querySelector(sel);
                    if (el) stripNode(el);
                }
            });
        }
    });
})();