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

QingJ © 2025

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