Show all Jira 9 comments (and more), in chronological order

Clicks all 'show more' buttons, and (shift-)clicks 'oldest first'. Works on Jira 9.4.5. Inspired by https://greasyfork.org/scripts/432731 (no external dependencies).

  1. // ==UserScript==
  2. // @name Show all Jira 9 comments (and more), in chronological order
  3. // @namespace https://greasyfork.org/users/1047370
  4. // @description Clicks all 'show more' buttons, and (shift-)clicks 'oldest first'. Works on Jira 9.4.5. Inspired by https://greasyfork.org/scripts/432731 (no external dependencies).
  5. // @include https://jira.*
  6. // @include http://jira.*
  7. // @match https://jira.*
  8. // @match http://jira.*
  9. // @version 0.2
  10. // @author Marnix Klooster <marnix.klooster@gmail.com>
  11. // @copyright public domain
  12. // @license public domain
  13. // @homepage https://greasyfork.org/scripts/472161
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. // Configuration options
  18. // ---------------------
  19. const forceSortOrder = true; // whether or not to force the sort order at page load
  20. const useOldestFirstSorting = true; // if forcing sort order, whether to use 'oldest first' == 'asc'
  21. // END Configuration options
  22.  
  23. (function() {
  24. var theInterval = null;
  25. var warnedMultipleSortButtons = false;
  26. var clickedSortorderButton = false;
  27. var sortOrderInFinalState = false;
  28. var clickedShowmoreButton = null;
  29. var tabSwitchEventHandlerInstalled = false;
  30.  
  31. function start() {
  32. if (theInterval) {
  33. console.log(`SOMETHING WENT WRONG. Ignoring this call to start().`);
  34. return;
  35. }
  36.  
  37. theInterval = setInterval(function() {
  38. // make sure sort order is as desired (direction determined by useOldestFirstSorting)
  39. if (forceSortOrder && !sortOrderInFinalState) {
  40. var sortButtons = document.querySelectorAll('button#sort-button');
  41. if (sortButtons.length > 1) {
  42. if (!warnedMultipleSortButtons) {
  43. console.log(`WARN: ${b.length} sort buttons found, will not try to change sort order`);
  44. warnedMultipleSortButtons = true;
  45. }
  46. } else if (sortButtons.length == 0) {
  47. // retry later
  48. } else {
  49. if (sortButtons[0].getAttribute('data-order') == (useOldestFirstSorting ? 'asc': 'desc')) {
  50. if (!clickedSortorderButton) {
  51. console.log(`Clicking the sort order button to switch to '${sortButtons[0].getAttribute('data-order')}'...`);
  52. sortButtons[0].click();
  53. clickedSortorderButton = true;
  54. return;
  55. }
  56. console.log(`waiting for sort order change`);
  57. // don't do anything else until we know the sort order is as we want it to be
  58. return;
  59. }
  60. }
  61. }
  62.  
  63. // click any 'show more' button in sight...
  64. var showmoreButtons = document.querySelectorAll('button.show-more-tab-items');
  65. if (clickedShowmoreButton) {
  66. for (var b of showmoreButtons) {
  67. if (b.isEqualNode(clickedShowmoreButton)) {
  68. console.log(`waiting for last "show more..." click to have been handled`);
  69. return;
  70. }
  71. }
  72. clickedShowmoreButton = null;
  73. console.log(`wait one more round, just to be certain, before we potentially click other "show more..." buttons`);
  74. return;
  75. }
  76. if (showmoreButtons.length > 0) {
  77. clickedShowmoreButton = showmoreButtons[0];
  78. console.log(`Shift-clicking the button marked "${clickedShowmoreButton.innerText}"...`);
  79. const shiftClickEvent = document.createEvent("Event");
  80. shiftClickEvent.initEvent("click", true, true);
  81. shiftClickEvent.shiftKey = true;
  82. clickedShowmoreButton.dispatchEvent(shiftClickEvent);
  83. return;
  84. }
  85.  
  86. // LATER: Enable the following code, once we know how to detect a tab switch
  87. //function tabSwitchEventHandler() {
  88. // console.log(`tab bar may have been clicked, restart if needed...`);
  89. // if (!theInterval) {
  90. // console.log(`...restarting`);
  91. // start();
  92. // }
  93. //}
  94. //
  95. //if (!tabSwitchEventHandlerInstalled) {
  96. // // TODO: somewhere register tabSwitchEventHandler...
  97. // tabSwitchEventHandlerInstalled = true;
  98. //}
  99. //
  100. //console.log(`Everything is at it should be now; stop, and restart the interval on tab switch.`);
  101. //clearInterval(theInterval);
  102. //theInterval = null;
  103. }, 1000);
  104. }
  105.  
  106. start();
  107. })();