<commit_before>var $ = document;
var el = {
  charging: $.getElementById('charging'),
  chargingTime: $.getElementById('chargingTime'),
  dischargingTime: $.getElementById('dischargingTime'),
  level: $.getElementById('level'),
  battery: $.getElementById('battery'),
  batteryBar: $.getElementById('battery-bar')
};

battery.on('ready', function() {
  console.log('ready');
  console.log('isCharging: ' + battery.isCharging());
  console.log('isDischarging: ' + battery.isDischarging());
  console.log('getChargingTime: ' + battery.getChargingTime());
  console.log('getDischargingTime: ' + battery.getDischargingTime()); // seconds
  console.log('getLevel: ' + battery.getLevel());
  console.log('getPercentage: ' + battery.getPercentage());
  console.log('getStatus: ' + battery.getStatus());

  updateCharging(battery.isCharging());
  updateChargingTime(battery.getChargingTime());
  updateDischargingTime(battery.getDischargingTime());
  updateLevel(battery.getLevel());
});

battery.on('chargingChange', updateCharging);

battery.on('chargingTimeChange', updateChargingTime);

battery.on('dischargingTimeChange', updateDischargingTime);

battery.on('levelChange', updateLevel);

battery.on('error', function(error) {
  alert(error);
  console.error(error);
});

function updateCharging(isCharging) {
  setText(el.charging, isCharging);
}

function updateChargingTime(chargingTime) {
  setText(el.chargingTime, chargingTime + toHMS(chargingTime));
}

function updateDischargingTime(dischargingTime) {
  setText(el.dischargingTime, dischargingTime + toHMS(dischargingTime));
}

function updateLevel(level) {
  setText(el.level, level + toPercent(level));
  var statusClass = 'ok';
  if (level < 0.2) {
    statusClass = 'warning';
  }
  if (level < 0.1) {
    statusClass = 'critical';
  }
  el.batteryBar.style.width = battery.getPercentage() + '%';
  el.batteryBar.setAttribute('class', statusClass);
}

function toPercent(value) {
  return ' (' + (value * 100) + '%)';
}

function toHMS(durationInSeconds) {
  if (!Number.isFinite(durationInSeconds)) return '';
  var hours = Math.floor(durationInSeconds / 3600);
  var seconds = durationInSeconds % 60;
  var minutes = Math.floor((durationInSeconds - hours * 3600 - seconds) / 60);
  return ' (' + hours + 'h:' + minutes + 'm:' + seconds + 's)';
}

function setText(el, t) {
  if (document.all) {
    el.innerText = t;
  } else{
    el.textContent = t;
  }
}<commit_msg>wrapp in iife<commit_after>(function() {
  var el = {
    charging: document.getElementById('charging'),
    chargingTime: document.getElementById('chargingTime'),
    dischargingTime: document.getElementById('dischargingTime'),
    level: document.getElementById('level'),
    battery: document.getElementById('battery'),
    batteryBar: document.getElementById('battery-bar')
  };

  battery.on('ready', function() {
    console.log('ready');
    console.log('isCharging: ' + battery.isCharging());
    console.log('isDischarging: ' + battery.isDischarging());
    console.log('getChargingTime: ' + battery.getChargingTime());
    console.log('getDischargingTime: ' + battery.getDischargingTime()); // seconds
    console.log('getLevel: ' + battery.getLevel());
    console.log('getPercentage: ' + battery.getPercentage());
    console.log('getStatus: ' + battery.getStatus());

    updateCharging(battery.isCharging());
    updateChargingTime(battery.getChargingTime());
    updateDischargingTime(battery.getDischargingTime());
    updateLevel(battery.getLevel());
  });

  battery.on('chargingChange', updateCharging);

  battery.on('chargingTimeChange', updateChargingTime);

  battery.on('dischargingTimeChange', updateDischargingTime);

  battery.on('levelChange', updateLevel);

  battery.on('error', function(error) {
    alert(error);
    console.error(error);
  });

  function updateCharging(isCharging) {
    setText(el.charging, isCharging);
  }

  function updateChargingTime(chargingTime) {
    setText(el.chargingTime, chargingTime + toHMS(chargingTime));
  }

  function updateDischargingTime(dischargingTime) {
    setText(el.dischargingTime, dischargingTime + toHMS(dischargingTime));
  }

  function updateLevel(level) {
    setText(el.level, level + toPercent(level));
    var statusClass = 'ok';
    if (level < 0.2) {
      statusClass = 'warning';
    }
    if (level < 0.1) {
      statusClass = 'critical';
    }
    el.batteryBar.style.width = battery.getPercentage() + '%';
    el.batteryBar.setAttribute('class', statusClass);
  }

  function toPercent(value) {
    return ' (' + (value * 100) + '%)';
  }

  function toHMS(durationInSeconds) {
    if (!Number.isFinite(durationInSeconds)) return '';
    var hours = Math.floor(durationInSeconds / 3600);
    var seconds = durationInSeconds % 60;
    var minutes = Math.floor((durationInSeconds - hours * 3600 - seconds) / 60);
    return ' (' + hours + 'h:' + minutes + 'm:' + seconds + 's)';
  }

  function setText(el, t) {
    if (document.all) {
      el.innerText = t;
    } else{
      el.textContent = t;
    }
  }
})();
{'fraction_non_alphanumeric': 0.15885623510722796, 'fraction_numerical': 0.007545671167593328, 'mean_word_length': 4.659550561797753, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7266048', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1638, 'n_words': 257}