mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-25 04:17:18 +00:00
🌟 Code Cleanup
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"styled-components": "^5.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/image-to-base64": "^2.1.0",
|
||||
"@types/react": "17.0.11",
|
||||
"eslint": "7.28.0",
|
||||
"eslint-config-next": "11.0.0",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { AppProps } from 'next/app'
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
export default function LandyardReadMe({ Component, pageProps }: AppProps) {
|
||||
return <Component {...pageProps} />
|
||||
}
|
||||
export default MyApp
|
||||
|
||||
@@ -2,14 +2,14 @@ import Document from 'next/document'
|
||||
import { ServerStyleSheet } from 'styled-components'
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
static async getInitialProps(ctx) {
|
||||
const sheet = new ServerStyleSheet()
|
||||
const originalRenderPage = ctx.renderPage
|
||||
static async getInitialProps(ctx: any) {
|
||||
const sheet = new ServerStyleSheet(),
|
||||
originalRenderPage = ctx.renderPage
|
||||
|
||||
try {
|
||||
ctx.renderPage = () =>
|
||||
originalRenderPage({
|
||||
enhanceApp: (App) => (props) =>
|
||||
enhanceApp: (App: any) => (props: any) =>
|
||||
sheet.collectStyles(<App {...props} />),
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ type Data = {
|
||||
}
|
||||
|
||||
type Parameters = {
|
||||
animated?: string;
|
||||
animated?: string;
|
||||
}
|
||||
|
||||
export default async function handler(
|
||||
@@ -17,24 +17,21 @@ export default async function handler(
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
|
||||
let params: Parameters = req.query;
|
||||
let userid = req.query.id[0];
|
||||
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
|
||||
res.setHeader("content-security-policy", "default-src 'none'; img-src *; style-src 'unsafe-inline'");
|
||||
let params: Parameters = req.query,
|
||||
userid = req.query.id[0],
|
||||
lanyardData: any;
|
||||
|
||||
let lanyardData: any;
|
||||
|
||||
await axios.get(`https://api.lanyard.rest/v1/users/${userid}`)
|
||||
.then((response) => {
|
||||
return lanyardData = response;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.send({ error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.` })
|
||||
});
|
||||
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
|
||||
res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'");
|
||||
|
||||
let svg = await renderCard(lanyardData.data, params);
|
||||
res.status(200).send(svg);
|
||||
try {
|
||||
lanyardData = (await axios.get(`https://api.lanyard.rest/v1/users/${userid}`)).data;
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
res.send({ error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.` })
|
||||
}
|
||||
|
||||
console.log(req.query);
|
||||
let svg = await renderCard(lanyardData.data, params);
|
||||
res.status(200).send(svg as any);
|
||||
}
|
||||
@@ -3,15 +3,13 @@ import styled from 'styled-components';
|
||||
import { useState } from 'react';
|
||||
|
||||
export default function Home() {
|
||||
|
||||
let [userId, setUserId] = useState(':id')
|
||||
const [userId, setUserId] = useState(':id')
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400&display=swap" rel="stylesheet" />
|
||||
|
||||
<title>Lanyard for GitHub Profile</title>
|
||||
</Head>
|
||||
|
||||
@@ -19,28 +17,16 @@ export default function Home() {
|
||||
<Header>
|
||||
🏷️ lanyard-profile-readme
|
||||
</Header>
|
||||
|
||||
<Container>
|
||||
|
||||
<p style={{fontSize: "1rem", fontWeight: "bold", marginTop: "1rem"}}>Make sure you're in the <a style={{color: "#fff"}} rel="noreferrer" href="https://discord.com/invite/WScAm7vNGF">Discord</a> for this to work.</p>
|
||||
|
||||
<Input maxLength={18} type="text" placeholder="Paste your Discord user ID here" onChange={((e) => setUserId(e.target.value))}>
|
||||
|
||||
</Input>
|
||||
|
||||
<span style={{fontSize: "1rem", marginTop: "1rem"}}>Copy the following and paste it into your README.md</span>
|
||||
|
||||
<p style={{ fontSize: "1rem", fontWeight: "bold", marginTop: "1rem" }}>Make sure you're in the <a style={{ color: "#fff" }} rel="noreferrer" href="https://discord.com/invite/WScAm7vNGF">Discord</a> for this to work.</p>
|
||||
<Input maxLength={18} type="text" placeholder="Paste your Discord user ID here" onChange={((e) => setUserId(e.target.value))} />
|
||||
<span style={{ fontSize: "1rem", marginTop: "1rem" }}>Copy the following and paste it into your README.md</span>
|
||||
<Link>
|
||||
[](https://discord.com/users/{userId})
|
||||
</Link>
|
||||
|
||||
<span style={{fontSize: "1rem", fontStyle: "italic", marginTop: "1rem"}}>For further customization, check out the <a rel="noreferrer" target="_blank" href="https://github.com/cnrad/lanyard-profile-readme" style={{color: "#fff", fontWeight: "bold"}}>repo</a>!</span>
|
||||
|
||||
<Example src={`https://lanyard-profile-readme.vercel.app/api/${userId}`} alt="[Please provide a valid user ID!]" style={{color: "#ff8787"}}/>
|
||||
|
||||
|
||||
<span style={{ fontSize: "1rem", fontStyle: "italic", marginTop: "1rem" }}>For further customization, check out the <a rel="noreferrer" target="_blank" href="https://github.com/cnrad/lanyard-profile-readme" style={{ color: "#fff", fontWeight: "bold" }}>repo</a>!</span>
|
||||
<Example src={`https://lanyard-profile-readme.vercel.app/api/${userId}`} alt="[Please provide a valid user ID!]" style={{ color: "#ff8787" }} />
|
||||
</Container>
|
||||
|
||||
</Background>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -1,36 +1,16 @@
|
||||
export const getFlags = (flag:number): string[] => {
|
||||
export const getFlags = (flag: number): string[] => {
|
||||
let flags: string[] = [];
|
||||
|
||||
if(flag & 1){
|
||||
flags.push("Discord_Employee")
|
||||
}
|
||||
if(flag & 2){
|
||||
flags.push("Partnered_Server_Owner")
|
||||
}
|
||||
if(flag & 4){
|
||||
flags.push("HypeSquad_Events")
|
||||
}
|
||||
if(flag & 8){
|
||||
flags.push("Bug_Hunter_Level_1")
|
||||
}
|
||||
if(flag & 64){
|
||||
flags.push("House_Bravery")
|
||||
}
|
||||
if(flag & 128){
|
||||
flags.push("House_Brilliance")
|
||||
}
|
||||
if(flag & 256){
|
||||
flags.push("House_Balance")
|
||||
}
|
||||
if(flag & 512){
|
||||
flags.push("Early_Supporter")
|
||||
}
|
||||
if(flag & 16384){
|
||||
flags.push("Bug_Hunter_Level_2")
|
||||
}
|
||||
if(flag & 131072){
|
||||
flags.push("Early_Verified_Bot_Developer")
|
||||
}
|
||||
if (flag & 1) flags.push("Discord_Employee")
|
||||
if (flag & 2) flags.push("Partnered_Server_Owner")
|
||||
if (flag & 4) flags.push("HypeSquad_Events")
|
||||
if (flag & 8) flags.push("Bug_Hunter_Level_1")
|
||||
if (flag & 64) flags.push("House_Bravery")
|
||||
if (flag & 128) flags.push("House_Brilliance")
|
||||
if (flag & 256) flags.push("House_Balance")
|
||||
if (flag & 512) flags.push("Early_Supporter")
|
||||
if (flag & 16384) flags.push("Bug_Hunter_Level_2")
|
||||
if (flag & 131072) flags.push("Early_Verified_Bot_Developer")
|
||||
|
||||
return flags;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
//probably the messiest code i've ever written but it works so :)
|
||||
|
||||
import { Badges } from '../public/assets/badges/BadgesEncoded';
|
||||
import { getFlags } from './getFlags';
|
||||
import * as LanyardTypes from './LanyardTypes';
|
||||
import { getFlags } from "./getFlags";
|
||||
import encodeBase64 from './toBase64';
|
||||
import { Badges } from '../public/assets/badges/BadgesEncoded'
|
||||
import { encodeBase64 } from './toBase64';
|
||||
|
||||
type Parameters = {
|
||||
theme?: string;
|
||||
@@ -13,57 +13,48 @@ type Parameters = {
|
||||
hideStatus?: string;
|
||||
}
|
||||
|
||||
const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<any> => {
|
||||
|
||||
let avatarBorderColor: string = "#747F8D";
|
||||
let userStatus: string = "";
|
||||
let avatarExtension: string = "webp";
|
||||
let statusExtension: string = "webp";
|
||||
let activity: any = false;
|
||||
let backgroundColor: string = '1a1c1f';
|
||||
let theme = 'dark';
|
||||
let discrim = 'show';
|
||||
let hideStatus = 'false';
|
||||
const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<string> => {
|
||||
const defaultAvatar: string = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAY1BMVEVYZfJib/OMlfahqPeWn/eBi/XLz/vq6/7////19f5tePTq7P22vPnV2Pyrsvirsvl3gvT09f7Axfp3gfRtePNsePPg4v22vPq2u/qCi/WhqPjf4/zf4v2Xn/essvjLzvuXnvdbidFTAAAETElEQVR4AezBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAIDZudMtV1UlDuCFRKlWIEJ6uOwbzXn/lzzzYc/GWiT6zya/79WrLeYSc5Vq9IFWa3Sr6JehWt0ZZn5RtFJvmHnodPsrPLx1/B9PKx1ziLOPnIRRO84EXaAP/CWnR3pArTWcybpA5G8NsX20pw+cSbpAngEeOQenY+Cf8KIZ4FuDfSV4Ko/7hS7wNjYH7W3MvNeHtn2jvxn+OXcgaP0x8KJo43vgnwqu85EXDfGVULWON9G1BOmDN/M/AnTgDSWC0xve0KAITeSsykFw4qzOQWB4YwNBOfLmPAHpeXsvr5XOgJkjGA3vIlU6A2bvOHvAnXwiCMrwTl5UpUtg5us7BAB2gcg78nXugaC6QORd+bo7AEAXiLwzX+8SANEFNHPdXcAwV90FDgxA037+zwAc7aZlCKnSNTDrADZBdU6DBwbha5wCAabBkWGkSqfAzFa6C8xeADYB9Y2ByEBsbSMAYAy0zHWPActQLPQuKBh3DiwiDRlwzwFOv9JfTpORh5x5rVfQc8CQiLLJiEMaA1oW6XgVq+grVh4yY56JA68x07fm8hCIhXCUPn823zgkG/HK4Rf6kYv8YBt5BQ03BQyv9CMq8M/JQ7IItw+e6cd8QQjKTqCX3OMTtOdCCNZOoCnqkrYgZEFD2/FF/08qDAE4Dji+TtHPKHknVmBboVB2i9HI9zIGahZUhaVqVxCyQEEVQ7rSBMj3QiPUUTCWJkC+8zrQVjzmELBYG2H5jDYUFqAiQDlMtAwKQgjr+nwoq9O2BSEQJQFVWKeNBSEQ6+BYeG3BFIUAHIfasmsLh7IQgLcjDZd0AWXEIZRDMDYCuuj73g95yJGxEuBLPmr6VBSyzMO9Fpzko3kqeA1r8W4GHOWNKQ/JIl4COL4SZf2lPAQhAY4lYrv860rlIVmHlYAsuBhjFwpCwO4LOkb0TMAzAc8EPBPwTMAGngl4JuCZgMig4jMB27AMykJUhCr4ekwzKI10T9hpwzcz6DNSUbRdORzThW/CJSKagd4LjKurof1suFCYVR54MDckpsBXDLk3pliQgxBTHneBrwiaNtOfeUUKCnMQYlKC32x2r7SlmSUpoOQdi5xtoqx1DNP8WW9kKSCVvAu8QnC2USR4/I2bP5vDmhS80pdOjXULw8dc7HSiL6ljYLTmz/ooKvJTdkqTt9G5s/mHczH6qXlV9I32Ehi0+QVfQbn7HryHhvY033V1Tuu3CRncOIj3rL3EV9pf7+53ced0bY+MIZm7ndEt9uNnkxN8OSWhAvjjZ8ktnIoKaMDHF0yH8S416C4Rpv7bU094pWJ9QFv4BJOBvnkFzjWKMvhu4G78IibMIz2EFM3KFUAwCEI+ID9MDia6kd/+enpFj+YE+af+aA8OZAAAAAAG+Vvf46sAAAAAAAAAAAAAAAAAAAAAAFYCeHSjWah9hFcAAAAASUVORK5CYII=";
|
||||
|
||||
if(body.data.activities[0]){
|
||||
if(body.data.activities[0].emoji && body.data.activities[0].emoji.animated === true) statusExtension = "gif";
|
||||
}
|
||||
let avatarBorderColor: string = "#747F8D",
|
||||
userStatus: string = "",
|
||||
avatarExtension: string = "webp",
|
||||
statusExtension: string = "webp",
|
||||
activity: any = false,
|
||||
backgroundColor: string = '1a1c1f',
|
||||
theme = 'dark',
|
||||
discrim = 'show',
|
||||
hideStatus = 'false';
|
||||
|
||||
if(body.data.activities.length > 0) {
|
||||
if(body.data.activities[Object.keys(body.data.activities).length - 1].type === 0) activity = body.data.activities[Object.keys(body.data.activities).length - 1];
|
||||
}
|
||||
|
||||
let defaultAvatar: string = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAY1BMVEVYZfJib/OMlfahqPeWn/eBi/XLz/vq6/7////19f5tePTq7P22vPnV2Pyrsvirsvl3gvT09f7Axfp3gfRtePNsePPg4v22vPq2u/qCi/WhqPjf4/zf4v2Xn/essvjLzvuXnvdbidFTAAAETElEQVR4AezBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAIDZudMtV1UlDuCFRKlWIEJ6uOwbzXn/lzzzYc/GWiT6zya/79WrLeYSc5Vq9IFWa3Sr6JehWt0ZZn5RtFJvmHnodPsrPLx1/B9PKx1ziLOPnIRRO84EXaAP/CWnR3pArTWcybpA5G8NsX20pw+cSbpAngEeOQenY+Cf8KIZ4FuDfSV4Ko/7hS7wNjYH7W3MvNeHtn2jvxn+OXcgaP0x8KJo43vgnwqu85EXDfGVULWON9G1BOmDN/M/AnTgDSWC0xve0KAITeSsykFw4qzOQWB4YwNBOfLmPAHpeXsvr5XOgJkjGA3vIlU6A2bvOHvAnXwiCMrwTl5UpUtg5us7BAB2gcg78nXugaC6QORd+bo7AEAXiLwzX+8SANEFNHPdXcAwV90FDgxA037+zwAc7aZlCKnSNTDrADZBdU6DBwbha5wCAabBkWGkSqfAzFa6C8xeADYB9Y2ByEBsbSMAYAy0zHWPActQLPQuKBh3DiwiDRlwzwFOv9JfTpORh5x5rVfQc8CQiLLJiEMaA1oW6XgVq+grVh4yY56JA68x07fm8hCIhXCUPn823zgkG/HK4Rf6kYv8YBt5BQ03BQyv9CMq8M/JQ7IItw+e6cd8QQjKTqCX3OMTtOdCCNZOoCnqkrYgZEFD2/FF/08qDAE4Dji+TtHPKHknVmBboVB2i9HI9zIGahZUhaVqVxCyQEEVQ7rSBMj3QiPUUTCWJkC+8zrQVjzmELBYG2H5jDYUFqAiQDlMtAwKQgjr+nwoq9O2BSEQJQFVWKeNBSEQ6+BYeG3BFIUAHIfasmsLh7IQgLcjDZd0AWXEIZRDMDYCuuj73g95yJGxEuBLPmr6VBSyzMO9Fpzko3kqeA1r8W4GHOWNKQ/JIl4COL4SZf2lPAQhAY4lYrv860rlIVmHlYAsuBhjFwpCwO4LOkb0TMAzAc8EPBPwTMAGngl4JuCZgMig4jMB27AMykJUhCr4ekwzKI10T9hpwzcz6DNSUbRdORzThW/CJSKagd4LjKurof1suFCYVR54MDckpsBXDLk3pliQgxBTHneBrwiaNtOfeUUKCnMQYlKC32x2r7SlmSUpoOQdi5xtoqx1DNP8WW9kKSCVvAu8QnC2USR4/I2bP5vDmhS80pdOjXULw8dc7HSiL6ljYLTmz/ooKvJTdkqTt9G5s/mHczH6qXlV9I32Ehi0+QVfQbn7HryHhvY033V1Tuu3CRncOIj3rL3EV9pf7+53ced0bY+MIZm7ndEt9uNnkxN8OSWhAvjjZ8ktnIoKaMDHF0yH8S416C4Rpv7bU094pWJ9QFv4BJOBvnkFzjWKMvhu4G78IibMIz2EFM3KFUAwCEI+ID9MDia6kd/+enpFj+YE+af+aA8OZAAAAAAG+Vvf46sAAAAAAAAAAAAAAAAAAAAAAFYCeHSjWah9hFcAAAAASUVORK5CYII=";
|
||||
|
||||
if(body.data.discord_user.avatar !== null && body.data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
|
||||
|
||||
if(params.animated === "false") avatarExtension = "webp";
|
||||
if(params.hideDiscrim === "true") discrim = "hide";
|
||||
if(params.theme === 'light'){
|
||||
if (body.data.activities[0] && body.data.activities[0].emoji && body.data.activities[0].emoji.animated) statusExtension = "gif";
|
||||
if (body.data.activities.length > 0 && body.data.activities[Object.keys(body.data.activities).length - 1].type === 0) activity = body.data.activities[Object.keys(body.data.activities).length - 1];
|
||||
if (params.animated === "false") avatarExtension = "webp";
|
||||
if (params.hideStatus === 'true') hideStatus = 'true';
|
||||
if (params.hideDiscrim === "true") discrim = "hide";
|
||||
if (params.bg) backgroundColor = params.bg;
|
||||
if (params.theme === 'light') {
|
||||
backgroundColor = '#eee';
|
||||
theme = 'light';
|
||||
}
|
||||
if(params.bg) backgroundColor = params.bg;
|
||||
if(params.hideStatus === 'true') hideStatus = 'true';
|
||||
|
||||
switch(body.data.discord_status){
|
||||
case "online":
|
||||
switch (body.data.discord_status) {
|
||||
case "online":
|
||||
avatarBorderColor = "#43B581";
|
||||
break;
|
||||
case "idle":
|
||||
case "idle":
|
||||
avatarBorderColor = "#FAA61A";
|
||||
break;
|
||||
case "dnd":
|
||||
case "dnd":
|
||||
avatarBorderColor = "#F04747";
|
||||
break;
|
||||
case "offline":
|
||||
case "offline":
|
||||
avatarBorderColor = "#747F8D";
|
||||
break;
|
||||
}
|
||||
|
||||
let flags: string[] = getFlags(body.data.discord_user.public_flags);
|
||||
const flags: string[] = getFlags(body.data.discord_user.public_flags);
|
||||
|
||||
if(body.data.activities[0] && body.data.activities[0].type === 4) userStatus = body.data.activities[0].state;
|
||||
if (body.data.activities[0] && body.data.activities[0].type === 4) userStatus = body.data.activities[0].state;
|
||||
|
||||
console.log(Object.keys(body.data.activities).length);
|
||||
|
||||
@@ -100,8 +91,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
width: 80px;
|
||||
">
|
||||
<img ${body.data.discord_user.avatar !== null ?
|
||||
`src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256`)}"` :
|
||||
`src="data:image/png;base64,${defaultAvatar}"`}
|
||||
`src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256`)}"` :
|
||||
`src="data:image/png;base64,${defaultAvatar}"`}
|
||||
style="
|
||||
border: solid 3px ${avatarBorderColor};
|
||||
border-radius: 50%;
|
||||
@@ -131,14 +122,13 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
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>`
|
||||
: ''}
|
||||
`<span style="color: ${theme === 'dark' ? '#ccc' : '#666'}; font-weight: lighter;">#${body.data.discord_user.discriminator}</span>`
|
||||
: ''}
|
||||
</h1>
|
||||
|
||||
${
|
||||
flags.map((v) => {
|
||||
return(
|
||||
`<img src="data:image/png;base64,${Badges[v]}" style="
|
||||
${flags.map((v) => {
|
||||
return (
|
||||
`<img src="data:image/png;base64,${Badges[v]}" style="
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
position: relative;
|
||||
@@ -146,9 +136,9 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
transform: translate(0%, -50%);
|
||||
margin: 0 0 0 4px;
|
||||
" />`
|
||||
)
|
||||
}).join('')
|
||||
}
|
||||
)
|
||||
}).join('')
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@@ -163,7 +153,7 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
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="
|
||||
`<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;
|
||||
@@ -171,22 +161,22 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
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
|
||||
:
|
||||
userStatus
|
||||
}
|
||||
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id ?
|
||||
body.data.activities[0].emoji.name + ' ' + userStatus
|
||||
:
|
||||
userStatus
|
||||
}
|
||||
|
||||
</h1>`
|
||||
: ``}
|
||||
: ``}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${activity ?
|
||||
|
||||
`
|
||||
${activity ?
|
||||
|
||||
`
|
||||
<div style="
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -200,8 +190,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
width: 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`)}" style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
@@ -209,7 +199,7 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
border-radius: 10px;
|
||||
"/>
|
||||
`
|
||||
: `
|
||||
: `
|
||||
<img src="data:image/png;base64,${await encodeBase64(`https://lanyard-profile-readme.vercel.app/assets/unknown.png`)}" style="
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
@@ -218,15 +208,15 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
"/>
|
||||
`}
|
||||
|
||||
${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="
|
||||
@@ -245,8 +235,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
height: 15px;
|
||||
margin: 7px 0;
|
||||
">${activity.name}</p>
|
||||
${activity.details ?
|
||||
`<p style="
|
||||
${activity.details ?
|
||||
`<p style="
|
||||
color: ${theme === 'dark' ? '#ccc' : '#777'};
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
@@ -254,17 +244,17 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
height: 15px;
|
||||
margin: 7px 0;
|
||||
">${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;
|
||||
@@ -308,11 +298,11 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
: ``}
|
||||
|
||||
${!activity && body.data.listening_to_spotify === false ?
|
||||
`<div style="
|
||||
: ``}
|
||||
|
||||
${!activity && body.data.listening_to_spotify === false ?
|
||||
`<div style="
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 150px;
|
||||
@@ -328,7 +318,7 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
||||
I'm not currently doing anything!
|
||||
</p>
|
||||
</div>`
|
||||
: ``}
|
||||
: ``}
|
||||
|
||||
</div>
|
||||
</foreignObject>
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
const imageToBase64 = require('image-to-base64');
|
||||
import imageToBase64 from "image-to-base64";
|
||||
|
||||
const encodeBase64 = async (url: string): Promise<string> => {
|
||||
|
||||
let encoded: string = '';
|
||||
|
||||
await imageToBase64(url)
|
||||
.then(
|
||||
(response: string) => {
|
||||
return encoded = response;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(error: any) => {
|
||||
console.log(error);
|
||||
}
|
||||
)
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
export default encodeBase64;
|
||||
export const encodeBase64 = async (url: string): Promise<string> => await imageToBase64(url);
|
||||
@@ -279,6 +279,11 @@
|
||||
"@types/react" "*"
|
||||
hoist-non-react-statics "^3.3.0"
|
||||
|
||||
"@types/image-to-base64@^2.1.0":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/image-to-base64/-/image-to-base64-2.1.0.tgz#8c77b09b7988df3a9a2a4278bbcc27efabbec379"
|
||||
integrity sha512-UgmqJVJyPIkzzI23TWqLc9iO+hZTzNoVD0rEf+I70FeKtcxxvLIlKJ5CrejkxkvDc/8/lk9yswSYZoAv8eyOYQ==
|
||||
|
||||
"@types/json5@^0.0.29":
|
||||
version "0.0.29"
|
||||
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
|
||||
|
||||
Reference in New Issue
Block a user