Skip to content

Commit

Permalink
fix/breakdown-chart
Browse files Browse the repository at this point in the history
Fix some issues related to breakdown chart:
 - stats are available also on approved kata
 - chart is not injected correctly after using BACK browser button
  • Loading branch information
hobovsky committed Jun 8, 2022
1 parent 0d730b8 commit 6720eff
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions polyglot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Polyglot for Codewars
// @description User script which provides some extra functionalities to Codewars
// @version 1.13.20
// @version 1.13.20.1
// @downloadURL https://github.com/hobovsky/polyglot/releases/latest/download/polyglot.js
// @updateURL https://github.com/hobovsky/polyglot/releases/latest/download/polyglot.js
// @match https://www.codewars.com/*
Expand Down Expand Up @@ -365,8 +365,10 @@ function buildLanguagesLeaderboardTab() {

function addRankAssessmentBreakdown(breakdown, elem) {

let canvas = '<tr style="display:none" id="glotBreakdownRow"><td colspan=2><canvas id="glotChartBreakdown"/></td></tr>';
jQuery(elem).parent().after(canvas);
if(!jQuery('#glotBreakdownRow').length) {
let canvas = '<tr style="display:none" id="glotBreakdownRow"><td colspan=2><canvas id="glotChartBreakdown"/></td></tr>';
jQuery(elem).parent().after(canvas);
}

let allRanks = {};
for(let b of breakdown) {
Expand Down Expand Up @@ -434,8 +436,11 @@ function addRankAssessmentsUi(elem) {
let allCells = jQuery(elem).find('td');

let leftCell = jQuery(allCells[8]);
leftCell.append(' <a id="glotToggleBreakdown">(see breakdown)</a>');
jQuery('#glotToggleBreakdown').click(toggleRankAssessmentsBreakdown);

if(!jQuery('#glotToggleBreakdown').length) {
leftCell.append(' <a id="glotToggleBreakdown">(see breakdown)</a>');
jQuery('#glotToggleBreakdown').click(toggleRankAssessmentsBreakdown);
}

let kataId = getViewedKataId();
fetchRankAssessmentBreakdown(kataId, leftCell);
Expand Down Expand Up @@ -572,7 +577,7 @@ const leaderboardScrollView=function(){

const processRankAssessments=function(){
let elem = jQuery(this);
if(elem.text() !== 'Stats:' || !isBetaKata()) {
if(elem.text() !== 'Stats:') {
return;
}
addRankAssessmentsUi(elem);
Expand Down

0 comments on commit 6720eff

Please sign in to comment.