刷连记录的迟到检测---Table表格增加一列值

时间:2024-05-01 19:03:47

公司OA新增加了 刷脸记录 ,用于查看自己是否迟到,但是没有什么提醒,于是乎自己写了一个脚本

刷连记录 类似于这样的:

刷连记录的迟到检测---Table表格增加一列值

运行脚本后,是这个样子的:

刷连记录的迟到检测---Table表格增加一列值

擦,我本月已经迟到了 3次了。。。。

拖拽 刷脸记录-迟到检测 到Chrome标签栏,点击就可以执行脚本了

脚本内容为:

 /*******************
* FileName : js_刷脸记录 整理.js
* Description: 在OA网页 刷脸记录中,执行后可显示 是否迟到。
********************/
// JS 压缩工具:
//http://tool.oschina.net/jscompress //===============================================
// 1 加载jQuery
//===============================================
//http://www.cnblogs.com/BearsTaR/archive/2010/08/05/js_include.html
//http://segmentfault.com/q/1010000000469374
//http://*.com/questions/950087/include-a-javascript-file-in-another-javascript-file //http://www.huoduan.com/jquery-cdn.html
//http://www.bootcdn.cn/jquery/ function include(jsurl) {
if (jsurl == null || typeof(jsurl) != 'string') return;
var script = document.createElement('script');
script.type = 'text/javascript';
script.charset = 'utf-8';
script.src = jsurl;
/*script.setAttribute("src",jsurl);*/
document.head.appendChild(script);
}
include("http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js");
//===============================================
//2 分析表格
//=============================================== //$("table.shualian").innerHTML=""; function IsAmPm(d){
var hour=d.getHours();
//早上 6点到12点 算是上班
if(hour>=0 && hour <=12){
return 1;
}
//中午12点到晚上24点之间 算是下班时间
if(hour >12 && hour <24){
return 2;
}
return 2;
} //将秒数 转化为人类可读的字符串
function HumanReadSeconds(mililsSeconds){
mililsSeconds=mililsSeconds/1000;
mililsSeconds=parseInt(mililsSeconds);
//typeof(mililsSeconds)=="number"||typeof(mililsSeconds)=="string"
/*
1.丢弃小数部分,保留整数部分
js:parseInt(7/2) 2.向上取整,有小数就整数部分加1
js: Math.ceil(7/2) 3,四舍五入.
js: Math.round(7/2) 4,向下取整
js: Math.floor(7/2)
*/
var isFushu=mililsSeconds>0?1:-1;
mililsSeconds=Math.abs(mililsSeconds);
var day=0,hour=0,minute=0,second=0;
day=mililsSeconds/86400;
day=parseInt(day);
hour=(mililsSeconds-day*86400)/3600;
hour=parseInt(hour);
minute=(mililsSeconds-day*86400-3600*hour)/60;
minute=parseInt(minute);
second=mililsSeconds-day*86400-3600*hour-minute*60;
second=parseInt(second);
//
var ret="";
if(day>0)
ret=day+"天";
if(hour>0||day>0)
ret+=hour+"小时";
if(minute>0||hour>0||hour>0){
ret+=minute+"分";
}
ret+=second+"秒";
return ret+(isFushu>0?"":"[以前]");
}
//当前时间 打卡算是迟到 或 早退吗
function IsLate(nowDate){
//上午 是 9点01分之前 ;下午是18:00之后
var date2;//当日 迟到时间
console.log("当前时间为:"+nowDate.toLocaleString());
if(IsAmPm(nowDate)==1){
date2=new Date(nowDate.getYear()+1900,
nowDate.getMonth(),/*范围0-11 代表1-12月*/
nowDate.getDate(),
9,
01,
00);
console.log("当日 不迟到时间为:"+date2.toLocaleString());
console.log("nowDate="+nowDate.valueOf()+"; date2="+date2.valueOf()+"; date2-nowDate="+(date2-nowDate));
if( nowDate<date2){
return "";
}else{
return "迟到了"+HumanReadSeconds(nowDate-date2);
}
}else{
date2=new Date(nowDate.getYear()+1900,
nowDate.getMonth(),/*范围0-11 代表1-12月*/
nowDate.getDate(),
18,
00,
00); console.log("当日 不早退时间为:"+date2.toLocaleString());
console.log("nowDate="+nowDate.valueOf()+"; date2="+date2.valueOf()+"; nowDate-date2="+(nowDate-date2));
if( nowDate>date2){
return "";
}else{
return "早退了"+HumanReadSeconds(date2-nowDate);
}
}
} function AddChiDaoColor(isLate,td,row){
if(isLate.length!=0){
//迟到提醒记录 红色 加粗字体
td.innerText+=isLate;
td.style="color:red;"
td.style.color="red";
td.style.fontWeight="bold";
td.style.backgroundColor="yellow"; row.appendChild(td);
}else{
//无迟到描述空
td.innerText+="没有迟到";
row.appendChild(td);
} } for(var i=0;i<document.getElementsByTagName("frame").length;i++)
{
if(document.getElementsByTagName("frame")[i].name==="main"){
var f=window.top.document.getElementsByTagName("frame")[2];
var content=f.contentDocument.getElementsByTagName("table")[2];
//var c=$(f.contentDocument.getElementsByTagName("table")[2]);
//第一行 是姓名 刷连时间,添加 是否迟到 var row0=content.rows[0];
var td = document.createElement('td');
td.innerText="是否迟到";
td.align="center"
td.width="10%"
row0.appendChild(td) //第二行 到最后一行 分别执行 判断迟到操作
var j=0;
var lastAmPM=1;//1是上班时间 2是下班时间
var lastDay=undefined;
while(++j<content.rows.length){
var row=content.rows[j];
//"刷脸时间"这一列 转化为 时间
var theDay = new Date(Date.parse(row.cells[1].innerText.replace(/-/g, "/")));
console.log("lastDay="+lastDay);
var td = document.createElement('td');
td.align="center"
td.width="10%" if(lastDay===undefined){
//这是第一条记录c
lastDay=theDay;
lastAmPM=IsAmPm(lastDay);//=1 am =2 pm
//console.log("lastDay="+lastDay.toLocaleString());
//console.log("lastAmPM="+lastAmPM);
var isLate=IsLate(lastDay);
AddChiDaoColor(isLate,td,row);
}else{ do{
//与前一次是同一天的记录
if(lastDay.getDate()==theDay.getDate()){
//前面的记录是当日上午的,忽略本次
if(lastAmPM==IsAmPm(theDay)){
if(lastAmPM==1){
td.innerText="已经刷过脸了";
row.appendChild(td);
break;
}else{
//同日下午 刷脸,按最后一次进行记录
}
}
//同日下午刷脸 按最后一次进行记录
var isLate=IsLate(theDay);
AddChiDaoColor(isLate,td,row);
}else{
//本次刷脸时间与前一次不是同一天
if(lastDay.getDay()!=5){
//如果有某一日没有刷卡
var passedDay=parseInt((theDay-lastDay)/1000/86400);
console.log("lastDay.getDate()="+lastDay.getDate());
console.log("theDay.getDate()="+theDay.getDate());
if( passedDay>1 ){
//昨天一天都没来 迟到了不!!
td.innerText="今天是星期"+theDay.getDay()+" ;距离上一次刷脸记录超过"+passedDay+"天了!";
/*
JS实现向表格中动态添加行的方法 function insRow()
{
var x=document.getElementById('myTable').insertRow(0);
var y=x.insertCell(0);
var z=x.insertCell(1);
y.innerHTML="NEW CELL1";
z.innerHTML="NEW CELL2";
} var tr=document.createElement("tr");
tr.insertBefore(td,tr[0]);
var td2=td.cloneNode(true);
td=td2;
content.insertBefore(tr,row);j++;
*/
}
}else{
//上次是周五
var passedDay=parseInt((theDay-lastDay)/1000/86400);
console.log("lastDay.getDate()="+lastDay.getDate());
console.log("theDay.getDate()="+theDay.getDate());
if( passedDay>3 ){
td.innerText="上周五以后 到星期一该上班了 怎么不上班???";
}
} var isLate=IsLate(theDay);
AddChiDaoColor(isLate,td,row); } //最后设置
if(lastDay!=theDay)lastDay=theDay;
if(lastAmPM!=IsAmPm(theDay))lastAmPM=IsAmPm(theDay);
}while(0); } }//遍历每一行 刷脸记录
}//if frame.name="main"
}