Auto-expand older comments in JIRA issue

Automatically expands the older comments accordion in JIRA so you see all comments by default. Workaround to jira.comment.collapsing.minimum.hidden. Aids in searching page. Forked from https://greasyfork.org/en/scripts/29233-atlassian-jira-auto-expand-older-comments and fixed (no external dependencies).

当前为 2021-09-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto-expand older comments in JIRA issue
  3. // @description Automatically expands the older comments accordion in JIRA so you see all comments by default. Workaround to jira.comment.collapsing.minimum.hidden. Aids in searching page. Forked from https://greasyfork.org/en/scripts/29233-atlassian-jira-auto-expand-older-comments and fixed (no external dependencies).
  4. // @include https://jira.*
  5. // @include http://jira.*
  6. // @match https://jira.*
  7. // @match http://jira.*
  8. // @version 1.0
  9. // @namespace https://greasyfork.org/en/users/709170
  10. // ==/UserScript==
  11.  
  12. /**
  13. * A utility function for userscripts that detects and handles AJAXed content.
  14. *
  15. * Author: https://github.com/CoeJoder/waitForKeyElements.js
  16. * Downloaded from: https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.2/waitForKeyElements.js
  17. *
  18. * Usage example:
  19. *
  20. * function callback(domElement) {
  21. * domElement.innerHTML = "This text inserted by waitForKeyElements().";
  22. * }
  23. *
  24. * waitForKeyElements("div.comments", callback);
  25. * // or
  26. * waitForKeyElements(selectorFunction, callback);
  27. *
  28. * @param {(string|function)} selectorOrFunction - The selector string or function.
  29. * @param {function} callback - The callback function; takes a single DOM element as parameter.
  30. * If returns true, element will be processed again on subsequent iterations.
  31. * @param {boolean} [waitOnce=true] - Whether to stop after the first elements are found.
  32. * @param {number} [interval=300] - The time (ms) to wait between iterations.
  33. * @param {number} [maxIntervals=-1] - The max number of intervals to run (negative number for unlimited).
  34. */
  35. function waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals) {
  36. if (typeof waitOnce === "undefined") {
  37. waitOnce = true;
  38. }
  39. if (typeof interval === "undefined") {
  40. interval = 300;
  41. }
  42. if (typeof maxIntervals === "undefined") {
  43. maxIntervals = -1;
  44. }
  45. var targetNodes = (typeof selectorOrFunction === "function")
  46. ? selectorOrFunction()
  47. : document.querySelectorAll(selectorOrFunction);
  48.  
  49. var targetsFound = targetNodes && targetNodes.length > 0;
  50. if (targetsFound) {
  51. targetNodes.forEach(function(targetNode) {
  52. var attrAlreadyFound = "data-userscript-alreadyFound";
  53. var alreadyFound = targetNode.getAttribute(attrAlreadyFound) || false;
  54. if (!alreadyFound) {
  55. var cancelFound = callback(targetNode);
  56. if (cancelFound) {
  57. targetsFound = false;
  58. }
  59. else {
  60. targetNode.setAttribute(attrAlreadyFound, true);
  61. }
  62. }
  63. });
  64. }
  65.  
  66. if (maxIntervals !== 0 && !(targetsFound && waitOnce)) {
  67. maxIntervals -= 1;
  68. setTimeout(function() {
  69. waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals);
  70. }, interval);
  71. }
  72. }
  73.  
  74. function clickWhenItAppears (jNode) {
  75. var clickEvent = document.createEvent ('MouseEvents');
  76. clickEvent.initEvent ('click', true, true);
  77. jNode.dispatchEvent (clickEvent);
  78. }
  79.  
  80. //bWaitOnce = true;
  81. // <a class="collapsed-comments" href="(redacted)"><span class="collapsed-comments-line"></span><span class="collapsed-comments-line"></span><span class="show-more-comments" data-collapsed-count="12">12 older comments</span></a>
  82. waitForKeyElements (
  83. "a[class='collapsed-comments']",
  84. clickWhenItAppears
  85. );