Greasy Fork

Greasy Fork is available in English.

CF解题难度数据可视化

显示某人Codeforces每个难度过了多少题

当前为 2023-04-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         CF解题难度数据可视化
// @name:en      codeforces analytics 
// @namespace    https://codeforces.com/profile/tongwentao
// @version      1.0.0
// @description  显示某人Codeforces每个难度过了多少题
// @description:en Analyse Codeforces profiles
// @author       tongwentao
// @match        https://codeforces.com/profile/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function drawChart(res){
        var div='<div class="roundbox userActivityRoundBox borderTopRound borderBottomRound" id="twtschart" style="height:400px;"></div>';
        document.getElementById('pageContent').insertAdjacentHTML('beforeend',div);

        var chartDom = document.getElementById('twtschart');
        var myChart = echarts.init(chartDom);
        var option;

        var xData=[];
        var yData=[];
        xData=Object.keys(res);
        for(var key in xData){
            yData.push(res[xData[key]]);
        }
        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'shadow'
                }
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis: [
                {
                  type: 'category',
                  data: xData,
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis: [
                {
                  type: 'value'
                }
              ],
              series: [
                {
                  name: 'solved',
                  type: 'bar',
                  barWidth: '60%',
                  data: yData
                }
              ]
        };

        option && myChart.setOption(option);
    }

    var pathname = window.location.pathname;
    var handle = pathname.substring(pathname.lastIndexOf('/') + 1, pathname.length);
    var httpRequest = new XMLHttpRequest();
        httpRequest.open('GET', 'https://codeforces.com/api/user.status?handle='+handle, true);
        httpRequest.send();
        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                var json=JSON.parse(httpRequest.responseText);
                var result=[];
                result=json.result;;
                var res={};
                for(var key in result){
                    if(result[key].verdict==="OK"){
                        var rating=result[key].problem.rating;
                        if(rating in res)
                            res[rating]++;
                        else
                            res[rating]=1;
                    }
                }
                console.log(res);
                drawChart(res);
            }
        };


})();