<commit_before>var util2 = require('util2');

var Settings = module.exports;

var state;

Settings.settingsUrl = 'http://meiguro.com/simplyjs/settings.html';

Settings.init = function() {
  state = Settings.state = {
    options: {},
    listeners: [],
  };
  // Register listeners for the Settings
  Pebble.addEventListener('showConfiguration', Settings.onOpenConfig);
  Pebble.addEventListener('webviewclosed', Settings.onCloseConfig);
};

Settings.mainScriptUrl = function(scriptUrl) {
  if (typeof scriptUrl === 'string' && scriptUrl.length && !scriptUrl.match(/^(\w+:)?\/\//)) {
    scriptUrl = 'http://' + scriptUrl;
  }
  if (scriptUrl) {
    localStorage.setItem('mainJsUrl', scriptUrl);
  } else {
    scriptUrl = localStorage.getItem('mainJsUrl');
  }
  return scriptUrl;
};

var getOptionsKey = function(path) {
  return 'options:' + path;
};

Settings.saveOptions = function(path) {
  var options = state.options;
  localStorage.setItem(getOptionsKey(path), JSON.stringify(options));
};

Settings.loadOptions = function(path) {
  state.options = {};
  var options = localStorage.getItem(getOptionsKey(path));
  try {
    options = JSON.parse(options);
  } catch (e) {}
  if (typeof options === 'object' && options !== null) {
    state.options = options;
  }
};

Settings.option = function(key, value) {
  var options = state.options;
  if (arguments.length === 1) {
    return options[key];
  }
  if (typeof value === 'undefined' || value === null) {
    delete options[key];
  } else {
    try {
      value = JSON.parse(value);
    } catch (e) {}
    options[key] = value;
  }
  Settings.saveOptions();
  return value;
};

Settings.getBaseOptions = function() {
  return {
    scriptUrl: Settings.mainScriptUrl(),
  };
};

Settings.config = function(opt, open, close) {
  if (typeof opt === 'string') {
    opt = { url: opt };
  }
  if (typeof close === 'undefined') {
    close = open;
    open = util2.noop;
  }
  var listener = {
    params: opt,
    open: open,
    close: close,
  };
  state.listeners.push(listener);
};

Settings.onOpenConfig = function(e) {
  console.log("Settings.onOpenConfig");
  var options;
  var url;
  var listener = util2.last(state.listeners);
  if (listener) {
    url = listener.params.url;
    options = state.options;
    e = {
      originalEvent: e,
      options: options,
      url: listener.params.url,
    };
    listener.open(e);
  } else {
    url = Settings.settingsUrl;
    options = Settings.getBaseOptions();
  }<commit_msg>Disable default settings configurable<commit_after>var util2 = require('util2');

var Settings = module.exports;

var state;

Settings.settingsUrl = 'http://meiguro.com/simplyjs/settings.html';

Settings.init = function() {
  state = Settings.state = {
    options: {},
    listeners: [],
  };
  // Register listeners for the Settings
  Pebble.addEventListener('showConfiguration', Settings.onOpenConfig);
  Pebble.addEventListener('webviewclosed', Settings.onCloseConfig);
};

Settings.mainScriptUrl = function(scriptUrl) {
  if (typeof scriptUrl === 'string' && scriptUrl.length && !scriptUrl.match(/^(\w+:)?\/\//)) {
    scriptUrl = 'http://' + scriptUrl;
  }
  if (scriptUrl) {
    localStorage.setItem('mainJsUrl', scriptUrl);
  } else {
    scriptUrl = localStorage.getItem('mainJsUrl');
  }
  return scriptUrl;
};

var getOptionsKey = function(path) {
  return 'options:' + path;
};

Settings.saveOptions = function(path) {
  var options = state.options;
  localStorage.setItem(getOptionsKey(path), JSON.stringify(options));
};

Settings.loadOptions = function(path) {
  state.options = {};
  var options = localStorage.getItem(getOptionsKey(path));
  try {
    options = JSON.parse(options);
  } catch (e) {}
  if (typeof options === 'object' && options !== null) {
    state.options = options;
  }
};

Settings.option = function(key, value) {
  var options = state.options;
  if (arguments.length === 1) {
    return options[key];
  }
  if (typeof value === 'undefined' || value === null) {
    delete options[key];
  } else {
    try {
      value = JSON.parse(value);
    } catch (e) {}
    options[key] = value;
  }
  Settings.saveOptions();
  return value;
};

Settings.getBaseOptions = function() {
  return {
    scriptUrl: Settings.mainScriptUrl(),
  };
};

Settings.config = function(opt, open, close) {
  if (typeof opt === 'string') {
    opt = { url: opt };
  }
  if (typeof close === 'undefined') {
    close = open;
    open = util2.noop;
  }
  var listener = {
    params: opt,
    open: open,
    close: close,
  };
  state.listeners.push(listener);
};

Settings.onOpenConfig = function(e) {
  var options;
  var url;
  var listener = util2.last(state.listeners);
  if (listener) {
    url = listener.params.url;
    options = state.options;
    e = {
      originalEvent: e,
      options: options,
      url: listener.params.url,
    };
    listener.open(e);
  } else {
    url = Settings.settingsUrl;
    options = Settings.getBaseOptions();
    return;
  }
{'fraction_non_alphanumeric': 0.1572807723250201, 'fraction_numerical': 0.002011263073209976, 'mean_word_length': 3.3776408450704225, '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': '1976939', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1597, 'n_words': 341}