Java script for bookmarklet data extraction from an html monthly calendar schedule

I have a bookmarklet and java script with which I am extracting data from an html table from a website.
For the most part the script works fine however it parses the date wrong. The date, in the HTML table,
shows up only once for a particular day, it’s a schedule table with client bookings, but I need
to have the date on each parsed line so I have the script add it to each line of the parsed text.

See the actual HTML of the first three rows of the table at the bottom of the post. The names have been randomized.

This is the result the script outputs currently:

2024-08-02,40P 02:30N
2024-08-02,40P 02:30N
2024-08-02,40P 03:20N,10963 Jane Doe
2024-08-02,40P 04:10N
2024-08-02,40P 04:10N
2024-08-02,40P 05:00N
2024-08-02,40P 05:00N
2024-08-02,40P 06:00N,M7967 Mary Jane
2024-08-02,40P 06:50N,10840 Samurai Jack
2024-08-02,40P 07:40N,11286 Soldier Boy
2024-08-02,40P 11:00N,1498 John Oliver
2024-08-02,40P 11:50N,5750 Tommy Jones
2024-08-02,40P 01:20N,3846 Super Mario(Z)
2024-08-02,40P 02:10N,5136 Cold Spring
2024-08-02,40P 03:00N,5136 Cold Spring
2024-08-02,40P 04:10N,8606 The Duke
2024-08-02,60G 05:00N

This is what I want it to output:

2024-08-02,40P 02:30N
2024-08-02,40P 02:30N
2024-08-02,40P 03:20N,10963 Jane Doe
2024-08-02,40P 04:10N
2024-08-02,40P 04:10N
2024-08-02,40P 05:00N
2024-08-02,40P 05:00N
2024-08-02,40P 06:00N,M7967 Mary Jane
2024-08-02,40P 06:50N,10840 Samurai Jack
2024-08-02,40P 07:40N,11286 Soldier Boy
2024-08-03,40P 11:00N,1498 John Oliver
2024-08-03,40P 11:50N,5750 Tommy Jones
2024-08-03,40P 01:20N,3846 Super Mario(Z)
2024-08-03,40P 02:10N,5136 Cold Spring
2024-08-03,40P 03:00N,5136 Cold Spring
2024-08-03,40P 04:10N,8606 The Duke
2024-08-03,60G 05:00N

Notice the date change here 2024-08-03,40P 11:00N,1498 John Oliver. The script does not detect the date change
in the html and keeps on going with the 2nd, the next date change it does detect is the 5th.The date in html is <a href="/instructor/reserve/daily/D_2024-08-02/S_/">.

<table class="ta01" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="bg01013E" width="14%"><span class="wday0">Su</span></th><th class="bg01013E" width="14%"><span class="wday1">Mo</span></th><th class="bg01013E" width="14%"><span class="wday2">Tu</span></th><th class="bg01013E" width="14%"><span class="wday3">We</span></th><th class="bg01013E" width="14%"><span class="wday4">Th</span></th><th class="bg01013E" width="14%"><span class="wday5">Fr</span></th><th class="bg01013E" width="14%"><span class="wday6">Sa</span></th>
</tr>
<tr>
<td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;" class="wdate4">01</div>
        </div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-02/S_/"><span class="wdate5">02</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 02:30N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 02:30N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10963 Jane Doe</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 04:10N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 04:10N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:00N</div><div style="color:#f00; font-weight: bold; background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;"><span class="is_method">M</span>7967 Mary Jane</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10840 Samurai Jack</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 07:40N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">11286 Soldier Boy</div></div></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-03/S_/"><span class="wdate6">03</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 11:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">1498 John Oliver</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 11:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5750 Tommy Jones</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 01:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">3846 Super Mario(Z)</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 02:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5136 Cold Spring</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5136 Cold Spring</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 04:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">8606 The Duke</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_gr " style="font-size:11px;">60G 05:00N</div></div></div>
        </td>
</tr>

<tr>
<td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;" class="wdate0">04</div>
        </div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-05/S_/"><span class="wdate1">05</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 02:30N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">0858 Magellan</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">11206 Little Car</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 04:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10402 Big Tom/10578 Little Tom</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">4577 Sunflower</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr capa_full" style="font-size:11px;">40P 06:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">7367 Jane Doe(Z)/7366 John Doe(Z)</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 07:40N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 07:40N</div></div></div>
        </td><td style="padding:0;">

And here is the script:

javascript:(function() {
  var table = document.querySelector('table.ta01[cellpadding="0"][cellspacing="0"][border="0"]');
  var output = [];
  var rowData = [];
  var currentDate = "";

  if (table) {
    table.querySelectorAll('tr').forEach(function(row) {
      var dateLinks = row.querySelectorAll('a[href^="/instructor/reserve/daily/D_"]');
      currentDate = dateLinks.length > 0 ? dateLinks[0].getAttribute('href').match(/D_(d{4}-d{2}-d{2})/)[1] : "";

      row.querySelectorAll('div[class^="ico_"]').forEach(function(div) {
        var text = div.textContent.trim();
        var extraInfo = div.nextElementSibling;

        if (extraInfo && extraInfo.style && extraInfo.style.backgroundColor == "rgb(211, 229, 237)") {
          text += "," + extraInfo.textContent.trim();
        }

        if (text) {
          rowData.push(text);
        }
      });

      if (rowData.length > 0) {
        rowData = rowData.map(function(line) {
          return currentDate + "," + line;
        });
      }

      output = output.concat(rowData);
      rowData = [];
    });

    var csv = "data:text/csv;charset=utf-8," + encodeURIComponent(output.join("n"));
    var link = document.createElement("a");
    link.href = csv;
    link.download = "schedule.csv";
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  } else {
    alert("Table not found!");
  }
})()