Greasy Fork

Greasy Fork is available in English.

WTRS工数自动填写

A script help you input work time automatically, enjoy!

当前为 2018-03-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WTRS工数自动填写
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  A script help you input work time automatically, enjoy!
// @author       贝克街的流浪猫
// @match        http://wtrs-cn.navercorp.com/
// @grant        none
// ==/UserScript==

(function() {
    var runButton = document.createElement("BUTTON");
    var runButtonSpan = document.createElement("SPAN");
    runButtonSpan.appendChild(document.createTextNode("自动填写工数"));
    runButton.appendChild(runButtonSpan);
    runButtonSpan.className = "ui-button-text";
    runButton.className = "ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only";
    runButton.onclick = doWork;
    $('#logoutBtn')[0].parentElement.appendChild(runButton);
    function doWork () {
        if (!isAllInputRowLoaded()) {
           rowsDisplayToggle();
           setInterval(loopWaitInputRowLoadedAndInputWorkTime, 100);
        } else {
           loopWaitInputRowLoadedAndInputWorkTime();
        }
    }
    function loopWaitInputRowLoadedAndInputWorkTime () {
       if (isAllInputRowLoaded()) {
           inputWorkTime();
           rowsDisplayToggle();
           clearInterval();
        }
    }
    function getAllRows () {
       with (document.getElementById('mainWin').contentWindow) {
            return $('.ui-widget-content.jqgrow.ui-row-ltr:not(.ui-state-disabled,.selected-row)');
        }
    }
    function getInputElement () {
       with (document.getElementById('mainWin').contentWindow) {
         return $('#1_times');
       }
    }
    function getDataRows() {
       var result = [];
       var searchResult = getAllRows();
       for(var i = 0; i < searchResult.length; i++){
          if (searchResult[i].id.indexOf('LINE') == -1) {
            result.push(searchResult[i]);
          }
       }
       return result;
    }
    function getInputRows() {
       var result = [];
       var searchResult = getAllRows();
       for(var i = 0; i < searchResult.length; i++){
          if (searchResult[i].id.indexOf('LINE') != -1) {
            result.push(searchResult[i]);
          }
       }
       return result;
    }
    function rowsDisplayToggle () {
       var rows = getAllRows();
       for(var i = 0; i < rows.length; i++){
          rows[i].children[1].click();
       }
    }
    function isAllInputRowLoaded () {
      return getDataRows().length == getInputRows().length;
    }
    function inputWorkTime() {
        var rows = getAllRows();
        for(var j = 0; j < rows.length; j++){
            var value =parseFloat(rows[j++].children[8].innerText);
            rows[j].children[6].click();
            getInputElement().val(value).trigger('change');
            rows[j].children[5].click();
        }
    }
})();