Sort JIRA comments in ascending order (oldest first).

Always sort JIRA comments ascending.

As of 2016-07-12. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Sort JIRA comments in ascending order (oldest first).
// @namespace    http://stevekehlet.com
// @version      0.3
// @description  Always sort JIRA comments ascending.
// @author       Steve Kehlet
// @match        https://jira.atlassian.com/browse/*
// ... include more match statements here, including your private JIRA repos
// @match        https://devtools.mirthcorp.com/jira/browse/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

	var desiredSortOrder = 'asc'; // change me to 'desc' if you prefer

    $('.issue-activity-sort-link').each(function () {
        var sortLink = $(this);
		// the link shows the order that will result if you click on it
        if (sortLink.attr('data-order') == desiredSortOrder) {
            // use .issue-view if present (there's a sidebar and scrollable frame to the right), otherwise window
            var selector = $('.issue-view').length > 0 ? '.issue-view' : window;
            var scrollPos = $(selector).scrollTop();
            // scroll back to where we were after clicking
            $(selector).one('scroll', function () {
                $(selector).scrollTop(scrollPos);
            });
            sortLink.click();
        }
    });
})();