Last active
February 1, 2018 02:56
-
-
Save bbq-all-stars/1f818085f7f67c89be3a143b7926c2d5 to your computer and use it in GitHub Desktop.
ネクストIC 時間集計用Bookmaklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var allSum = 0; | |
var dt = new Date(); | |
var curYYYYMMDD = ( dt.getFullYear() + ("0"+(dt.getMonth() + 1)).slice(-2) + ("0"+dt.getDate()).slice(-2) ) * 1; | |
var selectedYYYYMM = $('#year_month').val() * 100, sumCell; | |
//丸め処理(15分) | |
var doRound = function(v, floor = true, step = 15){ | |
return (floor ? Math.floor : Math.ceil)(v / step) * step; | |
}; | |
//休憩時間引く | |
var oTime = function(m){ | |
var dMap = {5:1, 12.5:1.5, 16:2, 24:2.5}; | |
var perV = 0, curV; | |
for(var h in dMap){ | |
curV = dMap[h]; | |
if(m <= 60 * h){ | |
return Math.min(m - 60 * perV, 60 * (h - curV)); | |
} | |
perV = curV; | |
} | |
}; | |
var calTm = function(cls){ | |
var roundMethod = [Math.ceil, Math.floor];//出社時間は切上、退社は切り捨て | |
var scds = [-1, -1, -1, -1], mt; | |
for(var j = 0; j < cls.length; j++){ | |
if(mt = cls[j].match(/(\d+):(\d+)/)){ | |
scds[j] = mt[1] * 60 + doRound(mt[2], j % 2); | |
} | |
} | |
var tmsum = 0; | |
if(scds[2] < 0 && scds[3] < 0){ | |
scds[2] = scds[3] = scds[0]; | |
} | |
if(0 <= scds[0] && scds[0] <= scds[2] && scds[2] <= scds[1]){ | |
tmsum = oTime((scds[1] - scds[0]) - (scds[3] - scds[2])); | |
} | |
return tmsum; | |
}; | |
var m2h = function(m){ | |
return Math.floor(m / 60) + (':0' + (m % 60)).replace(/0(?=..)/, ''); | |
}; | |
$('.table-responsive>table tr').each(function(i, e){ | |
var cls = $(':nth-child(n+6):nth-child(-n+9)', e); | |
var lst = cls[3]; | |
var n = e.insertBefore(lst.cloneNode(true), lst.nextSibling); | |
var rowYYYYMMDD = selectedYYYYMM + i; | |
if(i == 0){ | |
sumCell = n; | |
return; | |
}else if(rowYYYYMMDD > curYYYYMMDD){ | |
return; | |
} | |
cls.each(function(j, f){ cls[j] = $('span', f).text();}); | |
tmsum = calTm(cls); | |
if((rowYYYYMMDD == curYYYYMMDD) && (!tmsum)){ | |
cls[1] = dt.toLocaleTimeString().match(/..?:../)[0]; | |
tmsum = calTm(cls); | |
} | |
if(tmsum){ | |
allSum += tmsum; | |
n.innerHTML = m2h(tmsum); | |
} | |
}); | |
sumCell.innerHTML = '合計<br>' + m2h(allSum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
minify用スクリプト
出力された文字列をブックマーックレットとして貼り付ける。