Created
September 26, 2020 11:00
-
-
Save zemlanin/6780f0e609a114f6edf6967fc37691cb to your computer and use it in GitHub Desktop.
emoji touch icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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