Last active
August 29, 2015 14:20
-
-
Save quanon/a523dec640dbfc7f9354 to your computer and use it in GitHub Desktop.
j-motto のタイムカードに就業時間の列を追加するための user script
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
// ==UserScript== | |
// @name j-motto Userscript | |
// @namespace quanon | |
// @version 0.1.0 | |
// @author QUANON | |
// @include https://gws45.j-motto.co.jp/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
// @grant none | |
// ==/UserScript== | |
/*global jQuery, MutationObserver*/ | |
(function ($) { | |
'use strict'; | |
var observer, | |
addWorkingTimeToRows, | |
inTimeString, | |
outTimeString, | |
deltaTimeString, | |
inTime, | |
outTime, | |
deltaTime, | |
timePattern; | |
// 付箋を削除する。 | |
$('#dn-tags').remove(); | |
// サイドバーを削除する。 | |
$('#dn-side-wrap').remove(); | |
$('#dn-body').css('padding-left', 0); | |
// タイムカードに就業時刻の列を追加する。 | |
$('#jco-table-list thead tr th[title="退社"]').after('<th class="tcard-th-time" title="就業時間">就業時間</th>'); | |
addWorkingTimeToRows = function () { | |
$('#jco-table-list tbody tr').each(function () { | |
inTimeString = $($(this).find('td')[1]).text(); | |
outTimeString = $($(this).find('td')[4]).text(); | |
timePattern = /^\d{2}:\d{2}$/; | |
if (timePattern.test(inTimeString) === false || timePattern.test(outTimeString) === false) { | |
$($(this).find('td')[4]).after('<td></td>'); | |
return; // next | |
} | |
inTime = new Date('2015-01-01 ' + inTimeString + ':00'); | |
outTime = new Date('2015-01-01 ' + outTimeString + ':00'); | |
deltaTime = new Date(outTime - inTime); | |
deltaTimeString = (('0' + String(deltaTime.getUTCHours())).slice(-2)) + ':' + (('0' + String(deltaTime.getUTCMinutes())).slice(-2)); | |
$($(this).find('td')[4]).after('<td><span>' + deltaTimeString + '</span></td>'); | |
}); | |
}; | |
// 月を変更しても就業時刻の列がきちんと追加されるようにする。 | |
observer = new MutationObserver(addWorkingTimeToRows); | |
observer.observe($('#jco-table-list tbody').get(0), { | |
childList: true | |
}); | |
addWorkingTimeToRows(); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment