<commit_before>import _ from 'lodash';

const defaultStoreStructure = {
  settings: {
    wideScreen: true,
    threadPreview: true,
    adsRemove: true,
    linkHelper: true,
    notifyQuote: true,
    emotionHelper: true,
    minimizeQuote: true,
    quickPostQuotation: true,
    delay: 1, // minute
  },
  authInfo: {},
  quotes: [],
  quickLinks: [
    {
      id: 'voz_living_f17',
      label: 'F17',
      link: 'https://vozforums.com/forumdisplay.php?f=17',
    },
  ],
  followThreads: {},
  threadTracker: {},
  currentPost: {},
};

export default defaultStoreStructure;

const defaultSettingKeys = _.keys(defaultStoreStructure);

/* eslint-disable no-undef */
export const getChromeLocalStore = (keys = defaultSettingKeys) => (
  new Promise(resolve => {
    chrome.storage.local.get(keys, items => {
      if (_.isEmpty(items)) {
        const result = { };
        let outKeys = keys;
        if (_.isString(outKeys)) {
          outKeys = [outKeys];
        }
        outKeys.forEach(key => {
          result[key] = defaultStoreStructure[key];
        });
        resolve(result);
      } else {
        const result = items;
        keys.forEach(key => {
          if (_.isUndefined(result[key])) {
            result[key] = defaultStoreStructure[key];
          }
        });
        resolve(result);
      }
    });
  })
);

export const setChromeLocalStore = items => (
  new Promise(resolve => {
    chrome.storage.local.set(items, () => resolve(true));
  })
);
/* eslint-enable no-undef */<commit_msg>switch to use sync storage<commit_after>import _ from 'lodash';

const defaultStoreStructure = {
  settings: {
    wideScreen: true,
    threadPreview: true,
    adsRemove: true,
    linkHelper: true,
    notifyQuote: true,
    emotionHelper: true,
    minimizeQuote: true,
    quickPostQuotation: true,
    delay: 1, // minute
  },
  authInfo: {},
  quotes: [],
  quickLinks: [
    {
      id: 'voz_living_f17',
      label: 'F17',
      link: 'https://vozforums.com/forumdisplay.php?f=17',
    },
  ],
  followThreads: {},
  threadTracker: {},
  currentPost: {},
};

export default defaultStoreStructure;

const defaultSettingKeys = _.keys(defaultStoreStructure);

/* eslint-disable no-undef */
export const getChromeLocalStore = (keys = defaultSettingKeys) => (
  new Promise(resolve => {
    chrome.storage.sync.get(keys, items => {
      if (_.isEmpty(items)) {
        const result = { };
        let outKeys = keys;
        if (_.isString(outKeys)) {
          outKeys = [outKeys];
        }
        outKeys.forEach(key => {
          result[key] = defaultStoreStructure[key];
        });
        resolve(result);
      } else {
        const result = items;
        keys.forEach(key => {
          if (_.isUndefined(result[key])) {
            result[key] = defaultStoreStructure[key];
          }
        });
        resolve(result);
      }
    });
  })
);

export const setChromeLocalStore = items => (
  new Promise(resolve => {
    chrome.storage.sync.set(items, () => resolve(true));
  })
);
/* eslint-enable no-undef */
{'fraction_non_alphanumeric': 0.1445861956166176, 'fraction_numerical': 0.004579653254824992, 'mean_word_length': 2.447576099210823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '2718584', 'n_tokens_mistral': 965, 'n_tokens_neox': 948, 'n_words': 182}