页首Html代码

返回顶部

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

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

刷连记录 类似于这样的:

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

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

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

 

脚本内容为:

  1 /*******************
  2 * FileName   : js_刷脸记录 整理.js
  3 * Description: 在OA网页 刷脸记录中,执行后可显示 是否迟到。
  4 ********************/
  5 // JS 压缩工具:
  6 //http://tool.oschina.net/jscompress
  7 
  8 //===============================================
  9 // 1 加载jQuery
 10 //===============================================
 11 //http://www.cnblogs.com/BearsTaR/archive/2010/08/05/js_include.html
 12 //http://segmentfault.com/q/1010000000469374
 13 //http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file
 14 
 15 //http://www.huoduan.com/jquery-cdn.html
 16 //http://www.bootcdn.cn/jquery/
 17 
 18 function include(jsurl) {
 19     if (jsurl == null || typeof(jsurl) != 'string') return;
 20     var script = document.createElement('script');
 21     script.type = 'text/javascript';
 22     script.charset = 'utf-8';
 23     script.src = jsurl;
 24     /*script.setAttribute("src",jsurl);*/
 25     document.head.appendChild(script);
 26 }
 27 include("http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js");
 28 //===============================================
 29 //2 分析表格
 30 //===============================================
 31 
 32 //$("table.shualian").innerHTML="";
 33 
 34 function IsAmPm(d){
 35     var hour=d.getHours();
 36     //早上 6点到12点 算是上班
 37     if(hour>=0 && hour <=12){
 38         return 1;
 39     }
 40     //中午12点到晚上24点之间 算是下班时间
 41     if(hour >12 && hour <24){
 42         return 2;
 43     }
 44     return 2;
 45 }
 46 
 47 //将秒数 转化为人类可读的字符串
 48 function HumanReadSeconds(mililsSeconds){
 49     mililsSeconds=mililsSeconds/1000;
 50     mililsSeconds=parseInt(mililsSeconds);
 51     //typeof(mililsSeconds)=="number"||typeof(mililsSeconds)=="string"
 52 /*
 53 1.丢弃小数部分,保留整数部分 
 54 js:parseInt(7/2) 
 55 
 56 2.向上取整,有小数就整数部分加1 
 57 js: Math.ceil(7/2) 
 58 
 59 3,四舍五入. 
 60 js: Math.round(7/2) 
 61 
 62 4,向下取整 
 63 js: Math.floor(7/2)
 64 */
 65     var isFushu=mililsSeconds>0?1:-1;
 66     mililsSeconds=Math.abs(mililsSeconds);
 67     var day=0,hour=0,minute=0,second=0;
 68     day=mililsSeconds/86400;
 69     day=parseInt(day);
 70     hour=(mililsSeconds-day*86400)/3600;
 71     hour=parseInt(hour);
 72     minute=(mililsSeconds-day*86400-3600*hour)/60;
 73     minute=parseInt(minute);
 74     second=mililsSeconds-day*86400-3600*hour-minute*60;
 75     second=parseInt(second);
 76     //
 77     var ret="";
 78     if(day>0)
 79         ret=day+"天";
 80     if(hour>0||day>0)
 81         ret+=hour+"小时";
 82     if(minute>0||hour>0||hour>0){
 83         ret+=minute+"分";
 84     }
 85     ret+=second+"秒";
 86     return ret+(isFushu>0?"":"[以前]");
 87 }
 88 //当前时间 打卡算是迟到 或 早退吗
 89 function IsLate(nowDate){
 90     //上午 是 9点01分之前 ;下午是18:00之后
 91     var date2;//当日 迟到时间
 92     console.log("当前时间为:"+nowDate.toLocaleString());
 93     if(IsAmPm(nowDate)==1){
 94         date2=new Date(nowDate.getYear()+1900,
 95             nowDate.getMonth(),/*范围0-11 代表1-12月*/
 96             nowDate.getDate(),
 97             9,
 98             01,
 99             00);
100         console.log("当日 不迟到时间为:"+date2.toLocaleString());
101         console.log("nowDate="+nowDate.valueOf()+"; date2="+date2.valueOf()+"; date2-nowDate="+(date2-nowDate));
102         if( nowDate<date2){
103             return "";
104         }else{
105             return "迟到了"+HumanReadSeconds(nowDate-date2);
106         }
107     }else{
108         date2=new Date(nowDate.getYear()+1900,
109             nowDate.getMonth(),/*范围0-11 代表1-12月*/
110             nowDate.getDate(),
111             18,
112             00,
113             00);
114             
115         console.log("当日 不早退时间为:"+date2.toLocaleString());
116         console.log("nowDate="+nowDate.valueOf()+"; date2="+date2.valueOf()+"; nowDate-date2="+(nowDate-date2));
117         if( nowDate>date2){
118             return "";
119         }else{
120             return "早退了"+HumanReadSeconds(date2-nowDate);
121         }
122     }
123 }
124 
125 function AddChiDaoColor(isLate,td,row){
126     if(isLate.length!=0){
127         //迟到提醒记录 红色 加粗字体
128         td.innerText+=isLate;
129         td.style="color:red;"
130         td.style.color="red";
131         td.style.fontWeight="bold";
132         td.style.backgroundColor="yellow";
133         
134         row.appendChild(td);
135     }else{
136         //无迟到描述空
137         td.innerText+="没有迟到";
138         row.appendChild(td);
139     }
140     
141 }
142 
143 for(var i=0;i<document.getElementsByTagName("frame").length;i++)
144 {
145     if(document.getElementsByTagName("frame")[i].name==="main"){
146         var f=window.top.document.getElementsByTagName("frame")[2];
147         var content=f.contentDocument.getElementsByTagName("table")[2];
148         //var c=$(f.contentDocument.getElementsByTagName("table")[2]);
149         //第一行 是姓名 刷连时间,添加 是否迟到
150         
151         var row0=content.rows[0];
152         var td = document.createElement('td');
153         td.innerText="是否迟到";
154         td.align="center"
155         td.width="10%"
156         row0.appendChild(td)
157         
158         //第二行 到最后一行 分别执行 判断迟到操作
159         var j=0;
160         var lastAmPM=1;//1是上班时间 2是下班时间
161         var lastDay=undefined;
162         while(++j<content.rows.length){
163             var row=content.rows[j];
164             //"刷脸时间"这一列 转化为 时间
165             var theDay = new Date(Date.parse(row.cells[1].innerText.replace(/-/g, "/"))); 
166             console.log("lastDay="+lastDay);
167             var td = document.createElement('td');
168             td.align="center"
169             td.width="10%"
170             
171             if(lastDay===undefined){
172                 //这是第一条记录c
173                 lastDay=theDay;
174                 lastAmPM=IsAmPm(lastDay);//=1 am =2 pm
175                 //console.log("lastDay="+lastDay.toLocaleString());
176                 //console.log("lastAmPM="+lastAmPM);
177                 var isLate=IsLate(lastDay);
178                 AddChiDaoColor(isLate,td,row);
179             }else{
180                 
181                 do{
182                     //与前一次是同一天的记录
183                     if(lastDay.getDate()==theDay.getDate()){
184                         //前面的记录是当日上午的,忽略本次
185                         if(lastAmPM==IsAmPm(theDay)){
186                             if(lastAmPM==1){
187                                 td.innerText="已经刷过脸了";
188                                 row.appendChild(td);
189                                 break;
190                             }else{
191                                 //同日下午 刷脸,按最后一次进行记录
192                             }
193                         }
194                         //同日下午刷脸 按最后一次进行记录
195                         var isLate=IsLate(theDay);
196                         AddChiDaoColor(isLate,td,row);
197                     }else{
198                         //本次刷脸时间与前一次不是同一天
199                         if(lastDay.getDay()!=5){
200                             //如果有某一日没有刷卡
201                             var passedDay=parseInt((theDay-lastDay)/1000/86400);
202                             console.log("lastDay.getDate()="+lastDay.getDate());
203                             console.log("theDay.getDate()="+theDay.getDate());
204                             if( passedDay>1 ){
205                                 //昨天一天都没来 迟到了不!!
206                                 td.innerText="今天是星期"+theDay.getDay()+" ;距离上一次刷脸记录超过"+passedDay+"天了!";
207                                 /*
208                                 JS实现向表格中动态添加行的方法
209                                 
210                                 function insRow()
211                                 {
212                                 var x=document.getElementById('myTable').insertRow(0);
213                                 var y=x.insertCell(0);
214                                 var z=x.insertCell(1);
215                                 y.innerHTML="NEW CELL1";
216                                 z.innerHTML="NEW CELL2";
217                                 }
218 
219                                 var tr=document.createElement("tr");
220                                 tr.insertBefore(td,tr[0]);
221                                 var td2=td.cloneNode(true);
222                                 td=td2;
223                                 content.insertBefore(tr,row);j++;
224                                 */
225                             }
226                         }else{
227                             //上次是周五
228                             var passedDay=parseInt((theDay-lastDay)/1000/86400);
229                             console.log("lastDay.getDate()="+lastDay.getDate());
230                             console.log("theDay.getDate()="+theDay.getDate());
231                             if( passedDay>3 ){
232                                 td.innerText="上周五以后 到星期一该上班了 怎么不上班???";
233                             }
234                         }
235                         
236                         var isLate=IsLate(theDay);
237                         AddChiDaoColor(isLate,td,row);
238                         
239                     }
240                     
241                     //最后设置
242                     if(lastDay!=theDay)lastDay=theDay;
243                     if(lastAmPM!=IsAmPm(theDay))lastAmPM=IsAmPm(theDay);
244                 }while(0);
245                 
246             }
247             
248             
249         }//遍历每一行 刷脸记录
250     }//if frame.name="main"
251 }
View Code

 

posted @ 2015-12-07 11:40  ayanmw  阅读(386)  评论(0编辑  收藏  举报

页脚Html代码