亿赛通oa工时自动计算

亿赛通oa工时自动计算脚本 http://jsrun.net/2wsKp.js

目前为 2022-10-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         亿赛通oa工时自动计算
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  亿赛通oa工时自动计算脚本 http://jsrun.net/2wsKp.js
// @author       hangj
// @match        http://192.168.0.26:8080/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=0.26
// @grant        none
// ==/UserScript==

(function () {
    'use strict'; var count = 0
    function average(nums) {
        return (nums.reduce((a, b) => a + b) / nums.length).toFixed(2)
    }
    function percentage(num, total) {
        if (num == 0 || total == 0) {
            return 0
        }
        return Math.round(num / total * 10000) / 100.00
    }
    function createHaha(spans) {
        var haha = {}
        haha.date = spans[0].innerText
        haha.week = spans[1].innerText
        haha.dept = spans[2].innerText
        haha.name = spans[3].innerText
        haha.er = spans[6].innerText
        haha.startTime = new Date(haha.date + " " + spans[4].innerText)
        haha.endTime = new Date(haha.date + " " + spans[5].innerText)
        if (haha.er !== "") {
            haha.endTime.setTime(haha.endTime.getTime() + 1000 * 60 * 60 * 24)
        }
        haha.hour = parseInt(haha.endTime - haha.startTime) / 1000 / 60 / 60
        return haha
    }
    function createHtml(name, value, moreMonth) {
        var currDate = new Date()
        currDate.setHours(0)
        var dayStartTime = currDate.getTime()
        currDate.setDate(1)
        var monthStartTime = currDate.getTime()
        var filterValue = value.filter(o => {
            var time = o.startTime.getTime()
            var monthFlag = true
            if (moreMonth != undefined) {
                monthFlag = moreMonth ? (time >= monthStartTime) : (time < monthStartTime)
            }
            return monthFlag && time < dayStartTime
        })
        var val = average(filterValue.map(o => o.hour))
        return "<br/><span title='" + name + "'>" + name + ":" + val + ",符合率:" + percentage(val, 9.5) + "%</span>"
    }
    function countSecond() {
        var flag = false
        var title = document.getElementsByClassName("wea-new-top-title-breadcrumb")
        var logo = document.getElementsByClassName("e9header-top-logo")
        if (logo.length == 0 && count < 6) {
            flag = true
        } else {
            var tab = document.getElementsByClassName("table")
            var data = document.querySelectorAll("table > tbody > tr")
            if (data.length == 0) {
                flag = true
            } else {
                var hahas = []
                data.forEach(tr => {
                    var spans = tr.querySelectorAll("span.wea-url")
                    hahas.push(createHaha(spans))
                })
                var currM = createHtml("当月平均时长", hahas, true)
                var preM = createHtml("上月平均时长", hahas, false)
                var allM = createHtml("历史平均时长", hahas, undefined)
                title[0].parentNode.innerHTML = title[0].parentNode.innerHTML + currM + preM + allM
            }
        }
        count = count + 1
        if (flag) {
            setTimeout(countSecond, 1000)
        }
    }
    countSecond()
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址