@@ -42,6 +42,7 @@ async function getStrings() {
4242 } )
4343}
4444const browsingTimestamp = Math . floor ( Date . now ( ) / 1000 )
45+ const svgCache = new Map < string , string > ( )
4546
4647enum ActivityAssets {
4748 Logo = 'https://cdn.rcd.gg/PreMiD/websites/T/TBM/assets/logo.png' ,
@@ -57,6 +58,10 @@ enum ActivityAssets {
5758}
5859
5960async function svgToPng ( svgUrl : string ) : Promise < string | undefined > {
61+ if ( svgCache . has ( svgUrl ) ) {
62+ return svgCache . get ( svgUrl )
63+ }
64+
6065 if ( ! svgUrl || ! svgUrl . endsWith ( '.svg' ) )
6166 return
6267
@@ -92,6 +97,7 @@ async function svgToPng(svgUrl: string): Promise<string | undefined> {
9297 ctx . drawImage ( img , x , y , img . width , img . height )
9398
9499 png = canvas . toDataURL ( 'image/png' )
100+ svgCache . set ( svgUrl , png )
95101 }
96102
97103 URL . revokeObjectURL ( url )
@@ -231,8 +237,10 @@ presence.on('UpdateData', async () => {
231237 presenceData . details = strings . viewLines
232238 presenceData . smallImageKey = ActivityAssets . Lines
233239 if ( document . querySelector ( '.title-line' ) ) {
240+ const departureStop = document . querySelector ( '.lines > h2:nth-of-type(1)' )
241+ const arrivalStop = document . querySelector ( '.lines > h2:nth-of-type(2)' )
234242 presenceData . details = strings . viewLineInfo
235- presenceData . state = `${ document . querySelector ( '.lines > h2:nth-of-type(1)' ) ?. textContent } ↔ ${ document . querySelector ( '.lines > h2:nth-of-type(2)' ) ?. textContent } `
243+ presenceData . state = `${ departureStop ?. textContent } ${ arrivalStop ? ` ↔ ${ arrivalStop ?. textContent } ` : '' } `
236244 svgImg = document . querySelector < HTMLImageElement > ( '.tbm-icon-picto > img' )
237245 if ( svgImg ) {
238246 presenceData . smallImageKey = await svgToPng ( svgImg ?. src )
0 commit comments