Shorten BitBucket commit message on JIRA

Hides everything but the first line of a commit message

  1. // ==UserScript==
  2. // @name Shorten BitBucket commit message on JIRA
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Hides everything but the first line of a commit message
  6. // on related commits for JIRA tickets linked to BitBucket.
  7. // @author DJ Marcolesco
  8. // @match https://*.atlassian.net/*
  9. // @grant none
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. waitForKeyElements('.commits-table', function ($$) {
  17. var $commits = $$.find('.commitrow');
  18.  
  19. // Delete all text after first line on each commit row
  20. $commits.each(function () {
  21. var $message = $(this).find('.message .ellipsis');
  22. var text = $message.text();
  23. var pre_text = text.substr(0, text.indexOf('\n'));
  24. var post_text = text.substr(text.indexOf('\n'));
  25.  
  26. $message.html('<span>' + pre_text + '</span><span style="opacity: .6;">' + post_text + '</span>');
  27. });
  28. });
  29. })();
  30.  
  31. /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
  32. that detects and handles AJAXed content.
  33.  
  34. Usage example:
  35.  
  36. waitForKeyElements (
  37. "div.comments"
  38. , commentCallbackFunction
  39. );
  40.  
  41. //--- Page-specific function to do what we want when the node is found.
  42. function commentCallbackFunction (jNode) {
  43. jNode.text ("This comment changed by waitForKeyElements().");
  44. }
  45.  
  46. IMPORTANT: This function requires your script to have loaded jQuery.
  47. */
  48. function waitForKeyElements (
  49. selectorTxt, /* Required: The jQuery selector string that
  50. specifies the desired element(s).
  51. */
  52. actionFunction, /* Required: The code to run when elements are
  53. found. It is passed a jNode to the matched
  54. element.
  55. */
  56. bWaitOnce, /* Optional: If false, will continue to scan for
  57. new elements even after the first match is
  58. found.
  59. */
  60. iframeSelector /* Optional: If set, identifies the iframe to
  61. search.
  62. */
  63. ) {
  64. var targetNodes, btargetsFound;
  65.  
  66. if (typeof iframeSelector == "undefined")
  67. targetNodes = $(selectorTxt);
  68. else
  69. targetNodes = $(iframeSelector).contents ()
  70. .find (selectorTxt);
  71.  
  72. if (targetNodes && targetNodes.length > 0) {
  73. btargetsFound = true;
  74. /*--- Found target node(s). Go through each and act if they
  75. are new.
  76. */
  77. targetNodes.each ( function () {
  78. var jThis = $(this);
  79. var alreadyFound = jThis.data ('alreadyFound') || false;
  80.  
  81. if (!alreadyFound) {
  82. //--- Call the payload function.
  83. var cancelFound = actionFunction (jThis);
  84. if (cancelFound)
  85. btargetsFound = false;
  86. else
  87. jThis.data ('alreadyFound', true);
  88. }
  89. } );
  90. }
  91. else {
  92. btargetsFound = false;
  93. }
  94.  
  95. //--- Get the timer-control variable for this selector.
  96. var controlObj = waitForKeyElements.controlObj || {};
  97. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  98. var timeControl = controlObj [controlKey];
  99.  
  100. //--- Now set or clear the timer as appropriate.
  101. if (btargetsFound && bWaitOnce && timeControl) {
  102. //--- The only condition where we need to clear the timer.
  103. clearInterval (timeControl);
  104. delete controlObj [controlKey]
  105. }
  106. else {
  107. //--- Set a timer, if needed.
  108. if ( ! timeControl) {
  109. timeControl = setInterval ( function () {
  110. waitForKeyElements ( selectorTxt,
  111. actionFunction,
  112. bWaitOnce,
  113. iframeSelector
  114. );
  115. },
  116. 300
  117. );
  118. controlObj [controlKey] = timeControl;
  119. }
  120. }
  121. waitForKeyElements.controlObj = controlObj;
  122. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址