// ==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/echarts@5.4.2/dist/echarts.min.js // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; function drawChart(res){ var 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); } }; })();