mariotatis / Points for Jira

// ==UserScript==
// @name           Points for Jira
// @author         mariotatis
// @namespace      https://openuserjs.org/users/mariotatis/scripts
// @description    Points for Jira cumulated story points and shows total points in each column
// @icon           https://www.mariotatis.com/wp-content/uploads/2020/05/favicon-32x32-1.png
// @copyright      2020+, mariotatis.com
// @version        2.0.4
// @license        MIT
// @grant          none
// @include        /^https?:\/\/.*atlassian.*
// ==/UserScript==

(function() {
    'use strict';

    function setColumnPoints(){
       var totalPoints = [];
       jQuery('.ghx-swimlane').each(function(index, swimlane){
            jQuery(swimlane).find('.ghx-columns li').each(function(index, column) {
                var points = 0;
                jQuery(column).find('[data-tooltip^="Story Points:"] > span, .ghx-estimate').each(function(index) {
                    jQuery(this).addClass('aui-badge');
                    var point = parseFloat(jQuery(this).text());
                    if(!isNaN(parseFloat(point)))
                        points += point;
                });
                totalPoints[index] = totalPoints[index] === undefined ? points : totalPoints[index] + points;
            })
        })
        $('.ghx-column-header-flex').find('.ghx-qty').each(function(index) {
            jQuery("#ghx-estimate"+index+1).remove();
            jQuery(this).after('<aui-badge class="ghx-estimate f-estimate" style="margin-left: 4px;" id="ghx-estimate'+index+1+'">'+ totalPoints[index] +'</aui-badge>');
        })
    }

    setInterval(() => {
        setColumnPoints();
    }, 1000);
})();