OTRS_Timer

Timer for OTRS with auto-complete of Time Units

目前為 2014-10-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        OTRS_Timer
// @author      Pedro VAZ PEREIRA
// @description Timer for OTRS with auto-complete of Time Units
// @include     */otrs/index.pl?Action=AgentTicketNote*
// @include     */otrs/index.pl?Action=AgentTicketPhone*
// @include     */otrs/index.pl?Action=AgentTicketClose*
// @include     */otrs/index.pl?Action=AgentTicketPending*
// @include     */otrs/index.pl?*Action=AgentTicketCompose*
// @version     1.2
// @grant       none
// @namespace https://greasyfork.org/users/6245
// ==/UserScript==
function addTimer() {
  var ban = document.getElementsByClassName('Header') [0];
  var banClose = ban.getElementsByTagName('p') [1];
  var newTimer = createTimer();
  ban.insertBefore(newTimer, banClose)
}
function createTimer() {
  var newDiv = document.createElement('div');
  var buttonStart = document.createElement('button');
  var buttonStop = document.createElement('button');
  var buttonReset = document.createElement('button');
  newDiv.id = 'Timer';
  buttonStart.id = 'Start';
  buttonStop.id = 'Stop';
  buttonReset.id = 'Reset';
  newDiv.innerHTML = '<H3><time>00:00<sec style=\'font-size: 0.8em;\'>:00</sec></time></H3>';
  buttonStart.innerHTML = 'START';
  buttonStop.innerHTML = 'STOP';
  buttonReset.innerHTML = 'RESET';
  newDiv.appendChild(buttonStart);
  newDiv.appendChild(buttonStop);
  newDiv.appendChild(buttonReset);
  return newDiv;
}
addTimer();
timer();

var h3 = document.getElementsByTagName('h3') [0],
start = document.getElementById('Start'),
stop = document.getElementById('Stop'),
clear = document.getElementById('Reset'),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add() {
  seconds++;
  if (seconds >= 60) {
    seconds = 0;
    minutes++;
    if (minutes >= 60) {
      minutes = 0;
      hours++;
    }
  }
  updateWorkUnits(hours, minutes);
  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>';
  timer();
}
function updateWorkUnits(hour, min) {
  hour = parseInt(hour);
  min = parseInt(min);
  var timeUnitsInput = document.getElementById('TimeUnits');
  var totalMinutes = hour * 60 + min;
  var timeUnit = Math.floor(totalMinutes / 3) * 0.05
  timeUnitsInput.value = timeUnit;
}
function timer() {
  t = setTimeout(add, 1000);
}
/* Start button */

start.onclick = timer;
/* Stop button */
stop.onclick = function () {
  clearTimeout(t);
}
/* Clear button */

clear.onclick = function () {
  h3.innerHTML = '00:00<sec style=\'font-size: 0.8em;\'>:00</sec>';
  seconds = 0;
  minutes = 0;
  hours = 0;
  var timeUnitsInput = document.getElementById('TimeUnits');
  timeUnitsInput.value = 0;
}