(() => {
  'use strict';
  if ('serviceWorker' in navigator) {
    const manifest = document.querySelector('link[rel="manifest"]');
    const worker = manifest ? new URL('sw.js', manifest.href).href : './sw.js';
    window.addEventListener('load', () => navigator.serviceWorker.register(worker).catch(() => {}));
  }
  const all = document.querySelector('[data-check-all]');
  if (all) {
    all.addEventListener('change', () => document.querySelectorAll('input[name="ids[]"]').forEach(box => { box.checked = all.checked; }));
  }
  document.querySelectorAll('form').forEach(form => {
    form.addEventListener('submit', () => {
      const button = form.querySelector('button[type="submit"],button:not([type])');
      if (button && !button.dataset.ready) {
        button.dataset.ready = '1';
        button.classList.add('busy');
      }
    });
  });
  if (window.adsbygoogle) {
    document.querySelectorAll('.adsbygoogle').forEach(() => {
      try { (window.adsbygoogle = window.adsbygoogle || []).push({}); } catch (_) {}
    });
  }
})();
