Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion websites/T/TBM/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"url": "www.infotbm.com",
"regExp": "^https?[:][/][/]([a-z0-9-]+[.])*infotbm[.]com[/]",
"version": "1.0.2",
"version": "1.0.3",
"logo": "https://cdn.rcd.gg/PreMiD/websites/T/TBM/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/T/TBM/assets/thumbnail.png",
"color": "#FFFFFF",
Expand Down
10 changes: 9 additions & 1 deletion websites/T/TBM/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function getStrings() {
})
}
const browsingTimestamp = Math.floor(Date.now() / 1000)
const svgCache = new Map<string, string>()

enum ActivityAssets {
Logo = 'https://cdn.rcd.gg/PreMiD/websites/T/TBM/assets/logo.png',
Expand All @@ -57,6 +58,10 @@ enum ActivityAssets {
}

async function svgToPng(svgUrl: string): Promise<string | undefined> {
if (svgCache.has(svgUrl)) {
return svgCache.get(svgUrl)
}

if (!svgUrl || !svgUrl.endsWith('.svg'))
return

Expand Down Expand Up @@ -92,6 +97,7 @@ async function svgToPng(svgUrl: string): Promise<string | undefined> {
ctx.drawImage(img, x, y, img.width, img.height)

png = canvas.toDataURL('image/png')
svgCache.set(svgUrl, png)
}

URL.revokeObjectURL(url)
Expand Down Expand Up @@ -231,8 +237,10 @@ presence.on('UpdateData', async () => {
presenceData.details = strings.viewLines
presenceData.smallImageKey = ActivityAssets.Lines
if (document.querySelector('.title-line')) {
const departureStop = document.querySelector('.lines > h2:nth-of-type(1)')
const arrivalStop = document.querySelector('.lines > h2:nth-of-type(2)')
presenceData.details = strings.viewLineInfo
presenceData.state = `${document.querySelector('.lines > h2:nth-of-type(1)')?.textContent} ↔ ${document.querySelector('.lines > h2:nth-of-type(2)')?.textContent}`
presenceData.state = `${departureStop?.textContent}${arrivalStop ? ` ↔ ${arrivalStop?.textContent}` : ''}`
svgImg = document.querySelector<HTMLImageElement>('.tbm-icon-picto > img')
if (svgImg) {
presenceData.smallImageKey = await svgToPng(svgImg?.src)
Expand Down
Loading