Jira time entry helper

Allows entering the time as h:mm, hmn or hhmm. Also changes the background, depending on the entered time validating or not.

  1. // ==UserScript==
  2. // @name Jira time entry helper
  3. // @namespace Mathema
  4. // @description Allows entering the time as h:mm, hmn or hhmm. Also changes the background, depending on the entered time validating or not.
  5. // @version 1
  6. // @grant none
  7. // @include https://jira.*/*
  8. // @run-at document-idle
  9. // @license BSD-2-Clause
  10. // ==/UserScript==
  11.  
  12.  
  13. /* Copyright (c) 2023 Moritz Strübe / MATHEMA GmbH.
  14.  
  15. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  16.  
  17. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  18. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
  19. documentation and/or other materials provided with the distribution.
  20.  
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28.  
  29.  
  30. function validateDatetime(inputField) {
  31. var v = inputField.value;
  32. var canFormat = /^\d\d\d\d?$/.test(v);
  33.  
  34. if (canFormat) {
  35. if(v.length === 3) {
  36. v = 0 + v;
  37. }
  38. v = v.substring(0,2) + ":" + v.substring(2);
  39. inputField.value = v;
  40. }
  41. if(/^\d\:d\d$/.test(v)) {
  42. v = "0" + v;
  43. }
  44. var isValid = /^\d\d\:\d\d$/.test(v);
  45. if(isValid) {
  46. inputField.style.backgroundColor = '#bfa';
  47. } else {
  48. inputField.style.backgroundColor = '#fba';
  49. }
  50. }
  51.  
  52. function registerTimes() {
  53. const inp = document.getElementsByTagName('input');
  54. for(var key in inp){
  55. if(typeof inp[key].name === "undefined") continue;
  56. if(! inp[key].name.includes("Time"))continue;
  57. if(inp[key].classList.contains('jira-time-listener-23434')) continue;
  58. inp[key].addEventListener('blur', function(event) {
  59. var targ = event.target || event.srcElement;
  60. validateDatetime(targ);
  61. });
  62. inp[key].classList.add('jira-time-listener-23434');
  63. };
  64. }
  65.  
  66. var myTimer = setInterval(registerTimes, 1000);
  67.  
  68.  

QingJ © 2025

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