<commit_before>(function() {
  const PREFIX = 'octotree'
      , STORE_TOKEN = 'octotree.github_access_token'
      , STORE_POPUP = 'octotree.popup_shown'
      , STORE_WIDTH = 'octotree.sidebar_width'
      , DEFAULT_WIDTH = 250
      , RESERVED_USER_NAMES = [
          'settings', 'orgs', 'organizations', 
          'site', 'blog', 'about', 'explore',
          'styleguide', 'showcases', 'trending',
          'stars', 'dashboard', 'notifications'
        ]
      , RESERVED_REPO_NAMES = ['followers', 'following']
      , EVT_TOGGLED = 'octotree:toggled'

      // fragile selectors based GitHub DOM, tries to be change-proof
      , GH_BRANCH_SEL     = '*[data-master-branch]'
      , GH_BRANCH_BTN_SEL = '*[data-master-branch] > .js-select-button'
      , GH_PJAX_SEL       = '#js-repo-pjax-container'
      , GH_404_SEL        = '#parallax_wrapper'

      // regexps from https://github.com/shockie/node-iniparser
      , INI_SECTION = /^\s*\[\s*([^\]]*)\s*\]\s*$/
      , INI_COMMENT = /^\s*;.*$/
      , INI_PARAM   = /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/

  var $html = $('html')
    , $dom  = $('<div>' +
                  '<nav class="octotree_sidebar">' +
                    '<div class="octotree_header"/>' +
                    '<div class="octotree_treeview"/>' +
                    '<form class="octotree_options">' +
                      '<div class="message"/>' +
                      '<div>' +
                        '<input name="token" type="text" placeholder="Paste access token here" autocomplete="off"/>' +
                      '</div>' +
                      '<div>' +
                        '<button type="submit" class="button">Save</button>' +
                        '<a href="https://github.com/buunguyen/octotree#github-api-rate-limit" target="_blank">Why is this required?</a>' +
                      '</div>' +
                      '<div class="error"/>' +
                    '</form>' +
                  '</nav>' +
                  '<a class="octotree_toggle button"><div class="loader"/><span/></a>' +
                  '<div class="octotree_popup">' +
                    '<div class="arrow"/>' +
                    '<div class="content">Octotree is enabled on every GitHub code page. Click this button or press <kbd>⌘ b</kbd> (or <kbd>ctrl b</kbd>) to show it.</div>' +
                  '</div>' +
                '</div>')
    , $sidebar   = $dom.find('.octotree_sidebar')
    , $treeView  = $sidebar.find('.octotree_treeview')
    , $optsFrm   = $sidebar.find('.octotree_options')
    , $toggleBtn = $dom.find('.octotree_toggle')
    , $helpPopup = $dom.find('.octotree_popup')
    , $dummyDiv  = $('<div/>')
    , $document  = $(document)
    , store       = new Storage()
    , currentRepo = false
    , keysBound   = false

  $document.ready(function() {
    // initializes DOM
    $('body')
      .append($sidebar)
      .append($toggleBtn.click(toggleSidebar))
    $sidebar
      .width(store.get(STORE_WIDTH) || DEFAULT_WIDTH)
      .resizable({
        handles  : 'e',
        minWidth : 200
      })
      .resize(sidebarResized)
      .on(EVT_TOGGLED, sidebarResized)
    $treeView.hide()
    $optsFrm.hide().submit(saveToken)

    $document
      .on('pjax:send octotree:start', function() {
        $toggleBtn.addClass('loading')
      })
      .on('pjax:end octotree:end', function() {
        $toggleBtn.removeClass('loading')
      })
      .on('pjax:timeout', function(event) {
        event.preventDefault()
      })

    // When navigating from non-code pages (i.e. Pulls, Issues) to code page
    // GitHub doesn't reload the page but uses pjax. Need to detect and load Octotree.
    var href, hash
    function detectLocationChange() {
      if (location.href !== href || location.hash !== hash) {
        href = location.href
        hash = location.hash
        tryLoadRepo()
      }
      setTimeout(detectLocationChange, 200)
    }
    detectLocationChange()
  })

  function tryLoadRepo(reload) {
    var repo = getRepoFromPath()
      , repoChanged = JSON.stringify(repo) !== JSON.stringify(currentRepo)

    if (repo) {
      showHelpPopup()
      $toggleBtn.show()
      if (!keysBound) {
        key('⌘+b, ⌃+b', toggleSidebar)
        keysBound = true
      }

      if (repoChanged || reload) {
        $document.trigger('octotree:start')
        currentRepo = repo
        fetchData(repo, function(err, tree) {
          if (err) {
            $document.trigger('octotree:end')
            return onFetchError(err)
          }
          renderTree(repo, tree, function() {
            $document.trigger('octotree:end')
            selectTreeNode()
          })
        })
      } 
      else selectTreeNode()
    } 
    else {
      $toggleBtn.hide()
      if (keysBound) {<commit_msg>Fix bug commit->code still show sidebar<commit_after>(function() {
  const PREFIX = 'octotree'
      , STORE_TOKEN = 'octotree.github_access_token'
      , STORE_POPUP = 'octotree.popup_shown'
      , STORE_WIDTH = 'octotree.sidebar_width'
      , DEFAULT_WIDTH = 250
      , RESERVED_USER_NAMES = [
          'settings', 'orgs', 'organizations', 
          'site', 'blog', 'about', 'explore',
          'styleguide', 'showcases', 'trending',
          'stars', 'dashboard', 'notifications'
        ]
      , RESERVED_REPO_NAMES = ['followers', 'following']
      , EVT_TOGGLED = 'octotree:toggled'

      // fragile selectors based GitHub DOM, uses of them must be change-proof
      , GH_BRANCH_SEL     = '*[data-master-branch]'
      , GH_BRANCH_BTN_SEL = '*[data-master-branch] > .js-select-button'
      , GH_PJAX_SEL       = '#js-repo-pjax-container'
      , GH_404_SEL        = '#parallax_wrapper'

      // regexps from https://github.com/shockie/node-iniparser
      , INI_SECTION = /^\s*\[\s*([^\]]*)\s*\]\s*$/
      , INI_COMMENT = /^\s*;.*$/
      , INI_PARAM   = /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/

  var $html = $('html')
    , $dom  = $('<div>' +
                  '<nav class="octotree_sidebar">' +
                    '<div class="octotree_header"/>' +
                    '<div class="octotree_treeview"/>' +
                    '<form class="octotree_options">' +
                      '<div class="message"/>' +
                      '<div>' +
                        '<input name="token" type="text" placeholder="Paste access token here" autocomplete="off"/>' +
                      '</div>' +
                      '<div>' +
                        '<button type="submit" class="button">Save</button>' +
                        '<a href="https://github.com/buunguyen/octotree#github-api-rate-limit" target="_blank">Why is this required?</a>' +
                      '</div>' +
                      '<div class="error"/>' +
                    '</form>' +
                  '</nav>' +
                  '<a class="octotree_toggle button"><div class="loader"/><span/></a>' +
                  '<div class="octotree_popup">' +
                    '<div class="arrow"/>' +
                    '<div class="content">Octotree is enabled on every GitHub code page. Click this button or press <kbd>⌘ b</kbd> (or <kbd>ctrl b</kbd>) to show it.</div>' +
                  '</div>' +
                '</div>')
    , $sidebar   = $dom.find('.octotree_sidebar')
    , $treeView  = $sidebar.find('.octotree_treeview')
    , $optsFrm   = $sidebar.find('.octotree_options')
    , $toggleBtn = $dom.find('.octotree_toggle')
    , $helpPopup = $dom.find('.octotree_popup')
    , $dummyDiv  = $('<div/>')
    , $document  = $(document)
    , store       = new Storage()
    , currentRepo = false
    , keysBound   = false

  $document.ready(function() {
    // initializes DOM
    $('body')
      .append($sidebar)
      .append($toggleBtn.click(toggleSidebar))
    $sidebar
      .width(store.get(STORE_WIDTH) || DEFAULT_WIDTH)
      .resizable({
        handles  : 'e',
        minWidth : 200
      })
      .resize(sidebarResized)
      .on(EVT_TOGGLED, sidebarResized)
    $treeView.hide()
    $optsFrm.hide().submit(saveToken)

    $document
      .on('pjax:send octotree:start', function() {
        $toggleBtn.addClass('loading')
      })
      .on('pjax:end octotree:end', function() {
        $toggleBtn.removeClass('loading')
      })
      .on('pjax:timeout', function(event) {
        event.preventDefault()
      })

    // When navigating from non-code pages (i.e. Pulls, Issues) to code page
    // GitHub doesn't reload the page but uses pjax. Need to detect and load Octotree.
    var href, hash
    function detectLocationChange() {
      if (location.href !== href || location.hash !== hash) {
        href = location.href
        hash = location.hash
        tryLoadRepo()
      }
      setTimeout(detectLocationChange, 200)
    }
    detectLocationChange()
  })

  function tryLoadRepo(reload) {
    var repo = getRepoFromPath()
      , repoChanged = JSON.stringify(repo) !== JSON.stringify(currentRepo)

    if (repo) {
      showHelpPopup()
      $toggleBtn.show()
      if (!keysBound) {
        key('⌘+b, ⌃+b', toggleSidebar)
        keysBound = true
      }

      if (repoChanged || reload) {
        $document.trigger('octotree:start')
        currentRepo = repo
        fetchData(repo, function(err, tree) {
          if (err) {
            $document.trigger('octotree:end')
            return onFetchError(err)
          }
          renderTree(repo, tree, function() {
            $document.trigger('octotree:end')
            selectTreeNode()
          })
        })
      } 
      else selectTreeNode()
    } 
    else {
      $toggleBtn.hide()
      toggleSidebar(false)
      if (keysBound) {
{'fraction_non_alphanumeric': 0.16100812330764425, 'fraction_numerical': 0.0024994792751510102, 'mean_word_length': 1.9493243243243243, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 72, 'https://': 4, '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': '174630', 'n_tokens_mistral': 3099, 'n_tokens_neox': 3023, 'n_words': 546}