<commit_before>Components.utils.import('resource://gre/modules/AddonManager.jsm')

module.exports = Zotero.BetterBibTeX || {}

if !Zotero.BetterBibTeX
  debug = require('./debug.coffee')
  flash = require('./flash.coffee')
  edtf = require('edtf')
  events = require('./events.coffee')
  zotero_config = require('./zotero-config.coffee')

  debug('Loading Better BibTeX')

  Prefs = require('./prefs.coffee') # needs to be here early, initializes the prefs observer

  # TODO: remove after beta
  Zotero.Prefs.get('debug.store', true)
  Zotero.Debug.setStore(true)

  Translators = require('./translators.coffee')
  DB = require('./db/main.coffee')
  CACHE = require('./db/cache.coffee')
  Serializer = require('./serializer.coffee')
  Citekey = require('./keymanager/get-set.coffee')
  JournalAbbrev = require('./journal-abbrev.coffee')
  AutoExport = require('./auto-export.coffee')

  module.exports.KeyManager = KeyManager = require('./keymanager.coffee')

  ###
    UNINSTALL
  ###

  AddonManager.addAddonListener({
    onUninstalling: (addon, needsRestart) ->
      return unless addon.id == '<EMAIL>'

      for label, metadata of Translators.byName
        try
          Translators.uninstall(label, metadata.translatorID)

      try
        panePersist = JSON.parse(Zotero.Prefs.get('pane.persist'))
        if panePersist['zotero-items-column-citekey']
          delete panePersist['zotero-items-column-citekey']
          Zotero.Prefs.set('pane.persist', JSON.stringify(panePersist))
      catch err
        debug('Could not remove zotero-items-column-citekey:', err)
      return

    onOperationCancelled: (addon, needsRestart) ->
      return unless addon.id == '<EMAIL>'
      return if addon.pendingOperations & AddonManager.PENDING_UNINSTALL

      for id, header of Translators.byId
        try
          Translators.install(header)

      return
  })

  ###
    MONKEY PATCHES
  ###

  # otherwise the display of the citekey in the item pane flames out
  Zotero.ItemFields.isFieldOfBase = ((original) ->
    return (field, baseField) ->
      return false if field in ['citekey', 'itemID']
      return original.apply(@, arguments)
  )(Zotero.ItemFields.isFieldOfBase)
  # because the zotero item editor does not check whether a textbox is read-only. *sigh*
  Zotero.Item::setField = ((original) ->
    return (field, value, loadIn) ->
      return original.apply(@, arguments) unless field in ['citekey', 'itemID']<commit_msg>must be something along these lines #norelease<commit_after>Components.utils.import('resource://gre/modules/AddonManager.jsm')

module.exports = Zotero.BetterBibTeX || {}

if !Zotero.BetterBibTeX
  debug = require('./debug.coffee')
  flash = require('./flash.coffee')
  edtf = require('edtf')
  events = require('./events.coffee')
  zotero_config = require('./zotero-config.coffee')

  debug('Loading Better BibTeX')

  Prefs = require('./prefs.coffee') # needs to be here early, initializes the prefs observer

  # TODO: remove after beta
  Zotero.Prefs.get('debug.store', true)
  Zotero.Debug.setStore(true)

  Translators = require('./translators.coffee')
  DB = require('./db/main.coffee')
  CACHE = require('./db/cache.coffee')
  Serializer = require('./serializer.coffee')
  Citekey = require('./keymanager/get-set.coffee')
  JournalAbbrev = require('./journal-abbrev.coffee')
  AutoExport = require('./auto-export.coffee')

  module.exports.KeyManager = KeyManager = require('./keymanager.coffee')

  ###
    UNINSTALL
  ###

  AddonManager.addAddonListener({
    onUninstalling: (addon, needsRestart) ->
      return unless addon.id == '<EMAIL>'
      debug('uninstall')

      for label, metadata of Translators.byName
        try
          Translators.uninstall(label, metadata.translatorID)

      column.removeAttribute('zotero-perist') if column = document.getElementById('zotero-items-column-citekey')

      return

    onOperationCancelled: (addon, needsRestart) ->
      return unless addon.id == '<EMAIL>'
      return if addon.pendingOperations & AddonManager.PENDING_UNINSTALL

      for id, header of Translators.byId
        try
          Translators.install(header)

      column.setAttribute('zotero-perist', 'width ordinal hidden sortActive sortDirection') if column = document.getElementById('zotero-items-column-citekey')

      return
  })

  ###
    MONKEY PATCHES
  ###

  # otherwise the display of the citekey in the item pane flames out
  Zotero.ItemFields.isFieldOfBase = ((original) ->
    return (field, baseField) ->
      return false if field in ['citekey', 'itemID']
      return original.apply(@, arguments)
  )(Zotero.ItemFields.isFieldOfBase)
  # because the zotero item editor does not check whether a textbox is read-only. *sigh*
  Zotero.Item::setField = ((original) ->
    return (field, value, loadIn) ->
      return original.apply(@, arguments) unless field in ['citekey', 'itemID']
{'fraction_non_alphanumeric': 0.133428981348637, 'fraction_numerical': 0.0, 'mean_word_length': 3.5227062094531973, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '5495634', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1500, 'n_words': 331}