132 lines
5.4 KiB
JavaScript
132 lines
5.4 KiB
JavaScript
// ==UserScript==
|
||
// @name 复旦微加班时间统计
|
||
// @namespace http://start.fengbohan.com/
|
||
// @version 2025-07-19
|
||
// @description 统计加班总时间, 修复了周末加班时间统计的BUG
|
||
// @author bhfeng
|
||
// @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
|
||
// ==/UserScript==
|
||
|
||
(function() {
|
||
'use strict';
|
||
function calculateTimeDifference(timeString, weekday) {
|
||
// 判断字符串是否为 "--"
|
||
if (timeString === '--') {
|
||
return 0;
|
||
}
|
||
|
||
// 按逗号分割字符串
|
||
const times = timeString.split(',');
|
||
|
||
// 解析时间并转换为毫秒
|
||
const parsedTimes = times.map(timeStr => {
|
||
const [hours, minutes, seconds] = timeStr.trim().split(':').map(Number);
|
||
return isNaN(hours) || isNaN(minutes) || isNaN(seconds) ? null : (hours * 3600 + minutes * 60 + seconds) * 1000;
|
||
});
|
||
|
||
// 过滤掉无效的时间
|
||
const validTimes = parsedTimes.filter(time => time !== null);
|
||
|
||
if (validTimes.length === 0) {
|
||
return 'No valid times provided';
|
||
}
|
||
|
||
// 计算最大值和最小值
|
||
const maxTime = Math.max(...validTimes);
|
||
const minTime = Math.min(...validTimes);
|
||
|
||
// 下午5点20分(17:20:00)的时间戳
|
||
const fiveTwentyPM = (17 * 3600 + 20 * 60) * 1000;
|
||
let timeDifferenceInHours;
|
||
|
||
if (weekday === "周六" || weekday == "周日") {
|
||
// 计算时间差(以小时为单位)
|
||
timeDifferenceInHours = (maxTime - minTime) / (1000 * 60 * 60);
|
||
} else {
|
||
// 计算时间差(以小时为单位)
|
||
if (maxTime >= fiveTwentyPM) {
|
||
timeDifferenceInHours = (maxTime - fiveTwentyPM) / (1000 * 60 * 60);
|
||
} else {
|
||
//timeDifferenceInHours = (fiveTwentyPM - maxTime) / (1000 * 60 * 60);
|
||
timeDifferenceInHours = 0;
|
||
}
|
||
}
|
||
|
||
return timeDifferenceInHours;
|
||
}
|
||
|
||
function sumOfSecondColumn(tableId) {
|
||
// 获取表格元素
|
||
var table = document.getElementById(tableId);
|
||
|
||
// 初始化总和
|
||
var totalSum = 0;
|
||
|
||
// 获取所有的行
|
||
var rows = table.getElementsByTagName('tr');
|
||
|
||
// 遍历每行
|
||
for (var i = 1; i < rows.length; i++) { // 从1开始跳过表头
|
||
var cells = rows[i].getElementsByTagName('td');
|
||
if (cells.length > 1) { // 确保该行至少有两列
|
||
var cellValue = cells[3].textContent;
|
||
var weekday = cells[2].textContent;
|
||
var difference = calculateTimeDifference(cellValue, weekday);
|
||
console.log(`第${i}行:${difference} 小时`);
|
||
totalSum += difference;
|
||
|
||
// 创建新的单元格
|
||
var newCell2 = cells[4];
|
||
newCell2.style="width:110px;";
|
||
newCell2.textContent = `${difference.toFixed(2)}H`;
|
||
rows[i].appendChild(newCell2);
|
||
}
|
||
}
|
||
|
||
return totalSum;
|
||
}
|
||
|
||
// 创建一个新的按钮元素
|
||
var button = document.createElement('button');
|
||
button.style.width = "90px"; //按钮宽度
|
||
button.style.height = "60px"; //按钮高度
|
||
button.style.align = "center"; //文本居中
|
||
button.style.color = "#e5e5e5"; //按钮文字颜色
|
||
button.style.background = "#b46300"; //按钮底色
|
||
button.style.borderRadius = "4px"; //按钮四个角弧度
|
||
|
||
|
||
// 设置按钮的文字
|
||
button.textContent = '点击我';
|
||
|
||
// 添加点击事件监听器
|
||
button.addEventListener('click', function() {
|
||
var message = sumOfSecondColumn('grid').toFixed(2);
|
||
|
||
// 使用 alert() 函数弹出提示框
|
||
alert(`你加班了${message}小时,幸苦了!`);
|
||
|
||
var table = document.querySelector("#gview_grid > div.ui-state-default.ui-jqgrid-hdiv > div > table > thead > tr")
|
||
var rows = table.getElementsByTagName('th');
|
||
|
||
// 添加表头
|
||
var newCell = rows[4]
|
||
newCell.textContent = '加班时间';
|
||
table.appendChild(newCell);
|
||
});
|
||
|
||
// 获取要将按钮添加到其中的容器
|
||
var container = document.getElementById('seclevelmenu'); // 假设页面上有id为'container'的元素
|
||
|
||
// 如果没有找到容器,则添加到body元素
|
||
if (!container) {
|
||
container = document.body;
|
||
}
|
||
|
||
// 将按钮添加到容器中
|
||
container.appendChild(button);
|
||
console.log("复旦微加班时间统计脚本已加载");
|
||
console.log("点击按钮后会统计加班时间");
|
||
})(); |