Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created May 22, 2021 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfoxall/6e08c027bd8900e385edd0867603047c to your computer and use it in GitHub Desktop.
Save benfoxall/6e08c027bd8900e385edd0867603047c to your computer and use it in GitHub Desktop.
Favicon setter
const set = favicon()
set('🐝')
//
function favicon() {
const link = document.createElement('link')
link.rel = 'icon'
document.head.appendChild(link)
const canvas = document.createElement('canvas')
canvas.width = canvas.height = 32
const ctx = canvas.getContext('2d')
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
ctx.font = '26px serif'
return function (emoji) {
ctx.clearRect(0, 0, 32, 32)
ctx.fillText(emoji, 16, 16)
link.href = canvas.toDataURL()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment