ac-writers script

ちょっと便利

Ekde 2018/07/02. Vidu La ĝisdata versio.

// ==UserScript==
// @name         ac-writers script
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  ちょっと便利
// @author       ikd
// @match        https://beta.atcoder.jp/users/*/history
// @grant        none

// @require      https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js
// ==/UserScript==

(function() {
    'use strict';


    const tab = document.getElementById('history');

    const thead = tab.querySelector('thead tr');
    const th = document.createElement('th');
    th.setAttribute('width', '15%');
    th.setAttribute('class', 'text-center sorting');
    // th.setAttribute('tabindex', '0');
    th.setAttribute('aria-controls', 'history');
    th.setAttribute('rowspan', '1');
    th.setAttribute('colspan', '1');
    th.setAttribute('aria-label', 'writer');
    th.textContent = 'writer';
    thead.appendChild(th);

    const tbody = tab.getElementsByTagName('tbody')[0];
    const rows = tbody.getElementsByTagName('tr');

    for (let i = 0; i < rows.length; i += 1) {
        const td = document.createElement('td');
        rows[i].appendChild(td);
    }

    axios.get('https://storage.googleapis.com/ac-writers-bucket/cid2writers.json')
        .then((results) => {
        for (let i = 0; i < rows.length; i += 1) {
            const href = rows[i].querySelector('td a').getAttribute('href');
            const contestid = href.replace(/\/contests\//, '');
            const writers = results.data[contestid];
            const td = rows[i].lastElementChild;
            // console.log(td);
            if (Array.isArray(writers)) {
                for (let j = 0; j < writers.length; j += 1) {
                    const a = document.createElement('a');
                    a.setAttribute('href', '/user/' + writers[j].name);
                    a.setAttribute('class', 'username'); // いる?
                    const span = document.createElement('span');
                    span.textContent = writers[j].name;
                    span.style.color = writers[j].color;
                    a.appendChild(span);
                    td.appendChild(a);
                    if (j + 1 < writers.length) {
                        const comma = document.createElement('span');
                        comma.textContent = ', ';
                        td.appendChild(comma);
                    }
                }
            } else {

            }
            // rows[i].appendChild(td);
        }
    }).catch((err) => {
        console.error(err);
    });

})();