<commit_before>pageflow.Settings = Backbone.Model.extend({
  defaults: {
    volume: 1
  },

  initialize: function() {
    if (window.localStorage) {
      if (localStorage['pageflow.settings']) {
        try {
          this.set(JSON.parse(localStorage['pageflow.settings']));
        }
        catch(e) {
          pageflow.log(e);
        }
      }

      this.on('change', function() {
        localStorage['pageflow.settings'] = JSON.stringify(this);
      });
    }
  }
});

pageflow.settings = new pageflow.Settings();<commit_msg>Improve Local Storage Detection<commit_after>pageflow.Settings = Backbone.Model.extend({
  defaults: {
    volume: 1
  },

  initialize: function() {
    var storage = this.getLocalStorage();

    if (storage) {
      if (storage['pageflow.settings']) {
        try {
          this.set(JSON.parse(storage['pageflow.settings']));
        }
        catch(e) {
          pageflow.log(e);
        }
      }

      this.on('change', function() {
        storage['pageflow.settings'] = JSON.stringify(this);
      });
    }
  },

  getLocalStorage: function() {
    try {
      return window.localStorage;
    }
    catch(e) {
      // Safari throws SecurityError when accessing window.localStorage
      // if cookies/website data are disabled.
      return null;
    }
  }
});

pageflow.settings = new pageflow.Settings();
{'fraction_non_alphanumeric': 0.14443625644804717, 'fraction_numerical': 0.0014738393515106854, 'mean_word_length': 2.288135593220339, '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': '5552753', 'n_tokens_mistral': 415, 'n_tokens_neox': 401, 'n_words': 68}