{"size": 802, "ext": "js", "max_stars_repo_path": "static/js/component/Favicon.js", "max_stars_repo_name": "erdnaxe/bmpc", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "static/js/component/Favicon.js", "max_issues_repo_name": "erdnaxe/bmpc", "max_issues_repo_issues_event_min_datetime": "2021-05-09T16:57:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T08:59:35.000Z", "max_forks_repo_path": "static/js/component/Favicon.js", "max_forks_repo_name": "erdnaxe/bmpc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 23.5882352941, "max_line_length": 77, "alphanum_fraction": 0.6271820449}
'use strict'

/**
 * Build a favicon using text in a canvas
 */
export default class Favicon {
  constructor () {
    this.canvas = document.createElement('canvas')
    this.canvas.height = 64
    this.canvas.width = 64
    this.ctx = this.canvas.getContext('2d')
    this.ctx.font = '40px serif'
    this.lastIcon = null
    this.updateIcon('')
  }

  /**
   * Update favicon
   * @param {String} newIcon Text or emoji to show at bottom of favicon
   */
  updateIcon (newIcon) {
    if (newIcon === this.lastIcon) {
      return // Icon is already set
    }
    this.lastIcon = newIcon

    // Replace icon
    this.ctx.clearRect(0, 0, 64, 64)
    this.ctx.fillText('🎶', 0, 42)
    this.ctx.fillText(newIcon, 24, 60)
    document.querySelector("link[rel='icon']").href = this.canvas.toDataURL()
  }
}
