AtCoder Profile2Ranking Link

link the profile page to the ranking of country/region, birth year, and affiliation

目前為 2021-05-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AtCoder Profile2Ranking Link
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  link the profile page to the ranking of country/region, birth year, and affiliation
// @author       sotanishy
// @match        https://atcoder.jp/users/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let table = document.getElementsByClassName('dl-table')[0];
    let tbody = table.getElementsByTagName('tbody')[0];
    let tr = tbody.getElementsByTagName('tr');
    const baseUrl = 'https://atcoder.jp/ranking';

    for (let i = 0; i < tr.length; i++) {
        let head = tr[i].getElementsByTagName('th')[0].textContent;
        let td = tr[i].getElementsByTagName('td')[0];
        if (head == '国と地域' || head == 'Country/Region') {
            let img = td.getElementsByTagName('img')[0];
            let country = img.src.split('/')[5].split('.')[0];
            let a = document.createElement('a');
            a.textContent = td.textContent;
            td.textContent = '';
            a.href = `${baseUrl}?f.Country=${country}`;
            td.appendChild(img);
            td.appendChild(a);
        }
        if (head == '誕生年' || head == 'Birth Year') {
            let birthyear = td.textContent;
            let a = document.createElement('a');
            a.textContent = birthyear;
            td.textContent = '';
            a.href = `${baseUrl}?f.BirthYearLowerBound=${birthyear}&f.BirthYearUpperBound=${birthyear}`;
            td.appendChild(a);
        }
        if (head == '所属' || head == 'Affiliation') {
            let affiliation = td.textContent;
            let a = document.createElement('a');
            a.textContent = affiliation;
            td.textContent = '';
            a.href = `${baseUrl}?f.Affiliation=${affiliation.replace(' ', '+')}`;
            td.appendChild(a);
        }
    }
})();