update: escape chars to prevent parsing errors, bolden activity header text, reformatting

This commit is contained in:
Conrad
2021-07-04 17:34:59 -04:00
parent 50c6568b8c
commit 7732a19b62
3 changed files with 52 additions and 71 deletions

View File

@@ -11,6 +11,7 @@
"dependencies": {
"@types/styled-components": "^5.1.10",
"axios": "^0.21.1",
"escape-html": "^1.0.3",
"framer-motion": "^4.1.17",
"image-to-base64": "^2.2.0",
"next": "11.0.0",

View File

@@ -6,6 +6,8 @@ import * as LanyardTypes from "./LanyardTypes";
import { encodeBase64 } from "./toBase64";
import { blue, green, gray, gold, red } from "./defaultAvatars"
let escape = require('escape-html');
type Parameters = {
theme?: string;
bg?: string;
@@ -153,16 +155,12 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
font-size: 1.15rem;
margin: 0 5px 0 0;
">
${body.data.discord_user.username}${discrim !== "hide"
? `<span style="color: ${theme === "dark" ? "#ccc" : "#666"}; font-weight: lighter;">#${body.data.discord_user.discriminator
}</span>`
: ""
}
${escape(body.data.discord_user.username)}${discrim !== "hide" ?
`<span style="color: ${theme === "dark" ? "#ccc" : "#666"}; font-weight: lighter;">#${body.data.discord_user.discriminator}</span>`
: "" }
</h1>
${flags
.map(
v => `
${flags.map(v => `
<img src="data:image/png;base64,${Badges[v]}" style="
width: 20px;
height: 20px;
@@ -170,12 +168,9 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
top: 50%;
transform: translate(0%, -50%);
margin: 0 0 0 4px;
" />`
)
.join("")}
" />`).join("")}
</div>
${userStatus.length > 0 && hideStatus !== "true"
? `
${userStatus.length > 0 && hideStatus !== "true" ? `
<h1 style="
font-size: 0.9rem;
margin-top: 16px;
@@ -185,34 +180,27 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
white-space: nowrap;
text-overflow: ellipsis;
">
${body.data.activities[0].emoji && body.data.activities[0].emoji.id
? `
<img src="data:image/png;base64,${await encodeBase64(
`https://cdn.discordapp.com/emojis/${body.data.activities[0].emoji.id}.${statusExtension}`
)}" style="
${body.data.activities[0].emoji && body.data.activities[0].emoji.id ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/emojis/${body.data.activities[0].emoji.id}.${statusExtension}`)}"
style="
width: 15px;
height: 15px;
position: relative;
top: 10px;
transform: translate(0%, -50%);
margin: 0 2px 0 0;
" />`
: ``
}
" />` : ``
}
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id
? body.data.activities[0].emoji.name +
" " +
userStatus.replace(/\&/g, "and")
: userStatus.replace(/\&/g, "and")
}
</h1>`
: ``
}
? body.data.activities[0].emoji.name + " " + escape(userStatus)
: escape(userStatus)
}
</h1>` : ``
}
</div>
</div>
${activity
? `
${activity ? `
<div style="
display: flex;
flex-direction: row;
@@ -226,41 +214,32 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
width: auto;
height: auto;
">
${activity.assets && activity.assets.large_image
? `
<img src="data:image/png;base64,${await encodeBase64(
`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.webp`
)}" style="
${activity.assets && activity.assets.large_image ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.webp`)}"
style="
width: 80px;
height: 80px;
border: solid 0.5px #222;
border-radius: 10px;
"/>
`
: `
<img src="data:image/png;base64,${await encodeBase64(
`https://lanyard-profile-readme.vercel.app/assets/unknown.png`
)}" style="
` : `
<img src="data:image/png;base64,${await encodeBase64(`https://lanyard-profile-readme.vercel.app/assets/unknown.png`)}" style="
width: 70px;
height: 70px;
margin-top: 4px;
filter: invert(100);
"/>
`
}
${activity.assets && activity.assets.small_image
? `
<img src="data:image/png;base64,${await encodeBase64(
`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.webp`
)}" style="
`}
${activity.assets && activity.assets.small_image ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.webp`)}"
style="
width: 30px;
height: 30px;
border-radius: 50%;
margin-left: -26px;
margin-bottom: -8px;
"/>`
: ``
}
"/>` : ``
}
</div>
<div style="
color: #999;
@@ -268,10 +247,10 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
line-height: 1;
width: 279px;
">
<p style="font-size: 0.7rem; color: ${theme === "dark" ? "#7289DA" : "#334da6"
}; margin-bottom: 15px;">PLAYING A GAME...</p>
<p style="font-size: 0.75rem; font-weight: bold; color: ${theme === "dark" ? "#7289DA" : "#334da6"}; margin-bottom: 15px;">PLAYING A GAME...</p>
<p style="
color: ${theme === "dark" ? "#fff" : "#000"}; \
color: ${theme === "dark" ? "#fff" : "#000"};
font-size: 0.85rem;
font-weight: bold;
overflow: hidden;
white-space: nowrap;
@@ -279,27 +258,23 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
height: 15px;
margin: 7px 0;
">${activity.name}</p>
${activity.details
? `
${activity.details ? `
<p style="
color: ${theme === "dark" ? "#ccc" : "#777"};
overflow: hidden;
white-space: nowrap;
font-size: 0.85rem;
text-overflow: ellipsis;
height: 15px;
margin: 7px 0;
">${activity.details}</p>`
: ``
}
">${activity.details}</p>` : ``
}
</div>
</div>
`
: ``
}
` : ``
}
${body.data.listening_to_spotify === true &&
body.data.activities[Object.keys(body.data.activities).length - 1].type === 2
? `
${body.data.listening_to_spotify === true && body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 ? `
<div style="
display: flex;
flex-direction: row;
@@ -322,29 +297,29 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
line-height: 1;
width: 279px;
">
<p style="font-size: 0.75rem; color: ${theme === "dark" ? "#1CB853" : "#0d943d"
}; margin-bottom: 15px;">LISTENING NOW...</p>
<p style="font-size: 0.75rem; font-weight: bold; color: ${theme === "dark" ? "#1CB853" : "#0d943d"}; margin-bottom: 15px;">LISTENING TO SPOTIFY...</p>
<p style="
height: 15px;
color: ${theme === "dark" ? "#fff" : "#000"};
font-weight: bold;
font-size: 0.85rem;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin: 7px 0;
">${body.data.spotify.song.replace(/\&/g, "and")}</p>
">${escape(body.data.spotify.song)}</p>
<p style="
margin: 7px 0;
height: 15px;
overflow: hidden;
white-space: nowrap;
font-size: 0.85rem;
text-overflow: ellipsis;
color: ${theme === "dark" ? "#ccc" : "#777"};
">By ${body.data.spotify.artist.replace(/\;/g, ",").replace(/\&/g, "and")}</p>
">By ${escape(body.data.spotify.artist)}</p>
</div>
</div>
`
: ``
` : ``
}
${!activity && body.data.listening_to_spotify === false
? `<div style="

View File

@@ -1145,6 +1145,11 @@ escalade@^3.1.1:
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==
escape-html@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"