Skip to content

Instantly share code, notes, and snippets.

@thomaswilburn
Created May 25, 2022 16:43
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 thomaswilburn/a40cae683cd5a5f1317e373fffbe14bc to your computer and use it in GitHub Desktop.
Save thomaswilburn/a40cae683cd5a5f1317e373fffbe14bc to your computer and use it in GitHub Desktop.
Add a favicon with media playback progress in Firefox
var canvas = document.createElement("canvas");
canvas.width = canvas.height = 32;
var context = canvas.getContext("2d");
var link = document.createElement("link");
link.setAttribute("rel", "icon");
var media = document.querySelector("audio, video");
media.addEventListener("timeupdate", function() {
// get the current ratio
var ratio = media.currentTime / media.duration;
var arc = ratio * Math.PI * 2;
var start = Math.PI * 1.5;
var end = start + arc;
canvas.width = canvas.width;
context.fillStyle = "#0002";
context.beginPath();
context.arc(16, 16, 15, 0, Math.PI * 2);
context.fill();
context.beginPath();
context.arc(16, 16, 14, start, end);
context.lineWidth = 2;
context.stroke();
var href = canvas.toDataURL();
link.remove();
link.setAttribute("href", href);
document.head.append(link);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment