Created
December 7, 2019 01:13
-
-
Save wesbos/9d9c9c7bec5329004c03675a1358ff6e to your computer and use it in GitHub Desktop.
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
function invert() { | |
// grab the favicon | |
const icon = document.querySelector('link[rel*="icon"]'); | |
if (!icon) return; | |
// make a canvas | |
const canvas = document.createElement('canvas'); | |
canvas.width = 128; | |
canvas.height = 128; | |
document.body.append(canvas); | |
const ctx = canvas.getContext('2d'); | |
const img = document.createElement('img'); | |
img.src = icon.href; | |
document.body.append(img); | |
img.addEventListener('load', () => { | |
ctx.drawImage(img, 0, 0, 128, 128); | |
// invert colours. MEH this doesn't look that good | |
ctx.globalCompositeOperation = 'difference'; | |
ctx.fillStyle = 'white'; | |
ctx.fillRect(0, 0, canvas.width, canvas.height); | |
const data = canvas.toDataURL('image/png'); | |
icon.type = 'image/x-icon'; | |
icon.href = data; | |
}); | |
} | |
invert(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment