Esempio n. 1
0
;(function () {
  'use strict'

  require('./keyboardNavigation')
  require('./clickReport')
  require('./zoomLevel')
  require('./googleWindowOpen')

  const enUS = require('dictionary-en-us')
  const Spellchecker = require('nodehun')
  enUS((err, result) => {
    if (!err) {
      const spellchecker = new Spellchecker(result.aff, result.dic)
      require('./spellchecker')(spellchecker)
      require('./contextMenu')(spellchecker)
    } else {
      require('./contextMenu')(null)
    }
  })

  // Inject some styles
  const stylesheet = document.createElement('style')
  stylesheet.innerHTML = `
    a[href*="/SignOutOptions"] {
      visibility: hidden !important;
    }
  `
  document.head.appendChild(stylesheet)
})()
  return new Promise((resolve, reject) => {
    if (!SpellChecker) {
      console.log("SpellChecker being initialied.");
      dictionary(function(error, dict) {
        if (error) {
          // TODO: We should swallow this error and make the spell checker optional.
          // Currently code/tests assumes that SpellChecker is always available.
          console.log(`Error initializing the dictionary. Error: ${error}`);
          reject(error);
          return;
        }

        // Need to check if this is prohibitively expensive in prod env.

        // This is an expensive operation. SpellChecker should be made optional.
        // The load should be kicked off so subsequent requests can benefit from it
        // but the current session shouldn't be blocked on this.
        SpellChecker = nspell(dict);

        dictionaryAdditions.forEach(wordToBeAdded => {
          SpellChecker.add(wordToBeAdded);
        });

        resolve();
      });
    } else {
      resolve();
    }
  });