<commit_before>(function () {
  'use strict'

  if (document.readyState === 'complete') {
    startAgateScript()
  } else {
    window.addEventListener('load', startAgateScript)
  }

  function startAgateScript() {
    insertStyles();

    const userId = /^\/\w+\/time\/sheet\/(\d+)/.exec(window.location.pathname)?.[1];

    document
      .querySelectorAll('tr.work:not(.notworkedTr)')
      .forEach((workRow) => {
        const cell = workRow.querySelector('.hourButton')?.parentElement || workRow.querySelector('td:nth-child(3)');
        const infoButton = document.createElement('button');

        infoButton.classList.add('btn', 'ams-btn', 'ams-float-right', 'ams-ml-4');
        infoButton.setAttribute('title', 'Plus d\'informations');
        infoButton.innerHTML = '<i class="fa fa-info"></i>';
        infoButton.addEventListener('click', () => {
          summerize(workRow).catch((e) => {
            console.error('Failed to summerize row');
            console.error(e);
          });
        });

        const checkClockingsButton = document.createElement('a');

        const rowDate = /td-(\d+-\d+-\d+)/.exec(workRow.getAttribute('id'))?.[1];

        checkClockingsButton.classList.add('btn', 'ams-btn', 'ams-float-right', 'ams-ml-4');
        checkClockingsButton.setAttribute('href', getPunchUrl(rowDate));
        checkClockingsButton.setAttribute('title', 'Voir les pointages du jour');
        checkClockingsButton.innerHTML = '<i class="fa fa-history fa-lg"></i>';

        cell.appendChild(checkClockingsButton);
        cell.appendChild(infoButton);

        if (workRow.classList.contains('trToday')) {
          summerize(workRow).catch((e) => {
            console.error('Failed to summerize row');
            console.error(e);
          });
        }
      });

    async function summerize(workRow) {
      const clockingsCell = workRow.querySelector('.hourButton')?.parentElement || workRow.querySelector('td:nth-child(3)');

      if (!clockingsCell) { return; }

      let summary = clockingsCell.querySelector('.ams-summary');

      if (!summary) {
        summary = document.createElement('div');
        summary.classList.add('ams-summary', 'ams-float-right');
        clockingsCell.appendChild(summary);
      }

      summary.innerHTML = '';

      const rowDate = /td-(\d+-\d+-\d+)/.exec(workRow.getAttribute('id'))?.[1];

      const spinnerButton = createSpinnerButton();
      summary.appendChild(spinnerButton);

      let clockings;
      try {
        clockings = await getClockings(rowDate);
      } catch (e) {
        console.error('Failed to download clockings of current date');
        console.error(e);
      } finally {
        summary.removeChild(spinnerButton);
      }

      if (Array.isArray(clockings)) {
        clockings.forEach((clocking) => {
          summary.appendChild(createClockingButton(clocking));
        });
      }

      // We only need to calculate the end of day for the current date
      if (!workRow.classList.contains('trToday')) {
        return;
      }

      const dailyTotal = stringToMinutes(workRow.querySelector('.theoricalColumn')?.textContent);

      let regulation = 0;
      let breakTime = 0;
      let leaveTaken = false;

      workRow
        .querySelectorAll('.hourButton')
        .forEach((item) => {
          if (item.querySelector('i.fa-cutlery')) {
            breakTime += stringToMinutes(item?.textContent);
            return;
          }
          if (item.querySelector('i.icon-os-absence')) {
            leaveTaken = true;
            regulation += stringToMinutes(item?.textContent);
            return;
          }
          if (item.classList.contains('withoutValidation')) {
            regulation += stringToMinutes(item?.textContent);
          }
        });

      const minBreakTime = 45;

      if (!leaveTaken && breakTime === 0) {
        // If there are no break time, use the time between the two first clocking ranges
        // If a leave has been taken, we don't need to regulate the break time

        if (clockings.length >= 2) {
          breakTime = (clockings[1]?.clockIn - clockings[0]?.clockOut) || 0;
        }
        regulation += (breakTime - minBreakTime);
      }

      const remainingButton = document.createElement('button');
      remainingButton.classList.add('btn', 'ams-btn');
      remainingButton.setAttribute('title', 'Temps de travail restant');
      remainingButton.innerHTML = `
        <i class="fa fa-clock-o"></i>
        <span class="text"></span>
      `;

      const endOfDayButton = document.createElement('button');
      endOfDayButton.classList.add('btn', 'ams-btn');
      endOfDayButton.setAttribute('title', 'Fin de la journée');
      endOfDayButton.innerHTML = `
        <i class="fa fa-flag-checkered"></i><commit_msg>fix: don't alter regulation when breaktime is over 45min<commit_after>(function () {
  'use strict'

  if (document.readyState === 'complete') {
    startAgateScript()
  } else {
    window.addEventListener('load', startAgateScript)
  }

  function startAgateScript() {
    insertStyles();

    const userId = /^\/\w+\/time\/sheet\/(\d+)/.exec(window.location.pathname)?.[1];

    document
      .querySelectorAll('tr.work:not(.notworkedTr)')
      .forEach((workRow) => {
        const cell = workRow.querySelector('.hourButton')?.parentElement || workRow.querySelector('td:nth-child(3)');
        const infoButton = document.createElement('button');

        infoButton.classList.add('btn', 'ams-btn', 'ams-float-right', 'ams-ml-4');
        infoButton.setAttribute('title', 'Plus d\'informations');
        infoButton.innerHTML = '<i class="fa fa-info"></i>';
        infoButton.addEventListener('click', () => {
          summerize(workRow).catch((e) => {
            console.error('Failed to summerize row');
            console.error(e);
          });
        });

        const checkClockingsButton = document.createElement('a');

        const rowDate = /td-(\d+-\d+-\d+)/.exec(workRow.getAttribute('id'))?.[1];

        checkClockingsButton.classList.add('btn', 'ams-btn', 'ams-float-right', 'ams-ml-4');
        checkClockingsButton.setAttribute('href', getPunchUrl(rowDate));
        checkClockingsButton.setAttribute('title', 'Voir les pointages du jour');
        checkClockingsButton.innerHTML = '<i class="fa fa-history fa-lg"></i>';

        cell.appendChild(checkClockingsButton);
        cell.appendChild(infoButton);

        if (workRow.classList.contains('trToday')) {
          summerize(workRow).catch((e) => {
            console.error('Failed to summerize row');
            console.error(e);
          });
        }
      });

    async function summerize(workRow) {
      const clockingsCell = workRow.querySelector('.hourButton')?.parentElement || workRow.querySelector('td:nth-child(3)');

      if (!clockingsCell) { return; }

      let summary = clockingsCell.querySelector('.ams-summary');

      if (!summary) {
        summary = document.createElement('div');
        summary.classList.add('ams-summary', 'ams-float-right');
        clockingsCell.appendChild(summary);
      }

      summary.innerHTML = '';

      const rowDate = /td-(\d+-\d+-\d+)/.exec(workRow.getAttribute('id'))?.[1];

      const spinnerButton = createSpinnerButton();
      summary.appendChild(spinnerButton);

      let clockings;
      try {
        clockings = await getClockings(rowDate);
      } catch (e) {
        console.error('Failed to download clockings of current date');
        console.error(e);
      } finally {
        summary.removeChild(spinnerButton);
      }

      if (Array.isArray(clockings)) {
        clockings.forEach((clocking) => {
          summary.appendChild(createClockingButton(clocking));
        });
      }

      // We only need to calculate the end of day for the current date
      if (!workRow.classList.contains('trToday')) {
        return;
      }

      const dailyTotal = stringToMinutes(workRow.querySelector('.theoricalColumn')?.textContent);

      let regulation = 0;
      let breakTime = 0;
      let leaveTaken = false;

      workRow
        .querySelectorAll('.hourButton')
        .forEach((item) => {
          if (item.querySelector('i.fa-cutlery')) {
            breakTime += stringToMinutes(item?.textContent);
            return;
          }
          if (item.querySelector('i.icon-os-absence')) {
            leaveTaken = true;
            regulation += stringToMinutes(item?.textContent);
            return;
          }
          if (item.classList.contains('withoutValidation')) {
            regulation += stringToMinutes(item?.textContent);
          }
        });

      const minBreakTime = 45;

      if (!leaveTaken && breakTime === 0) {
        // If there are no break time, use the time between the two first clocking ranges
        // If a leave has been taken, we don't need to regulate the break time

        if (clockings.length >= 2) {
          breakTime = (clockings[1]?.clockIn - clockings[0]?.clockOut) || 0;
        }
        regulation += Math.min(breakTime - minBreakTime, 0);
      }

      const remainingButton = document.createElement('button');
      remainingButton.classList.add('btn', 'ams-btn');
      remainingButton.setAttribute('title', 'Temps de travail restant');
      remainingButton.innerHTML = `
        <i class="fa fa-clock-o"></i>
        <span class="text"></span>
      `;

      const endOfDayButton = document.createElement('button');
      endOfDayButton.classList.add('btn', 'ams-btn');
      endOfDayButton.setAttribute('title', 'Fin de la journée');
      endOfDayButton.innerHTML = `
        <i class="fa fa-flag-checkered"></i>
{'fraction_non_alphanumeric': 0.1497824735860783, 'fraction_numerical': 0.003625440232028175, 'mean_word_length': 2.569316081330869, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6245247', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2716, 'n_words': 508}