mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-26 04:17:19 +00:00
update: escape chars to prevent parsing errors, bolden activity header text, reformatting
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/styled-components": "^5.1.10",
|
"@types/styled-components": "^5.1.10",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
|
"escape-html": "^1.0.3",
|
||||||
"framer-motion": "^4.1.17",
|
"framer-motion": "^4.1.17",
|
||||||
"image-to-base64": "^2.2.0",
|
"image-to-base64": "^2.2.0",
|
||||||
"next": "11.0.0",
|
"next": "11.0.0",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import * as LanyardTypes from "./LanyardTypes";
|
|||||||
import { encodeBase64 } from "./toBase64";
|
import { encodeBase64 } from "./toBase64";
|
||||||
import { blue, green, gray, gold, red } from "./defaultAvatars"
|
import { blue, green, gray, gold, red } from "./defaultAvatars"
|
||||||
|
|
||||||
|
let escape = require('escape-html');
|
||||||
|
|
||||||
type Parameters = {
|
type Parameters = {
|
||||||
theme?: string;
|
theme?: string;
|
||||||
bg?: string;
|
bg?: string;
|
||||||
@@ -153,16 +155,12 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
font-size: 1.15rem;
|
font-size: 1.15rem;
|
||||||
margin: 0 5px 0 0;
|
margin: 0 5px 0 0;
|
||||||
">
|
">
|
||||||
${body.data.discord_user.username}${discrim !== "hide"
|
${escape(body.data.discord_user.username)}${discrim !== "hide" ?
|
||||||
? `<span style="color: ${theme === "dark" ? "#ccc" : "#666"}; font-weight: lighter;">#${body.data.discord_user.discriminator
|
`<span style="color: ${theme === "dark" ? "#ccc" : "#666"}; font-weight: lighter;">#${body.data.discord_user.discriminator}</span>`
|
||||||
}</span>`
|
: "" }
|
||||||
: ""
|
|
||||||
}
|
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
${flags
|
${flags.map(v => `
|
||||||
.map(
|
|
||||||
v => `
|
|
||||||
<img src="data:image/png;base64,${Badges[v]}" style="
|
<img src="data:image/png;base64,${Badges[v]}" style="
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
@@ -170,12 +168,9 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(0%, -50%);
|
transform: translate(0%, -50%);
|
||||||
margin: 0 0 0 4px;
|
margin: 0 0 0 4px;
|
||||||
" />`
|
" />`).join("")}
|
||||||
)
|
|
||||||
.join("")}
|
|
||||||
</div>
|
</div>
|
||||||
${userStatus.length > 0 && hideStatus !== "true"
|
${userStatus.length > 0 && hideStatus !== "true" ? `
|
||||||
? `
|
|
||||||
<h1 style="
|
<h1 style="
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
@@ -185,34 +180,27 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
">
|
">
|
||||||
${body.data.activities[0].emoji && body.data.activities[0].emoji.id
|
${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}`)}"
|
||||||
<img src="data:image/png;base64,${await encodeBase64(
|
style="
|
||||||
`https://cdn.discordapp.com/emojis/${body.data.activities[0].emoji.id}.${statusExtension}`
|
|
||||||
)}" style="
|
|
||||||
width: 15px;
|
width: 15px;
|
||||||
height: 15px;
|
height: 15px;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
transform: translate(0%, -50%);
|
transform: translate(0%, -50%);
|
||||||
margin: 0 2px 0 0;
|
margin: 0 2px 0 0;
|
||||||
" />`
|
" />` : ``
|
||||||
: ``
|
}
|
||||||
}
|
|
||||||
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id
|
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id
|
||||||
? body.data.activities[0].emoji.name +
|
? body.data.activities[0].emoji.name + " " + escape(userStatus)
|
||||||
" " +
|
: escape(userStatus)
|
||||||
userStatus.replace(/\&/g, "and")
|
}
|
||||||
: userStatus.replace(/\&/g, "and")
|
</h1>` : ``
|
||||||
}
|
}
|
||||||
</h1>`
|
|
||||||
: ``
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${activity
|
${activity ? `
|
||||||
? `
|
|
||||||
<div style="
|
<div style="
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -226,41 +214,32 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
">
|
">
|
||||||
${activity.assets && activity.assets.large_image
|
${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`)}"
|
||||||
<img src="data:image/png;base64,${await encodeBase64(
|
style="
|
||||||
`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.webp`
|
|
||||||
)}" style="
|
|
||||||
width: 80px;
|
width: 80px;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
border: solid 0.5px #222;
|
border: solid 0.5px #222;
|
||||||
border-radius: 10px;
|
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;
|
width: 70px;
|
||||||
height: 70px;
|
height: 70px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
filter: invert(100);
|
filter: invert(100);
|
||||||
"/>
|
"/>
|
||||||
`
|
`}
|
||||||
}
|
${activity.assets && activity.assets.small_image ? `
|
||||||
${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="
|
||||||
<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;
|
width: 30px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
margin-left: -26px;
|
margin-left: -26px;
|
||||||
margin-bottom: -8px;
|
margin-bottom: -8px;
|
||||||
"/>`
|
"/>` : ``
|
||||||
: ``
|
}
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
<div style="
|
<div style="
|
||||||
color: #999;
|
color: #999;
|
||||||
@@ -268,10 +247,10 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
width: 279px;
|
width: 279px;
|
||||||
">
|
">
|
||||||
<p style="font-size: 0.7rem; color: ${theme === "dark" ? "#7289DA" : "#334da6"
|
<p style="font-size: 0.75rem; font-weight: bold; color: ${theme === "dark" ? "#7289DA" : "#334da6"}; margin-bottom: 15px;">PLAYING A GAME...</p>
|
||||||
}; margin-bottom: 15px;">PLAYING A GAME...</p>
|
|
||||||
<p style="
|
<p style="
|
||||||
color: ${theme === "dark" ? "#fff" : "#000"}; \
|
color: ${theme === "dark" ? "#fff" : "#000"};
|
||||||
|
font-size: 0.85rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -279,27 +258,23 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
height: 15px;
|
height: 15px;
|
||||||
margin: 7px 0;
|
margin: 7px 0;
|
||||||
">${activity.name}</p>
|
">${activity.name}</p>
|
||||||
${activity.details
|
${activity.details ? `
|
||||||
? `
|
|
||||||
<p style="
|
<p style="
|
||||||
color: ${theme === "dark" ? "#ccc" : "#777"};
|
color: ${theme === "dark" ? "#ccc" : "#777"};
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
font-size: 0.85rem;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
height: 15px;
|
height: 15px;
|
||||||
margin: 7px 0;
|
margin: 7px 0;
|
||||||
">${activity.details}</p>`
|
">${activity.details}</p>` : ``
|
||||||
: ``
|
}
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
` : ``
|
||||||
: ``
|
}
|
||||||
}
|
|
||||||
|
|
||||||
${body.data.listening_to_spotify === true &&
|
${body.data.listening_to_spotify === true && body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 ? `
|
||||||
body.data.activities[Object.keys(body.data.activities).length - 1].type === 2
|
|
||||||
? `
|
|
||||||
<div style="
|
<div style="
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -322,29 +297,29 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
width: 279px;
|
width: 279px;
|
||||||
">
|
">
|
||||||
<p style="font-size: 0.75rem; color: ${theme === "dark" ? "#1CB853" : "#0d943d"
|
<p style="font-size: 0.75rem; font-weight: bold; color: ${theme === "dark" ? "#1CB853" : "#0d943d"}; margin-bottom: 15px;">LISTENING TO SPOTIFY...</p>
|
||||||
}; margin-bottom: 15px;">LISTENING NOW...</p>
|
|
||||||
<p style="
|
<p style="
|
||||||
height: 15px;
|
height: 15px;
|
||||||
color: ${theme === "dark" ? "#fff" : "#000"};
|
color: ${theme === "dark" ? "#fff" : "#000"};
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
font-size: 0.85rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
margin: 7px 0;
|
margin: 7px 0;
|
||||||
">${body.data.spotify.song.replace(/\&/g, "and")}</p>
|
">${escape(body.data.spotify.song)}</p>
|
||||||
<p style="
|
<p style="
|
||||||
margin: 7px 0;
|
margin: 7px 0;
|
||||||
height: 15px;
|
height: 15px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
font-size: 0.85rem;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
color: ${theme === "dark" ? "#ccc" : "#777"};
|
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>
|
||||||
</div>
|
</div>
|
||||||
`
|
` : ``
|
||||||
: ``
|
|
||||||
}
|
}
|
||||||
${!activity && body.data.listening_to_spotify === false
|
${!activity && body.data.listening_to_spotify === false
|
||||||
? `<div style="
|
? `<div style="
|
||||||
|
|||||||
@@ -1145,6 +1145,11 @@ escalade@^3.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
|
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
|
||||||
integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==
|
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:
|
escape-string-regexp@^1.0.5:
|
||||||
version "1.0.5"
|
version "1.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||||
|
|||||||
Reference in New Issue
Block a user