<commit_before>function normalizeHex(color) {
  var digits = color.toLowerCase().split('');
  return digits.length === 7 ? digits.join('') : digits[0] + digits[1] + digits[1] + digits[2] + digits[2] + digits[3] + digits[3];
}

document.addEventListener('DOMContentLoaded', function () {
  if (localStorage.input) {
    document.getElementById('css').value = localStorage.input;
  }

  document.getElementById('css').oninput = function () {
    localStorage.input = this.value;
  }

  window.onreset = function () {
    delete localStorage.input;
  }
});

document.forms[0].onsubmit = function (e) {
  var css = document.getElementById('css').value;
  var matches = css.match(/#[0-9A-Fa-f]{3}([0-9A-Fa-f]{3})?/g);
  var res = {};

  matches.forEach(function (i) {
    i = normalizeHex(i);
    res[i] ? res[i]++ : res[i] = 1;
  });

  var result = document.createElement('div');
  result.id = 'result'

  for (var x in res) {
    var div = document.createElement('div');
    div.className = 'color';
    div.style.backgroundColor = x;
    div.title = x + ' (' + res[x] + ')';
    if (x === '#ffffff') {
      div.style.boxShadow = 'inset 0 0 0 1px #eee';
    }
    result.appendChild(div)
  }
  document.body.appendChild(result);
  location.href = '#result';
  e.preventDefault();
};<commit_msg>Refactored JS<commit_after>function normalize(color) {
  if (color.length === 4) {
    var chars = color.split('');
    color = chars[0] +
      chars[1] + chars[1] +
      chars[2] + chars[2] +
      chars[3] + chars[3];
  }

  return color.toLowerCase();
}

document.addEventListener('DOMContentLoaded', function () {
  var inputElement = document.getElementById('css');

  if (localStorage.input) {
    inputElement.value = localStorage.input;
  }

  inputElement.oninput = function () {
    localStorage.input = this.value;
  };

  window.onreset = function () {
    delete localStorage.input;
  };

  document.forms[0].onsubmit = function (e) {
    var colors = inputElement.value.match(/#[0-9A-Fa-f]{3}([0-9A-Fa-f]{3})?/g);
    var swatches = {};

    colors.forEach(function (color) {
      color = normalize(color);
      swatches[color] ? swatches[color]++ : swatches[color] = 1;
    });

    var resultElement = document.createElement('div');
    resultElement.id = 'result';

    // TODO: Sort swatches by times used

    for (var color in swatches) {
      if (swatches.hasOwnProperty(color)) {
        var swatchElement = document.createElement('div');

        swatchElement.className = 'color';
        swatchElement.title = color + ' ×' + swatches[color];

        swatchElement.style.backgroundColor = color;
        if (color === '#ffffff') {
          swatchElement.style.boxShadow = 'inset 0 0 0 1px #eee';
        }

        resultElement.appendChild(swatchElement);
      }
    }

    document.body.appendChild(resultElement);
    location.href = '#result';

    e.preventDefault();
  };
});
{'fraction_non_alphanumeric': 0.1703372333103923, 'fraction_numerical': 0.013764624913971095, 'mean_word_length': 3.152857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3250710', 'n_tokens_mistral': 1001, 'n_tokens_neox': 940, 'n_words': 180}