Skip to content

Commit a9291fc

Browse files
authored
Improve Favicon Messages
1 parent bfde8de commit a9291fc

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

features/favicon-messages/script.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
export default async function ({ feature, console }) {
22
function drawNotification(canvas, text) {
33
var ctx = canvas.getContext("2d");
4-
54
var favicon = new Image();
65
favicon.src = "/favicon.ico";
76
favicon.onload = function () {
7+
ctx.clearRect(0, 0, canvas.width, canvas.height);
88
ctx.drawImage(favicon, 0, 0, canvas.width, canvas.height);
9-
109
ctx.beginPath();
11-
ctx.arc(canvas.width - 10, 14, 8, 0, 2 * Math.PI);
10+
ctx.arc(canvas.width - 6, 6, 7, 0, 2 * Math.PI);
1211
ctx.fillStyle = "#ff9f00";
1312
ctx.fill();
14-
1513
ctx.fillStyle = "white";
16-
ctx.font = "bold " + 10 / (text.length * 0.4) + "px Arial";
14+
let fontSize = text.length === 1 ? 10 : text.length === 2 ? 8 : 7;
15+
ctx.font = `bold ${fontSize}px Arial`;
1716
ctx.textAlign = "center";
1817
ctx.textBaseline = "middle";
19-
ctx.fillText(text, canvas.width - 10, 14);
20-
18+
ctx.fillText(text, canvas.width - 6, 6);
2119
var newFavicon = canvas.toDataURL("image/png");
2220
var link = document.createElement("link");
2321
link.type = "image/x-icon";
@@ -31,11 +29,9 @@ export default async function ({ feature, console }) {
3129
window.setFaviconCount = setFaviconCount;
3230
async function setFaviconCount() {
3331
var canvas = document.createElement("canvas");
34-
canvas.width = 20;
35-
canvas.height = 20;
36-
32+
canvas.width = 16;
33+
canvas.height = 16;
3734
let username = (await feature.auth.fetch())?.user?.username;
38-
3935
let data = await (
4036
await fetch(
4137
`https://api.scratch.mit.edu/users/${username}/messages/count?really-no-cache=${Date.now().toString()}`
@@ -50,7 +46,6 @@ export default async function ({ feature, console }) {
5046

5147
feature.addEventListener("disabled", function () {
5248
clearInterval(interval);
53-
5449
var link = document.createElement("link");
5550
link.type = "image/x-icon";
5651
link.rel = "shortcut icon";

0 commit comments

Comments
 (0)