GitLab Total Time

Add total time to header of lists on GitLab boards

目前為 2021-08-16 提交的版本,檢視 最新版本

  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. // @match http*://*/*/boards
  8. // @match http*://*/*/boards?*
  9. // @match http*://*/*/boards/*
  10. // @icon https://gitlab.com/assets/gitlab_logo-7ae504fe4f68fdebb3c2034e36621930cd36ea87924c11ff65dbcb8ed50dca58.png
  11. // @require https://code.jquery.com/jquery-3.6.0.min.js
  12. // ==/UserScript==
  13.  
  14. function listTotalTime() {
  15. $('header.board-header div.issue-count-badge').each(function() {
  16. var container = $(this).children();
  17. var timeElement = container.find('span.list-total-time');
  18. if(timeElement.length === 0) {
  19. container.append('<span class="gl-display-inline-flex gl-ml-3 list-total-time"></span>')
  20. }
  21. timeElement = container.find('span.list-total-time')
  22.  
  23. timeElement.attr('time_m', 0)
  24. timeElement.attr('time_h', 0)
  25. });
  26.  
  27. $('time:not([datetime]').each(function() {
  28. var countElement = $(this).closest('div.board-inner').find('span.list-total-time');
  29. var time = $(this).text()
  30. var type = time.slice(-1)
  31. time = time.slice(0, -1)
  32. countElement.attr('time_' + type, parseInt(countElement.attr('time_' + type)) + parseInt(time))
  33. })
  34.  
  35. $('span.list-total-time').each(function() {
  36. var min = parseInt($(this).attr('time_m'))
  37. if (min >= 60) {
  38. $(this).attr('time_h', parseInt($(this).attr('time_h')) + min / 60)
  39. $(this).attr('time_m', parseInt($(this).attr('time_m')) + min % 60)
  40. }
  41. var minPad = $(this).attr('time_m')
  42. minPad = ('00' + minPad).slice(-2)
  43. $(this).html(
  44. '<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>'
  45. + $(this).attr('time_h')
  46. + ':'
  47. + minPad
  48. )
  49. });
  50. }
  51.  
  52. $(document).ready(function() {
  53. setTimeout(function () {
  54. $('<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"]'));
  55.  
  56. $('#refresh-list-time').on("click", function(){
  57. listTotalTime()
  58. })
  59. }, 1000)
  60. });

QingJ © 2025

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