Skip to content
Merged
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
19 changes: 7 additions & 12 deletions features/favicon-messages/script.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
export default async function ({ feature, console }) {
function drawNotification(canvas, text) {
var ctx = canvas.getContext("2d");

var favicon = new Image();
favicon.src = "/favicon.ico";
favicon.onload = function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(favicon, 0, 0, canvas.width, canvas.height);

ctx.beginPath();
ctx.arc(canvas.width - 10, 14, 8, 0, 2 * Math.PI);
ctx.arc(canvas.width - 6, 6, 7, 0, 2 * Math.PI);
ctx.fillStyle = "#ff9f00";
ctx.fill();

ctx.fillStyle = "white";
ctx.font = "bold " + 10 / (text.length * 0.4) + "px Arial";
let fontSize = text.length === 1 ? 10 : text.length === 2 ? 8 : 7;
ctx.font = `bold ${fontSize}px Arial`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width - 10, 14);

ctx.fillText(text, canvas.width - 6, 6);
var newFavicon = canvas.toDataURL("image/png");
var link = document.createElement("link");
link.type = "image/x-icon";
Expand All @@ -31,11 +29,9 @@ export default async function ({ feature, console }) {
window.setFaviconCount = setFaviconCount;
async function setFaviconCount() {
var canvas = document.createElement("canvas");
canvas.width = 20;
canvas.height = 20;

canvas.width = 16;
canvas.height = 16;
let username = (await feature.auth.fetch())?.user?.username;

let data = await (
await fetch(
`https://api.scratch.mit.edu/users/${username}/messages/count?really-no-cache=${Date.now().toString()}`
Expand All @@ -50,7 +46,6 @@ export default async function ({ feature, console }) {

feature.addEventListener("disabled", function () {
clearInterval(interval);

var link = document.createElement("link");
link.type = "image/x-icon";
link.rel = "shortcut icon";
Expand Down
Loading