<commit_before>self.addEventListener('push', function(event) {
  var data = event.data ? event.data.json() : null;

  var title = data ? data.title : 'Mercurius';
  var body = data ? data.body : 'Notification';

  event.waitUntil(self.registration.showNotification(title, {
    body: body,
  }));
});<commit_msg>Keep user subscription updated. Fixes #4<commit_after>importScripts('localforage.min.js');

self.addEventListener('push', function(event) {
  var data = event.data ? event.data.json() : null;

  var title = data ? data.title : 'Mercurius';
  var body = data ? data.body : 'Notification';

  event.waitUntil(self.registration.showNotification(title, {
    body: body,
  }));
});

self.addEventListener('pushsubscriptionchange', function(event) {
  event.waitUntil(
    localforage.getItem('token').then(function(token) {
      if (!token) {
        return;
      }

      return self.registration.pushManager.subscribe({ userVisibleOnly: true }).then(function(subscription) {
        var key = subscription.getKey ? subscription.getKey('p256dh') : '';

        return fetch('./updateRegistration', {
          method: 'post',
          headers: {
            'Content-type': 'application/json'
          },
          body: JSON.stringify({
            token: token,
            endpoint: subscription.endpoint,
            key: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : '',
          }),
        });
      });
    })
  );
});
{'fraction_non_alphanumeric': 0.15195071868583163, 'fraction_numerical': 0.0034223134839151265, 'mean_word_length': 2.983651226158038, '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': '2939938', 'n_tokens_mistral': 426, 'n_tokens_neox': 421, 'n_words': 80}