<commit_before>const calendarGraph = document.querySelector('.js-calendar-graph')
const contributionsBox = document.querySelector('.js-yearly-contributions')
const observedContainer = document.getElementById('js-contribution-activity')

const COLORS = [
  new obelisk.CubeColor().getByHorizontalColor(0xebedf0),
  new obelisk.CubeColor().getByHorizontalColor(0x9be9a8),
  new obelisk.CubeColor().getByHorizontalColor(0x40c463),
  new obelisk.CubeColor().getByHorizontalColor(0x30a14e),
  new obelisk.CubeColor().getByHorizontalColor(0x216e39)
]

const dateOptions         = {month: "short", day: "numeric"}
const dateWithYearOptions = {month: "short", day: "numeric", year: "numeric"}

let yearTotal           = 0
let averageCount        = 0
let maxCount            = 0
let bestDay             = null
let firstDay            = null
let lastDay             = null

let toggleSetting = "cubes"
let show2DSetting = "no"

const resetValues = () => {
  yearTotal           = 0
  averageCount        = 0
  maxCount            = 0
  bestDay             = null
  firstDay            = null
  lastDay             = null
}

const getSettings = () => {
  return new Promise(function(resolve, reject) {
    // Check for user preference, if chrome.storage is available.
    // The storage API is not supported in content scripts.
    // https://developer.mozilla.org/Add-ons/WebExtensions/Chrome_incompatibilities#storage
    if (chrome && chrome.storage) {
      chrome.storage.local.get(["toggleSetting", "show2DSetting"], (settings) => {
        toggleSetting = settings.toggleSetting ? settings.toggleSetting : "cubes"
        show2DSetting = settings.show2DSetting ? settings.show2DSetting : "no"
        console.log(`toggleSetting: ${toggleSetting}`)
        console.log(`show2DSetting: ${show2DSetting}`)
        resolve('Settings loaded')
      })
    }
    else {
      toggleSetting = localStorage.toggleSetting ? localStorage.toggleSetting : "cubes"
      show2DSetting = localStorage.show2DSetting ? localStorage.show2DSetting : "no"
      resolve('Settings loaded')
    }
  })
}

const persistSetting = (key, value) => {
  if (chrome && chrome.storage) {
    let obj = {}
    obj[key] = value
    chrome.storage.local.set(obj)
  }
  else {
    localStorage[key] = value
  }
}

const initUI = () => {
  if (show2DSetting === "yes") {
    contributionsBox.classList.add("show-2d")
  }
  else {
    contributionsBox.classList.remove("show-2d")
  }

  const contributionsWrapper = document.createElement("div")
  contributionsWrapper.className = "ic-contributions-wrapper"
  calendarGraph.before(contributionsWrapper)

  const canvas = document.createElement("canvas")
  canvas.id = "isometric-contributions"
  canvas.width = 720
  canvas.height = 410
  contributionsWrapper.appendChild(canvas)

  // Inject toggle
  const insertLocation = contributionsBox.querySelector("h2")

  const htmlToggle = document.createElement("span")
  htmlToggle.className = "ic-toggle"

  const squaresButton = document.createElement("a")
  squaresButton.className = "ic-toggle-option tooltipped tooltipped-nw squares"
  squaresButton.setAttribute("aria-label", "Normal chart view")
  squaresButton.setAttribute("data-ic-option", "squares")
  squaresButton.setAttribute("href", "#")
  squaresButton.addEventListener("click", handleViewToggle);
  if (toggleSetting === "squares") {
    squaresButton.classList.add("active")
  }

  const cubesButton = document.createElement("a")
  cubesButton.className = "ic-toggle-option tooltipped tooltipped-nw cubes"
  cubesButton.setAttribute("aria-label", "Isometric chart view")
  cubesButton.setAttribute("data-ic-option", "cubes")
  cubesButton.setAttribute("href", "#")
  cubesButton.addEventListener("click", handleViewToggle);
  if (toggleSetting === "cubes") {
    cubesButton.classList.add("active")
  }

  insertLocation.before(htmlToggle)
  htmlToggle.appendChild(squaresButton)
  htmlToggle.appendChild(cubesButton)

  // Inject footer w/ toggle for showing 2D chart
  const htmlFooter = document.createElement("span")
  htmlFooter.className = "ic-footer"

  const normalChartToggle = document.createElement("a")
  normalChartToggle.className = "ic-2d-toggle text-small muted-link"
  if (show2DSetting === "yes") {
    normalChartToggle.innerHTML = "Hide normal chart below"
  }
  else {
    normalChartToggle.innerHTML = "Show normal chart below"
  }
  normalChartToggle.setAttribute("href", "#")
  normalChartToggle.addEventListener("click", handle2DToggle);

  contributionsWrapper.append(htmlFooter)
  htmlFooter.append(normalChartToggle)
}

const handleViewToggle = (e) => {
  e.preventDefault()
  let option = e.target.dataset.icOption

  if (option === "squares") {
    contributionsBox.classList.remove("ic-cubes")
    contributionsBox.classList.add("ic-squares")
  }
  else {
    contributionsBox.classList.remove("ic-squares")
    contributionsBox.classList.add("ic-cubes")
  }

  document.querySelectorAll(".ic-toggle-option").forEach(toggle => { toggle.classList.remove("active") })
  e.target.classList.add("active")

  persistSetting("toggleSetting", option)
  toggleSetting = option

  // Apply user preference
  document.querySelector(`.ic-toggle-option.${toggleSetting}`).classList.add("active")
  contributionsBox.classList.add(`ic-${toggleSetting}`)
}

const handle2DToggle = (e) => {
  e.preventDefault()

  if (contributionsBox.classList.contains("show-2d")) {
    e.target.innerHTML = "Show normal chart"
    contributionsBox.classList.remove("show-2d")
    persistSetting("show2DSetting", "no")
    show2DSetting = "no"
  }
  else {
    e.target.innerHTML = "Hide normal chart"
    contributionsBox.classList.add("show-2d")
    persistSetting("show2DSetting", "yes")
    show2DSetting = "yes"
  }
}

const loadStats = () => {
  console.log("loadStats")
}<commit_msg>s/normal/standard<commit_after>const calendarGraph = document.querySelector('.js-calendar-graph')
const contributionsBox = document.querySelector('.js-yearly-contributions')
const observedContainer = document.getElementById('js-contribution-activity')

const COLORS = [
  new obelisk.CubeColor().getByHorizontalColor(0xebedf0),
  new obelisk.CubeColor().getByHorizontalColor(0x9be9a8),
  new obelisk.CubeColor().getByHorizontalColor(0x40c463),
  new obelisk.CubeColor().getByHorizontalColor(0x30a14e),
  new obelisk.CubeColor().getByHorizontalColor(0x216e39)
]

const dateOptions         = {month: "short", day: "numeric"}
const dateWithYearOptions = {month: "short", day: "numeric", year: "numeric"}

let yearTotal           = 0
let averageCount        = 0
let maxCount            = 0
let bestDay             = null
let firstDay            = null
let lastDay             = null

let toggleSetting = "cubes"
let show2DSetting = "no"

const resetValues = () => {
  yearTotal           = 0
  averageCount        = 0
  maxCount            = 0
  bestDay             = null
  firstDay            = null
  lastDay             = null
}

const getSettings = () => {
  return new Promise(function(resolve, reject) {
    // Check for user preference, if chrome.storage is available.
    // The storage API is not supported in content scripts.
    // https://developer.mozilla.org/Add-ons/WebExtensions/Chrome_incompatibilities#storage
    if (chrome && chrome.storage) {
      chrome.storage.local.get(["toggleSetting", "show2DSetting"], (settings) => {
        toggleSetting = settings.toggleSetting ? settings.toggleSetting : "cubes"
        show2DSetting = settings.show2DSetting ? settings.show2DSetting : "no"
        console.log(`toggleSetting: ${toggleSetting}`)
        console.log(`show2DSetting: ${show2DSetting}`)
        resolve('Settings loaded')
      })
    }
    else {
      toggleSetting = localStorage.toggleSetting ? localStorage.toggleSetting : "cubes"
      show2DSetting = localStorage.show2DSetting ? localStorage.show2DSetting : "no"
      resolve('Settings loaded')
    }
  })
}

const persistSetting = (key, value) => {
  if (chrome && chrome.storage) {
    let obj = {}
    obj[key] = value
    chrome.storage.local.set(obj)
  }
  else {
    localStorage[key] = value
  }
}

const initUI = () => {
  if (show2DSetting === "yes") {
    contributionsBox.classList.add("show-2d")
  }
  else {
    contributionsBox.classList.remove("show-2d")
  }

  const contributionsWrapper = document.createElement("div")
  contributionsWrapper.className = "ic-contributions-wrapper"
  calendarGraph.before(contributionsWrapper)

  const canvas = document.createElement("canvas")
  canvas.id = "isometric-contributions"
  canvas.width = 720
  canvas.height = 410
  contributionsWrapper.appendChild(canvas)

  // Inject toggle
  const insertLocation = contributionsBox.querySelector("h2")

  const htmlToggle = document.createElement("span")
  htmlToggle.className = "ic-toggle"

  const squaresButton = document.createElement("a")
  squaresButton.className = "ic-toggle-option tooltipped tooltipped-nw squares"
  squaresButton.setAttribute("aria-label", "Standard chart view")
  squaresButton.setAttribute("data-ic-option", "squares")
  squaresButton.setAttribute("href", "#")
  squaresButton.addEventListener("click", handleViewToggle);
  if (toggleSetting === "squares") {
    squaresButton.classList.add("active")
  }

  const cubesButton = document.createElement("a")
  cubesButton.className = "ic-toggle-option tooltipped tooltipped-nw cubes"
  cubesButton.setAttribute("aria-label", "Isometric chart view")
  cubesButton.setAttribute("data-ic-option", "cubes")
  cubesButton.setAttribute("href", "#")
  cubesButton.addEventListener("click", handleViewToggle);
  if (toggleSetting === "cubes") {
    cubesButton.classList.add("active")
  }

  insertLocation.before(htmlToggle)
  htmlToggle.appendChild(squaresButton)
  htmlToggle.appendChild(cubesButton)

  // Inject footer w/ toggle for showing 2D chart
  const htmlFooter = document.createElement("span")
  htmlFooter.className = "ic-footer"

  const standardChartToggle = document.createElement("a")
  standardChartToggle.className = "ic-2d-toggle text-small muted-link"
  if (show2DSetting === "yes") {
    standardChartToggle.innerHTML = "Hide normal chart below"
  }
  else {
    standardChartToggle.innerHTML = "Show normal chart below"
  }
  standardChartToggle.setAttribute("href", "#")
  standardChartToggle.addEventListener("click", handle2DToggle);

  contributionsWrapper.append(htmlFooter)
  htmlFooter.append(standardChartToggle)
}

const handleViewToggle = (e) => {
  e.preventDefault()
  let option = e.target.dataset.icOption

  if (option === "squares") {
    contributionsBox.classList.remove("ic-cubes")
    contributionsBox.classList.add("ic-squares")
  }
  else {
    contributionsBox.classList.remove("ic-squares")
    contributionsBox.classList.add("ic-cubes")
  }

  document.querySelectorAll(".ic-toggle-option").forEach(toggle => { toggle.classList.remove("active") })
  e.target.classList.add("active")

  persistSetting("toggleSetting", option)
  toggleSetting = option

  // Apply user preference
  document.querySelector(`.ic-toggle-option.${toggleSetting}`).classList.add("active")
  contributionsBox.classList.add(`ic-${toggleSetting}`)
}

const handle2DToggle = (e) => {
  e.preventDefault()

  if (contributionsBox.classList.contains("show-2d")) {
    e.target.innerHTML = "Show standard chart"
    contributionsBox.classList.remove("show-2d")
    persistSetting("show2DSetting", "no")
    show2DSetting = "no"
  }
  else {
    e.target.innerHTML = "Hide standard chart"
    contributionsBox.classList.add("show-2d")
    persistSetting("show2DSetting", "yes")
    show2DSetting = "yes"
  }
}

const loadStats = () => {
  console.log("loadStats")
}
{'fraction_non_alphanumeric': 0.12817433081674673, 'fraction_numerical': 0.010466712422786548, 'mean_word_length': 4.031074665515753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2910006', 'n_tokens_mistral': 3555, 'n_tokens_neox': 3495, 'n_words': 632}