增加了多个查询按钮
This commit is contained in:
174
main.js
174
main.js
@@ -7,6 +7,7 @@
|
||||
// @match http://192.168.36.67:7888/shr/dynamic.do?uipk=com.kingdee.eas.hr.ats.app.WorkCalendarItem*
|
||||
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAdVBMVEX///////7+/v4kVZ729/lafbO2xd3x8/f5+vz8/Pzd4+4tW6GSp8xnh7nP2OgxXqLK1OZ1kb/s7/UgUZytvdhKcKw+aKgaTZlhgrbU3eqar9Dm6fFVd7CEnsZwjb4VSZfAy+BCbKq3xd58l8OXrM6nudaMo8kyjkGlAAABfklEQVQokT1Si5arIBCLDIqCiogP8FHtWvv/n3iH7vZyDjDMQAIJwLdlpVIlz0L8T0FAxDaTy5JBrWn52ZhxoO6tQ+ZyjT7fJSqRpYJAJte8qbDPmxKPY4vgXOqdhramwzp6B1GTKRJahjjVVdlQI3FauiTahkOmFfHyJ9qJduC2lHf4o69weiZYyLyAYvLWFe3O1apHa80AsZOpGfdhZrLHDfSDwpumFuVO5HqI8xot3xvrM5Qy+DGiqo3fTgbvteRRT36AHmlk2J/R26vlbHmuiMVrWtOlpoGPX2a2wV3BMjQiNSXakezVA50zfvbHyGTMQlcFnRNtRQXEl3u4lklWVRi6FNRuyTRD/5E7sXehvIlCBM6c3zBed3E/dNKqCdlg/bRIlENj/XHMxztphdUGxNxTKNhAPbz3/edjlEC0uRTLc6b81syu5K8fPOhxKtAvm5/NMw/vNRNfy1U9hUKpbnFNsyh8v0Pa0A/O1SyE+LrxV6mSdjH2gsPf/D//7BjTQny+YwAAAABJRU5ErkJggg==
|
||||
// @grant none
|
||||
// @run-at document-idle
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
@@ -14727,34 +14728,151 @@
|
||||
}
|
||||
return totalSum;
|
||||
}
|
||||
// 创建并添加按钮
|
||||
var button = document.createElement('button');
|
||||
var copiedStyles = {
|
||||
webkitTapHighlightColor: "rgba(0, 0, 0, 0)",
|
||||
fontFamily: '"Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif',
|
||||
fontSize: "14px",
|
||||
listStyle: "none",
|
||||
textAlign: "center",
|
||||
boxSizing: "border-box",
|
||||
webkitTextSizeAdjust: "100%",
|
||||
backgroundColor: "transparent",
|
||||
display: "block",
|
||||
lineHeight: "60px",
|
||||
height: "60px",
|
||||
padding: "0px 10px",
|
||||
textDecoration: "none",
|
||||
color: "#e5e5e5",
|
||||
};
|
||||
Object.assign(button.style, copiedStyles);
|
||||
button.textContent = '统计加班时间';
|
||||
|
||||
// 添加点击事件监听器
|
||||
button.addEventListener('click', function() {
|
||||
var message = sumOfSecondColumn('grid').toFixed(2);
|
||||
var table = document.querySelector("#gview_grid > div.ui-state-default.ui-jqgrid-hdiv > div > table > thead > tr")
|
||||
var rows = table.getElementsByTagName('th');
|
||||
// 方便快速查询前一月、前二月、前三月
|
||||
function simulateDateInput(elementId, dateValue) {
|
||||
const inputElement = document.getElementById(elementId);
|
||||
if (!inputElement) {
|
||||
console.error(`未找到ID为 ${elementId} 的输入框`);
|
||||
return;
|
||||
}
|
||||
|
||||
inputElement.focus();
|
||||
inputElement.value = dateValue;
|
||||
inputElement.dispatchEvent(new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}));
|
||||
|
||||
inputElement.dispatchEvent(new Event('change', {
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}));
|
||||
inputElement.blur();
|
||||
}
|
||||
|
||||
function getCustomMonthRange(monthsAgo) {
|
||||
const now = new Date();
|
||||
let year = now.getFullYear();
|
||||
let month = now.getMonth() - monthsAgo;
|
||||
while (month < 0) {
|
||||
month += 12;
|
||||
year--;
|
||||
}
|
||||
const firstDay = new Date(year, month - 1, 20);
|
||||
const lastDay = new Date(year, month, 19);
|
||||
const formatLocal = (date) => {
|
||||
return date.toLocaleDateString('en-CA', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
}).replace(/\//g, '-');
|
||||
};
|
||||
return {
|
||||
firstDay: formatLocal(firstDay),
|
||||
lastDay: formatLocal(lastDay)
|
||||
};
|
||||
}
|
||||
|
||||
// 创建菜单按钮
|
||||
function createMenueButton(text, options = {}) {
|
||||
const button = document.createElement('button');
|
||||
button.textContent = text;
|
||||
const copiedStyles = {
|
||||
webkitTapHighlightColor: "rgba(0, 0, 0, 0)",
|
||||
fontFamily: '"Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif',
|
||||
fontSize: "14px",
|
||||
listStyle: "none",
|
||||
textAlign: "center",
|
||||
boxSizing: "border-box",
|
||||
webkitTextSizeAdjust: "100%",
|
||||
backgroundColor: "transparent",
|
||||
display: "block",
|
||||
lineHeight: "60px",
|
||||
height: "60px",
|
||||
padding: "0px 10px",
|
||||
textDecoration: "none",
|
||||
color: "#e5e5e5",
|
||||
};
|
||||
Object.assign(button.style, copiedStyles);
|
||||
|
||||
// 处理点击事件回调
|
||||
if (typeof options.onClick === 'function') {
|
||||
button.addEventListener('click', options.onClick);
|
||||
}
|
||||
return button;
|
||||
}
|
||||
// 查询工作时间
|
||||
function get_work_time() {
|
||||
const message = sumOfSecondColumn('grid').toFixed(2);
|
||||
const table = document.querySelector("#gview_grid > div.ui-state-default.ui-jqgrid-hdiv > div > table > thead > tr")
|
||||
const rows = table.getElementsByTagName('th');
|
||||
// 修改表头
|
||||
rows[5].querySelector('#jqgh_grid_fillCardTimeStr').textContent = `加班时间(${message}小时)`;
|
||||
}
|
||||
|
||||
var query_button = document.getElementById("query");
|
||||
// 创建菜单按钮
|
||||
const button = createMenueButton("统计加班时间", {
|
||||
onClick: () => {
|
||||
get_work_time();
|
||||
}
|
||||
})
|
||||
const button0 = createMenueButton('查当月', {
|
||||
onClick: () => {
|
||||
const month = getCustomMonthRange(0);
|
||||
const firstDay = month.firstDay;
|
||||
const lastDay = month.lastDay;
|
||||
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
|
||||
simulateDateInput('beginDate', firstDay);
|
||||
simulateDateInput('endDate', lastDay);
|
||||
query_button.click();
|
||||
setTimeout(function() {
|
||||
get_work_time();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
const button1 = createMenueButton('查上月', {
|
||||
onClick: () => {
|
||||
const month = getCustomMonthRange(1);
|
||||
const firstDay = month.firstDay;
|
||||
const lastDay = month.lastDay;
|
||||
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
|
||||
simulateDateInput('beginDate', firstDay);
|
||||
simulateDateInput('endDate', lastDay);
|
||||
query_button.click();
|
||||
setTimeout(function() {
|
||||
get_work_time();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
const button2 = createMenueButton('查上上月', {
|
||||
onClick: () => {
|
||||
const month = getCustomMonthRange(2);
|
||||
const firstDay = month.firstDay;
|
||||
const lastDay = month.lastDay;
|
||||
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
|
||||
simulateDateInput('beginDate', firstDay);
|
||||
simulateDateInput('endDate', lastDay);
|
||||
query_button.click();
|
||||
setTimeout(function() {
|
||||
get_work_time();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
const button3 = createMenueButton('查上上上月', {
|
||||
onClick: () => {
|
||||
const month = getCustomMonthRange(3);
|
||||
const firstDay = month.firstDay;
|
||||
const lastDay = month.lastDay;
|
||||
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
|
||||
simulateDateInput('beginDate', firstDay);
|
||||
simulateDateInput('endDate', lastDay);
|
||||
query_button.click();
|
||||
setTimeout(function() {
|
||||
get_work_time();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// 获取要将按钮添加到其中的容器
|
||||
@@ -14763,6 +14881,10 @@
|
||||
container = document.body;
|
||||
}
|
||||
container.appendChild(button);
|
||||
container.appendChild(button0);
|
||||
container.appendChild(button1);
|
||||
container.appendChild(button2);
|
||||
container.appendChild(button3);
|
||||
console.log("复旦微加班时间统计脚本已加载");
|
||||
console.log("点击按钮后会统计加班时间");
|
||||
})();
|
||||
})()
|
Reference in New Issue
Block a user