Last active
January 22, 2025 10:03
-
-
Save creasty/e1215795a31432e04d0b725c3bd030be to your computer and use it in GitHub Desktop.
Akashi で埋まっていないところを勝手に埋めてくれるくん
This file contains hidden or 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
| (() => { | |
| /** 出勤時刻 (HH:MM) */ | |
| const START_TIME = '10:00'; | |
| /** 退勤時刻 (HH:MM) */ | |
| const END_TIME = '19:30'; | |
| /** 退勤時刻のしきい値 (この時刻以降は退勤とみなす) */ | |
| const END_TIME_THRESHOLD = '17:00'; | |
| /** 勤務時間の変動幅の下限 (分単位) */ | |
| const WORKING_HOUR_FLUCTUATION_MIN = -30; | |
| /** 勤務時間の変動幅の上限 (分単位) */ | |
| const WORKING_HOUR_FLUCTUATION_MAX = 90; | |
| function addMinutes(time, minutes) { | |
| const date = new Date(`2000/1/1 ${time}`); | |
| // 繰り上げを考慮して分を加算 | |
| date.setMinutes(date.getMinutes() + minutes); | |
| // 時刻を HH:MM 形式の文字列に変換 | |
| return date.toTimeString().slice(0, 5); | |
| } | |
| function generateWorkingHours() { | |
| // 全体での変動幅をランダムに決定 → 出勤と退勤にランダムな割合で分配 というロジック | |
| const fluctuation = WORKING_HOUR_FLUCTUATION_MIN + Math.random() * (WORKING_HOUR_FLUCTUATION_MAX - WORKING_HOUR_FLUCTUATION_MIN); | |
| const splitter = Math.random(); | |
| const startTimeShift = Math.floor(fluctuation * splitter); | |
| const endTimeShift = Math.floor(fluctuation * (1 - splitter)); | |
| return { | |
| startTime: addMinutes(START_TIME, startTimeShift), | |
| endTime: addMinutes(END_TIME, endTimeShift), | |
| }; | |
| } | |
| window.generateWorkingHours = generateWorkingHours; // export | |
| function populateWorkingHours( | |
| /** 強制的に上書き */ | |
| force = false | |
| ) { | |
| document.querySelectorAll('tr[data-working-record-id]').forEach((tr) => { | |
| const kinmu = tr.querySelector('td:nth-child(4)'); // 勤務状況 | |
| const start = tr.querySelector('input[name*=result_start_time_text]'); // 実績(出) | |
| const end = tr.querySelector('input[name*=result_end_time_text]'); // 実績(退) | |
| // 勤務日以外は無視する | |
| if (kinmu?.innerText.trim() !== '勤務') return; | |
| // 入力欄が見つからない場合は無視する | |
| if (!start || !end) return; | |
| // 退勤時刻が出勤時刻に間違えて入っている場合は入れ替える | |
| if (!end.value && start.value && start.value >= END_TIME_THRESHOLD) { | |
| end.value = start.value; | |
| start.value = ''; | |
| } | |
| // 勤務時間を生成 | |
| const { startTime, endTime } = generateWorkingHours(); | |
| // 出勤時刻を入力 | |
| if (force || !start.value) { | |
| start.value = startTime; | |
| start.dispatchEvent(new Event('blur')); | |
| } | |
| // 退勤時刻を入力 | |
| if (force || !end.value) { | |
| end.value = endTime; | |
| end.dispatchEvent(new Event('blur')); | |
| } | |
| }); | |
| } | |
| window.populateWorkingHours = populateWorkingHours; // export | |
| // ボタンを追加 | |
| const header = document.querySelector('.c-tool-header.js-sticky-header'); | |
| if (header) { | |
| const button = document.createElement('button'); | |
| button.className = | |
| 'c-tool-header__button c-tool-header__button--save c-button c-button--medium c-button--blue'; | |
| button.innerText = '自動入力'; | |
| button.onclick = (e) => { | |
| e.preventDefault(); | |
| populateWorkingHours(); | |
| }; | |
| header.append(button); | |
| } | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://atnd-awj.ak4.jp/ja/attendanceで利用します「自動入力」のボタンを押すと空欄がすべて入力がされるので、最後に「一覧の修正を確定」を押して完了です。