OTRS_Timer

Timer for OTRS with auto-complete of Time Units

  1. // ==UserScript==
  2. // @name OTRS_Timer
  3. // @author Pedro VAZ PEREIRA
  4. // @description Timer for OTRS with auto-complete of Time Units
  5. // @include */otrs/index.pl?Action=AgentTicketNote*
  6. // @include */otrs/index.pl?Action=AgentTicketPhone*
  7. // @include */otrs/index.pl?Action=AgentTicketClose*
  8. // @include */otrs/index.pl?Action=AgentTicketPending*
  9. // @version 1.4
  10. // @license Licence Creative Commons Attribution - Partage dans les Mêmes Conditions 3.0 France (CC BY-SA 3.0 FR)
  11. // @grant none
  12. // @namespace https://greasyfork.org/users/6245
  13. // ==/UserScript==
  14. function addTimer() {
  15. var ban = document.getElementsByClassName('Header') [0];
  16. var banClose = ban.getElementsByTagName('p') [1];
  17. var newTimer = createTimer();
  18. ban.insertBefore(newTimer, banClose)
  19. }
  20. function createTimer() {
  21. var newDiv = document.createElement('div');
  22. var buttonStart = document.createElement('button');
  23. var buttonStop = document.createElement('button');
  24. var buttonReset = document.createElement('button');
  25. newDiv.id = 'Timer';
  26. buttonStart.id = 'Start';
  27. buttonStop.id = 'Stop';
  28. buttonReset.id = 'Reset';
  29. newDiv.innerHTML = '<H3><time>00:00<sec style=\'font-size: 0.8em;\'>:00</sec></time></H3>';
  30. buttonStart.innerHTML = 'START';
  31. buttonStop.innerHTML = 'STOP';
  32. buttonReset.innerHTML = 'RESET';
  33. newDiv.appendChild(buttonStart);
  34. newDiv.appendChild(buttonStop);
  35. newDiv.appendChild(buttonReset);
  36. return newDiv;
  37. }
  38. addTimer();
  39. timer();
  40.  
  41. var h3 = document.getElementsByTagName('h3') [0],
  42. start = document.getElementById('Start'),
  43. stop = document.getElementById('Stop'),
  44. clear = document.getElementById('Reset'),
  45. seconds = 0,
  46. minutes = 0,
  47. hours = 0,
  48. t;
  49.  
  50. function add() {
  51. seconds++;
  52. if (seconds >= 60) {
  53. seconds = 0;
  54. minutes++;
  55. if (minutes >= 60) {
  56. minutes = 0;
  57. hours++;
  58. }
  59. }
  60. updateWorkUnits(hours, minutes);
  61. h3.innerHTML = (hours ? (hours > 9 ? hours : '0' + hours) : '00') + ':' + (minutes ? (minutes > 9 ? minutes : '0' + minutes) : '00') + '<sec style=\'font-size: 0.8em;\'>:' + (seconds > 9 ? seconds : '0' + seconds) + '</sec>';
  62. timer();
  63. }
  64. function updateWorkUnits(hour, min) {
  65. hour = parseInt(hour);
  66. min = parseInt(min);
  67. var timeUnitsInput = document.getElementById('TimeUnits');
  68. var totalMinutes = hour * 60 + min;
  69. var timeUnit = Math.floor(totalMinutes / 3) * 0.05
  70. timeUnitsInput.value = timeUnit;
  71. }
  72. function timer() {
  73. t = setTimeout(add, 1000);
  74. }
  75. /* Start button */
  76.  
  77. start.onclick = timer;
  78. /* Stop button */
  79. stop.onclick = function () {
  80. clearTimeout(t);
  81. }
  82. /* Clear button */
  83.  
  84. clear.onclick = function () {
  85. h3.innerHTML = '00:00<sec style=\'font-size: 0.8em;\'>:00</sec>';
  86. seconds = 0;
  87. minutes = 0;
  88. hours = 0;
  89. var timeUnitsInput = document.getElementById('TimeUnits');
  90. timeUnitsInput.value = 0;
  91. }