1
1
export default async function ( { feature, console } ) {
2
2
function drawNotification ( canvas , text ) {
3
3
var ctx = canvas . getContext ( "2d" ) ;
4
-
5
4
var favicon = new Image ( ) ;
6
5
favicon . src = "/favicon.ico" ;
7
6
favicon . onload = function ( ) {
7
+ ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
8
8
ctx . drawImage ( favicon , 0 , 0 , canvas . width , canvas . height ) ;
9
-
10
9
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 ) ;
12
11
ctx . fillStyle = "#ff9f00" ;
13
12
ctx . fill ( ) ;
14
-
15
13
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` ;
17
16
ctx . textAlign = "center" ;
18
17
ctx . textBaseline = "middle" ;
19
- ctx . fillText ( text , canvas . width - 10 , 14 ) ;
20
-
18
+ ctx . fillText ( text , canvas . width - 6 , 6 ) ;
21
19
var newFavicon = canvas . toDataURL ( "image/png" ) ;
22
20
var link = document . createElement ( "link" ) ;
23
21
link . type = "image/x-icon" ;
@@ -31,11 +29,9 @@ export default async function ({ feature, console }) {
31
29
window . setFaviconCount = setFaviconCount ;
32
30
async function setFaviconCount ( ) {
33
31
var canvas = document . createElement ( "canvas" ) ;
34
- canvas . width = 20 ;
35
- canvas . height = 20 ;
36
-
32
+ canvas . width = 16 ;
33
+ canvas . height = 16 ;
37
34
let username = ( await feature . auth . fetch ( ) ) ?. user ?. username ;
38
-
39
35
let data = await (
40
36
await fetch (
41
37
`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 }) {
50
46
51
47
feature . addEventListener ( "disabled" , function ( ) {
52
48
clearInterval ( interval ) ;
53
-
54
49
var link = document . createElement ( "link" ) ;
55
50
link . type = "image/x-icon" ;
56
51
link . rel = "shortcut icon" ;
0 commit comments