document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('select[name="category_ids[]"][multiple]').forEach(function (select) {
    if (select.dataset.checkboxReady) return;
    select.dataset.checkboxReady = '1';
    var wrap = document.createElement('div');
    wrap.className = 'category-checkbox-list';
    Array.prototype.forEach.call(select.options, function (option) {
      var label = document.createElement('label');
      label.className = 'category-checkbox';
      var input = document.createElement('input');
      input.type = 'checkbox'; input.checked = option.selected;
      input.addEventListener('change', function () { option.selected = input.checked; });
      label.appendChild(input); label.appendChild(document.createTextNode(' ' + option.text)); wrap.appendChild(label);
    });
    select.style.display = 'none'; select.parentNode.insertBefore(wrap, select.nextSibling);
  });
});
