Sort JIRA comments.

Force JIRA comments to be sorted in the order you prefer.

  1. // ==UserScript==
  2. // @name Sort JIRA comments.
  3. // @namespace https://github.com/skehlet/jira-sort-comments-tampermonkey
  4. // @version 0.7
  5. // @description Force JIRA comments to be sorted in the order you prefer.
  6. // @author @skehlet (Steve Kehlet)
  7. // @contributor @saurabhere
  8. // @contributor @catholicon
  9. // @match https://jira.atlassian.com/browse/*
  10. // ... include more match statements here, including your private JIRA repos
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var desiredSortOrder = 'asc'; // change me to 'desc' if you prefer
  18.  
  19. // apparently sometimes $ isn't available and jQuery is there (e.g. issues.apache.org/jira)
  20. $ = $ || jQuery;
  21.  
  22. // some jira setups (e.g. issues.apache.org/jira) have sort toggle button as
  23. // class="icon icon-sort-down ajax-activity-content" OR class="icon icon-sort-up ajax-activity-content"
  24. // depending on the context. So, using those selectors too.
  25. $('.issue-activity-sort-link')
  26. .add($('.icon-sort-down.ajax-activity-content'))
  27. .add($('.icon-sort-up.ajax-activity-content'))
  28. .each(function () {
  29. var sortLink = $(this);
  30. // the link shows the order that will result if you click on it
  31. if (sortLink.attr('data-order') == desiredSortOrder || sortLink.attr('href').endsWith(desiredSortOrder)) {
  32. // use .issue-view if present (there's a sidebar and scrollable frame to the right), otherwise window
  33. var selector = $('.issue-view').length > 0 ? '.issue-view' : window;
  34. var scrollPos = $(selector).scrollTop();
  35. // scroll back to where we were after clicking
  36. $(selector).one('scroll', function () {
  37. $(selector).scrollTop(scrollPos);
  38. });
  39. sortLink.click();
  40. }
  41. });
  42. })();