Created
January 26, 2020 21:12
-
-
Save easrng/5614c3faf794770aea812e8b2350a54f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if (!window.OffscreenCanvas) { | |
window.OffscreenCanvas = class OffscreenCanvas { | |
constructor(width, height) { | |
this.canvas = document.createElement("canvas"); | |
this.canvas.width = width; | |
this.canvas.height = height; | |
this.canvas.convertToBlob = () => { | |
return new Promise(resolve => { | |
this.canvas.toBlob(resolve); | |
}); | |
}; | |
return this.canvas; | |
} | |
}; | |
} | |
function loadImage(url){ | |
return new Promise((resolve)=>{ | |
let i=new Image(); | |
i.onload=()=>resolve(i); | |
i.src=url | |
}) | |
} | |
(async()=>{ | |
let favicon=document.querySelector('link[rel="shortcut icon"][href*="svg"]') | |
let i=await loadImage(favicon.href) | |
let c=new OffscreenCanvas(512,512) | |
let ctx=c.getContext("2d") | |
ctx.drawImage(i,0,0,512,512) | |
favicon.href=URL.createObjectURL(await c.convertToBlob()) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment