<commit_before><script>
  // FIXME: setting color to auto does not clear color

  /** GLOBAL STATE **/
  /* =============================================*/

  let tempSettings = {}
  let refCodes = []


  /* LIBRARY FUNCTIONS */
  /* =============================================*/

  const getColorStr = colorHex => colorHex?.slice(1)

  const isValidColor = color => /(#|^)([0-9A-f]{3}|[0-9A-f]{6})$/.test(color)

  const doubleEach = (acc, cur) => acc + cur + cur

  const arrayMinus = (arr, item) => arr.filter(a => a !== item)

  const htmlEncode = str => String(str)
    .replace(/[^\w. ]/gi, match => '&#' + match.charCodeAt(0) + ';')
    .replace(' ', '&nbsp;')

  const isDefault = code => ['equ', 'fig', 'tab', 'fno'].includes(code.substr(0, 3))

  const getSelectedOptionText = $el => $.trim($el.children('option:selected').text()) // TODO: why bother passing in element

  const all$ = els => $(els.join(','))

  const getColorHex = hexStr => {
    if (!hexStr)                return null
    if (hexStr.length === 6)    return '#' + hexStr
    if (hexStr.length === 3)    return hexStr.split().reduce(doubleEach, '#')
    return null
  }

  const typeFlexibleCompare = (a, b) => {
    switch (typeof a) {
      case 'string':              return a < b ? -1 : b < a ? 1 : 0
      case 'number': case 'bool': return a - b
      default:                    return 0
    }
  }

  // byProp can be used to sort by different types. It takes a function that will
  // retrieve the relevant sort target from something. The default function does
  // not modify the sort target
  const byProp = (getProp = a => a, asc = true) => (a, b) =>
    asc
      ? typeFlexibleCompare(getProp(a), getProp(b))
      : typeFlexibleCompare(getProp(b), getProp(a))

  const showLoader = () => $('.load-overlay').css('visibility', 'visible')
  const hideLoader = () => $('.load-overlay').css('visibility', 'hidden')

  /* INTERACTIONS WITH GOOGLE SCRIPTS */
  /* =============================================*/

  // Runs on open sidebar
  $(function () {
    google.script.run.withSuccessHandler(initialiseSidebar).getSettings()
  })


  // Save the current sidebar settings as document settings
  function saveProperties(button) {
    updateTempSettings()
    console.log(tempSettings)
    google.script.run.withSuccessHandler(enableButton).updateProps(tempSettings)
  }


  $('#save-defaults').on('click', function () {<commit_msg>remove console.log<commit_after><script>
  // FIXME: setting color to auto does not clear color

  /** GLOBAL STATE **/
  /* =============================================*/

  let tempSettings = {}
  let refCodes = []


  /* LIBRARY FUNCTIONS */
  /* =============================================*/

  const getColorStr = colorHex => colorHex?.slice(1)

  const isValidColor = color => /(#|^)([0-9A-f]{3}|[0-9A-f]{6})$/.test(color)

  const doubleEach = (acc, cur) => acc + cur + cur

  const arrayMinus = (arr, item) => arr.filter(a => a !== item)

  const htmlEncode = str => String(str)
    .replace(/[^\w. ]/gi, match => '&#' + match.charCodeAt(0) + ';')
    .replace(' ', '&nbsp;')

  const isDefault = code => ['equ', 'fig', 'tab', 'fno'].includes(code.substr(0, 3))

  const getSelectedOptionText = $el => $.trim($el.children('option:selected').text()) // TODO: why bother passing in element

  const all$ = els => $(els.join(','))

  const getColorHex = hexStr => {
    if (!hexStr)                return null
    if (hexStr.length === 6)    return '#' + hexStr
    if (hexStr.length === 3)    return hexStr.split().reduce(doubleEach, '#')
    return null
  }

  const typeFlexibleCompare = (a, b) => {
    switch (typeof a) {
      case 'string':              return a < b ? -1 : b < a ? 1 : 0
      case 'number': case 'bool': return a - b
      default:                    return 0
    }
  }

  // byProp can be used to sort by different types. It takes a function that will
  // retrieve the relevant sort target from something. The default function does
  // not modify the sort target
  const byProp = (getProp = a => a, asc = true) => (a, b) =>
    asc
      ? typeFlexibleCompare(getProp(a), getProp(b))
      : typeFlexibleCompare(getProp(b), getProp(a))

  const showLoader = () => $('.load-overlay').css('visibility', 'visible')
  const hideLoader = () => $('.load-overlay').css('visibility', 'hidden')

  /* INTERACTIONS WITH GOOGLE SCRIPTS */
  /* =============================================*/

  // Runs on open sidebar
  $(function () {
    google.script.run.withSuccessHandler(initialiseSidebar).getSettings()
  })


  // Save the current sidebar settings as document settings
  function saveProperties(button) {
    updateTempSettings()
    google.script.run.withSuccessHandler(enableButton).updateProps(tempSettings)
  }


  $('#save-defaults').on('click', function () {
{'fraction_non_alphanumeric': 0.21696743414229414, 'fraction_numerical': 0.006637627048330222, 'mean_word_length': 3.131962296486718, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, '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': '5726266', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1434, 'n_words': 392}