// ==UserScript== // @name WTRS工数自动填写 // @namespace http://tampermonkey.net/ // @version 0.3 // @description A script help you input work time automatically, enjoy! // @author 贝克街的流浪猫 // @match http://wtrs-cn.navercorp.com/ // @grant none // @downloadURL 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(); } } })();