<commit_before>"use strict";

if (chrome.storage && Settings.get("vimSync") === true) setTimeout(function() {
  Settings.Sync = {
    storage: chrome.storage.sync,
    doNotSync: ["findModeRawQueryList", "keyboard"],
    fetchAsync: function() {
      var _this = this;
      this.storage.get(null, function(items) {
        var key, value, hasOwn;
        if (chrome.runtime.lastError) {
          return chrome.runtime.lastError;
        }
        hasOwn = Object.prototype.hasOwnProperty;
        for (key in items) {
          if (!hasOwn.call(items, key)) continue;
          value = items[key];
          _this.storeAndPropagate(key, value);
        }
      });
    },
    HandleStorageUpdate: function(changes) {
      var change, key;
      var _this = Settings.Sync, func = Object.prototype.hasOwnProperty;
      for (key in changes) {
        if (!func.call(changes, key)) continue;
        change = changes[key];
        _this.storeAndPropagate(key, change != null ? change.newValue : undefined);
      }
    },
    storeAndPropagate: function(key, value) {
      var defaultValue, defaultValueJSON;
      if (!(key in Settings.defaults)) {
        return;
      }
      if (!this.shouldSyncKey(key)) {
        return;
      }
      if (value && key in localStorage && localStorage[key] === value) {
        return;
      }
      defaultValue = Settings.defaults[key];
      defaultValueJSON = JSON.stringify(defaultValue);
      if (value && value !== defaultValueJSON) {
        value = JSON.parse(value);
      } else {
        value = defaultValue;
      }
      Settings.set(key, value);
    },
    set: function(key, value) {
      if (this.shouldSyncKey(key)) {
        var settings = {};
        settings[key] = value;
        this.storage.set(settings);
      }
    },
    clear: function(key) {
      if (this.shouldSyncKey(key)) {
        this.storage.remove(key);
      }
    },
    shouldSyncKey: function(key) {
      return this.doNotSync.index(key) < 0;
    }
  };
  chrome.storage.onChanged.addListener(Settings.Sync.HandleStorageUpdate);
  Settings.Sync.fetchAsync();
}, 100);

if (chrome.browserAction) setTimeout(function() {
  var func;
  g_requestHandlers.SetIcon = function(tabId, type) {
    chrome.browserAction.setIcon({
      tabId: tabId,
      path: Settings.icons[type]
    });
  };
  func = Settings.updateHooks.showActionIcon;
  Settings.updateHooks.showActionIcon = function (value) {
    func.call(Settings, value);
    if (value) {
      chrome.browserAction.setTitle({
        title: "Vimium++"
      });
      chrome.browserAction.enable();
    } else {
      chrome.browserAction.disable();
      chrome.browserAction.setTitle({
        title: "Vimium++\nThis icon is not in use"
      });
    }
  };
  Settings.postUpdate("showActionIcon");
}, 50);

if (chrome.omnibox) setTimeout(function() {
  var last, firstUrl, lastSuggest, spanRe = /<(\/?)span(?: [^>]+)?>/g,
  tempRequest, timeout = 0, sessionIds,
  defaultSug = { description: "<dim>Open: </dim><url>%s</url>" },
  formatSessionId = function(sug) {
    if (sug.sessionId != null) {
      sessionIds[sug.url] = sug.sessionId;
    }
  },
  format = function(sug) {<commit_msg>delay access to chrome.***, which is loaded lazily<commit_after>"use strict";

setTimeout(function() { if (!chrome.storage || Settings.get("vimSync") !== true) { return; }
  Settings.Sync = {
    storage: chrome.storage.sync,
    doNotSync: ["findModeRawQueryList", "keyboard"],
    fetchAsync: function() {
      var _this = this;
      this.storage.get(null, function(items) {
        var key, value, hasOwn;
        if (chrome.runtime.lastError) {
          return chrome.runtime.lastError;
        }
        hasOwn = Object.prototype.hasOwnProperty;
        for (key in items) {
          if (!hasOwn.call(items, key)) continue;
          value = items[key];
          _this.storeAndPropagate(key, value);
        }
      });
    },
    HandleStorageUpdate: function(changes) {
      var change, key;
      var _this = Settings.Sync, func = Object.prototype.hasOwnProperty;
      for (key in changes) {
        if (!func.call(changes, key)) continue;
        change = changes[key];
        _this.storeAndPropagate(key, change != null ? change.newValue : undefined);
      }
    },
    storeAndPropagate: function(key, value) {
      var defaultValue, defaultValueJSON;
      if (!(key in Settings.defaults)) {
        return;
      }
      if (!this.shouldSyncKey(key)) {
        return;
      }
      if (value && key in localStorage && localStorage[key] === value) {
        return;
      }
      defaultValue = Settings.defaults[key];
      defaultValueJSON = JSON.stringify(defaultValue);
      if (value && value !== defaultValueJSON) {
        value = JSON.parse(value);
      } else {
        value = defaultValue;
      }
      Settings.set(key, value);
    },
    set: function(key, value) {
      if (this.shouldSyncKey(key)) {
        var settings = {};
        settings[key] = value;
        this.storage.set(settings);
      }
    },
    clear: function(key) {
      if (this.shouldSyncKey(key)) {
        this.storage.remove(key);
      }
    },
    shouldSyncKey: function(key) {
      return this.doNotSync.index(key) < 0;
    }
  };
  chrome.storage.onChanged.addListener(Settings.Sync.HandleStorageUpdate);
  Settings.Sync.fetchAsync();
}, 100);

setTimeout(function() { if (!chrome.browserAction) { return; }
  var func = Settings.updateHooks.showActionIcon;
  g_requestHandlers.SetIcon = function(tabId, type) {
    chrome.browserAction.setIcon({
      tabId: tabId,
      path: Settings.icons[type]
    });
  };
  Settings.updateHooks.showActionIcon = function (value) {
    func.call(this, value);
    if (value) {
      chrome.browserAction.setTitle({
        title: "Vimium++"
      });
      chrome.browserAction.enable();
    } else {
      chrome.browserAction.disable();
      chrome.browserAction.setTitle({
        title: "Vimium++\nThis icon is not in use"
      });
    }
  };
  Settings.postUpdate("showActionIcon");
}, 50);

setTimeout(function() { if (!chrome.omnibox) { return; }
  var last, firstUrl, lastSuggest, spanRe = /<(\/?)span(?: [^>]+)?>/g,
  tempRequest, timeout = 0, sessionIds,
  defaultSug = { description: "<dim>Open: </dim><url>%s</url>" },
  formatSessionId = function(sug) {
    if (sug.sessionId != null) {
      sessionIds[sug.url] = sug.sessionId;
    }
  },
  format = function(sug) {
{'fraction_non_alphanumeric': 0.1449906658369633, 'fraction_numerical': 0.0021779713752333543, 'mean_word_length': 2.5976496922216006, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '72305', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1989, 'n_words': 393}