Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/resources/templates/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ <h5>Integration with the mob tool</h5>

</main>

<canvas id="favicon-canvas" width="64" height="64" hidden></canvas>
<footer th:replace="~{fragments/footer}"></footer>

<div th:replace="~{fragments/github-corner}"></div>
Expand Down Expand Up @@ -390,10 +391,44 @@ <h5>Integration with the mob tool</h5>
}
}

let faviconLink = document.querySelector("link[rel='icon']");
let faviconUri = faviconLink.getAttribute('href');
let faviconCanvas = document.getElementById('favicon-canvas');
let faviconCanvasContext = faviconCanvas.getContext('2d');
let faviconSize = Math.min(faviconCanvas.width, faviconCanvas.height);
function renderTimerFavicon() {
if (!faviconCanvasContext || !requestedTimestamp || !timerDurationInMilliseconds || !faviconLink) {
return;
}

let elapsedMillisecondsSinceRequested = Date.now() - requestedTimestamp;
if (elapsedMillisecondsSinceRequested < timerDurationInMilliseconds) {
let elapsedTimerFraction = Math.max(0.05, elapsedMillisecondsSinceRequested / timerDurationInMilliseconds);
let startAngle = -Math.PI / 2;

faviconCanvasContext.clearRect(0, 0, faviconSize, faviconSize);
faviconCanvasContext.fillStyle = requestType === 'BREAKTIMER' ? 'red' : 'green';
faviconCanvasContext.beginPath();
faviconCanvasContext.moveTo(faviconSize / 2, faviconSize / 2);
faviconCanvasContext.arc(faviconSize / 2,
faviconSize / 2,
faviconSize / 2,
startAngle,
startAngle + (2 * Math.PI * elapsedTimerFraction));
faviconCanvasContext.lineTo(faviconSize / 2, faviconSize / 2);
faviconCanvasContext.fill();

faviconLink.href = faviconCanvas.toDataURL('image/png');
} else {
faviconLink.href = faviconUri;
}
}

// loop
function timer() {
setTimeout(function () {
renderTimer();
renderTimerFavicon();
timer();
}, 50);
}
Expand Down