Newer
Older
verification / script.js
@ahiko ahiko on 5 Dec 2024 1 KB Update script.js
document.getElementById('csvFileInput').addEventListener('change', handleFile);

function handleFile(event) {
  const file = event.target.files[0];
  if (file) {
    const reader = new FileReader();
    reader.onload = function (e) {
      const text = e.target.result;
      processCSV(text);
    };
    reader.readAsText(file);
  }
}

function processCSV(data) {
  const rows = data.split('\n'); // 改行で分割
  const tableBody = document.querySelector('#csvTable tbody');
  tableBody.innerHTML = ''; // 既存データをクリア

  rows.forEach(row => {
    const cols = row.split(','); // カンマで分割
    if (cols.length > 1) {
      const tr = document.createElement('tr');
      
      // データ列
      const dataCell = document.createElement('td');
      dataCell.textContent = cols[0];
      tr.appendChild(dataCell);

      // チェックマーク列
      const checkCell = document.createElement('td');
      if (cols[1].trim().toLowerCase() === 'yes') {
        checkCell.innerHTML = '✅'; // Yesの場合
      } else if (cols[1].trim().toLowerCase() === 'no') {
        checkCell.innerHTML = '❌'; // Noの場合
      }
      tr.appendChild(checkCell);

      tableBody.appendChild(tr);
    }
  });
}