AKASHI Show Remaining Hours

Display the remaining required working hours in attendance page.

2023-03-09 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name            AKASHI Show Remaining Hours
// @namespace       https://github.com/SlashNephy
// @version         0.1.0
// @author          SlashNephy
// @description     Display the remaining required working hours in attendance page.
// @description:ja  出勤簿ページに残り必要な労働時間を表示します。
// @homepage        https://scrapbox.io/slashnephy/AKASHI_%E3%81%AE%E6%AE%8B%E3%82%8A%E5%BF%85%E8%A6%81%E5%8A%B4%E5%83%8D%E6%99%82%E9%96%93%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B_UserScript
// @homepageURL     https://scrapbox.io/slashnephy/AKASHI_%E3%81%AE%E6%AE%8B%E3%82%8A%E5%BF%85%E8%A6%81%E5%8A%B4%E5%83%8D%E6%99%82%E9%96%93%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B_UserScript
// @icon            https://www.google.com/s2/favicons?sz=64&domain=atnd.ak4.jp
// @supportURL      https://github.com/SlashNephy/.github/issues
// @match           https://atnd.ak4.jp/attendance
// @grant           none
// @license         MIT license
// ==/UserScript==

document.addEventListener('DOMNodeInserted', () => {
    const b = document.querySelector('#time-card-accordion-02 > div > div > table > tbody > tr > td:nth-child(2) > span');
    if (b === null || b.textContent?.includes('(') !== false) {
        return;
    }
    const [a1, a2] = document
        .querySelector('#time-card-accordion-02 > div > div > table > tbody > tr > td:nth-child(1) > span')
        ?.textContent?.trim()
        .split(':') ?? [];
    const [b1, b2] = b.textContent.trim().split(':');
    const [c1, c2] = document
        .querySelector('#time-card-accordion-02 > div > div > table > tbody > tr > td:nth-child(3) > span')
        ?.textContent?.trim()
        .split(':') ?? [];
    let h = parseInt(a1, 10) - parseInt(b1, 10) - parseInt(c1, 10);
    let m = parseInt(a2, 10) - parseInt(b2, 10) - parseInt(c2, 10);
    if (m < 0) {
        h -= Math.ceil(-m / 60);
        m = 60 + (m % 60);
    }
    const d = (h + m / 60) / 8;
    b.textContent += ` (-${h}:${m} = -${d.toFixed(2)} d)`;
});