Skip to content

Instantly share code, notes, and snippets.

@zemlanin
Created September 26, 2020 11:00
Show Gist options
  • Save zemlanin/6780f0e609a114f6edf6967fc37691cb to your computer and use it in GitHub Desktop.
Save zemlanin/6780f0e609a114f6edf6967fc37691cb to your computer and use it in GitHub Desktop.
emoji touch icon
<!DOCTYPE html>
<meta charset="utf-8">
<title>test apple-touch-icon</title>
<canvas id=c width=180 height=180 style="border: 1px solid black"></canvas>
<div id=t></div>
<script>
const ctx = window.c.getContext('2d')
ctx.fillStyle = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`;
ctx.fillRect(0, 0, 180, 180);
ctx.font = '120px serif';
ctx.fillStyle = 'black';
ctx.strokeStyle = 'white';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
const emoji = ['👍', '💩', '😁', '💃'][Math.floor(Math.random() * 4)]
document.title = emoji
ctx.fillText(emoji, 90, 100);
const src = window.c.toDataURL()
const link = document.createElement("link")
link.rel = "apple-touch-icon"
link.href = src
document.head.appendChild(link)
const favicon = document.createElement("link")
favicon.rel = "shortcut icon"
favicon.type="image/png"
favicon.href = src
document.head.appendChild(favicon)
const img = document.createElement("img")
img.src = src
document.body.appendChild(img)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment