@@ -13,7 +13,7 @@ export default async function ({ feature, console }) {
1313 ctx . fill ( ) ;
1414
1515 ctx . fillStyle = "white" ;
16- ctx . font = "bold " + 10 / ( text . length * .4 ) + "px Arial" ;
16+ ctx . font = "bold " + 10 / ( text . length * 0 .4) + "px Arial" ;
1717 ctx . textAlign = "center" ;
1818 ctx . textBaseline = "middle" ;
1919 ctx . fillText ( text , canvas . width - 10 , 14 ) ;
@@ -22,24 +22,27 @@ export default async function ({ feature, console }) {
2222 var link = document . createElement ( "link" ) ;
2323 link . type = "image/x-icon" ;
2424 link . rel = "shortcut icon" ;
25+ link . dataset . ste = "favicon-messages" ;
2526 link . href = newFavicon ;
2627 document . head . appendChild ( link ) ;
2728 } ;
2829 }
2930
30- window . setFaviconCount = setFaviconCount
31- async function setFaviconCount ( count ) {
31+ window . setFaviconCount = setFaviconCount ;
32+ async function setFaviconCount ( ) {
3233 var canvas = document . createElement ( "canvas" ) ;
3334 canvas . width = 20 ;
3435 canvas . height = 20 ;
3536
37+ let username = ( await feature . auth . fetch ( ) ) ?. user ?. username ;
38+
3639 let data = await (
3740 await fetch (
38- "https://scratch.mit.edu/messages/ajax/get-message-count/?scratchtools=" +
39- Date . now ( ) . toString ( )
41+ `https://api.scratch.mit.edu/users/${ username } /messages/count?really-no-cache=${ Date . now ( ) . toString ( ) } `
4042 )
4143 ) . json ( ) ;
42- drawNotification ( canvas , count ?. toString ( ) || data . msg_count . toString ( ) ) ;
44+ document . querySelector ( "link[rel='shortcut icon']" ) ?. remove ( ) ;
45+ drawNotification ( canvas , data . count . toString ( ) ) ;
4346 }
4447
4548 let interval = setInterval ( setFaviconCount , 60000 ) ;
@@ -57,6 +60,6 @@ export default async function ({ feature, console }) {
5760
5861 feature . addEventListener ( "enabled" , function ( ) {
5962 interval = setInterval ( setFaviconCount , 60000 ) ;
60- setFaviconCount ( )
63+ setFaviconCount ( ) ;
6164 } ) ;
6265}
0 commit comments