GitLab Total Time

Add total time to header of lists on GitLab boards

Verze ze dne 16. 08. 2021. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name GitLab Total Time
  3. // @namespace https://github.com/LibreCodeCoop/gitlab-time-userscript/
  4. // @version 0.1
  5. // @description Add total time to header of lists on GitLab boards
  6. // @author Vitor Mattos
  7. // @supportURL https://github.com/LibreCodeCoop/gitlab-time-userscript/issues
  8. // @license AGPL-3.0-or-later
  9. // @match http*://*/*/boards
  10. // @match http*://*/*/boards?*
  11. // @match http*://*/*/boards/*
  12. // @icon https://gitlab.com/assets/gitlab_logo-7ae504fe4f68fdebb3c2034e36621930cd36ea87924c11ff65dbcb8ed50dca58.png
  13. // @require https://code.jquery.com/jquery-3.6.0.min.js
  14. // ==/UserScript==
  15.  
  16. function listTotalTime() {
  17. $('header.board-header div.issue-count-badge').each(function() {
  18. var container = $(this).children();
  19. var timeElement = container.find('span.list-total-time');
  20. if(timeElement.length === 0) {
  21. container.append('<span class="gl-display-inline-flex gl-ml-3 list-total-time"></span>')
  22. }
  23. timeElement = container.find('span.list-total-time')
  24.  
  25. timeElement.attr('time_m', 0)
  26. timeElement.attr('time_h', 0)
  27. });
  28.  
  29. $('time:not([datetime]').each(function() {
  30. var countElement = $(this).closest('div.board-inner').find('span.list-total-time');
  31. var time = $(this).text()
  32. var type = time.slice(-1)
  33. time = time.slice(0, -1)
  34. countElement.attr('time_' + type, parseInt(countElement.attr('time_' + type)) + parseInt(time))
  35. })
  36.  
  37. $('span.list-total-time').each(function() {
  38. var min = parseInt($(this).attr('time_m'))
  39. if (min >= 60) {
  40. $(this).attr('time_h', parseInt($(this).attr('time_h')) + min / 60)
  41. $(this).attr('time_m', parseInt($(this).attr('time_m')) + min % 60)
  42. }
  43. var minPad = $(this).attr('time_m')
  44. minPad = ('00' + minPad).slice(-2)
  45. $(this).html(
  46. '<svg role="img" aria-hidden="true" class="gl-mr-2 gl-icon s16" data-testid="hourglass-icon"><use href="/assets/icons-05c4d4d8f3cc1fe0f22064d47d6a57d254ff9686a08abb74993ade21581e46f8.svg#hourglass"></use></svg>'
  47. + $(this).attr('time_h')
  48. + ':'
  49. + minPad
  50. )
  51. });
  52. }
  53.  
  54. $(document).ready(function() {
  55. setTimeout(function () {
  56. $('<div class="gl-ml-3 gl-display-flex gl-align-items-center"><button title="" data-qa-selector="boards_config_button" type="button" class="btn btn-default btn-md gl-button" id="refresh-list-time"><!----> <!----> <span class="gl-button-text">Refresh times</span></button></div>').insertAfter($('[data-testid="boards-create-list"]'));
  57.  
  58. $('#refresh-list-time').on("click", function(){
  59. listTotalTime()
  60. })
  61. }, 1000)
  62. });