theonedemon / Netpeak Redmine Usability Sp Left

// ==UserScript==
// @name         Netpeak Redmine Usability Sp Left
// @namespace    https://openuserjs.org/users/theonedemon
// @version      0.2
// @description  try to take over the world!
// @author       nomedeno.netpeak@gmail.com
// @include        https://redmine.netpeak.net/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  var sp_class = '.cf_24';
  var progress_class = '.progress';

  if (jQuery(sp_class).length && jQuery(progress_class).length) {
    jQuery(progress_class).each(function (i, el) {
      var progress_val = jQuery(el).attr('class').match(/progress-(\d+)/)[1];
      progress_val = parseInt(progress_val) || 0;
      var sp_el = jQuery(el).closest('tr').find(sp_class);
      var sp_val = parseFloat(jQuery(sp_el).html()) || 0;
      var sp_left = (100 - progress_val) / 100 * sp_val;
      //sp_left = Math.round(sp_left);
      sp_left = sp_left.toFixed(2);

      var sp_left_block = jQuery('<div>').html(jQuery('<p>').html('(' + sp_left + ')'));

      jQuery(sp_el).closest('td').append(sp_left_block.html());
    });
  }
})();