From d5fb04015157b569c739284fdc8466b0cc0deb2c Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Mon, 29 Jan 2024 18:48:42 -0600 Subject: [PATCH 1/6] Small Images --- index.js | 49 +++++++++++++++++++++++++++++++++++------------- static/style.css | 10 ++++++++++ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index d2d00b6..213418a 100644 --- a/index.js +++ b/index.js @@ -44,15 +44,11 @@ if (!fs.existsSync(path.join(staticpath, 'cached'))) { var randomQuotes = config.quotes -function get_img_url(activity) { +function get_img_url(activity, size="large_image") { if ("assets" in activity) { - var image = undefined - if ("large_image" in activity.assets) { - image = activity.assets.large_image - } else if ("small_image" in activity.assets) { - image = activity.assets.small_image - } + var image = activity.assets[size] + if (image) { if (image.includes("https/")) { return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length)) @@ -198,9 +194,9 @@ async function pageUpdate() { } - function get_img(activity) { - if (get_img_url(activity)) { - var fn = sha256(get_img_url(activity)) + function get_img(activity, size="large_image") { + if (get_img_url(activity, size)) { + var fn = sha256(get_img_url(activity, size)) var fp = path.join(staticpath, 'cached', fn) if (!fs.existsSync(fp)) { @@ -272,10 +268,19 @@ async function pageUpdate() { activity.assets = { "large_text": " ", "small_text": " " } } + function smch() { + console.log(activity.name, get_img_url(activity, "small_image")) + if (get_img_url(activity, "small_image")) { + return `` + } + return "" + } + addedHTML += `
- + + ${smch()}

Playing ${activity.name}
${(activity.details || activity.assets.large_text || " ")} @@ -405,8 +410,6 @@ lanyard.addEventListener("message", (res) => { for (let index = 0; index < lanyardData.activities.length; index++) { const activity = lanyardData.activities[index]; - - if (get_img_url(activity)) { var fn = sha256(get_img_url(activity)) var fp = path.join(__dirname, 'static/cached', fn) @@ -426,7 +429,27 @@ lanyard.addEventListener("message", (res) => { }) } } + if (get_img_url(activity, "small_image")) { + var fn = sha256(get_img_url(activity, "small_image")) + var fp = path.join(__dirname, 'static/cached', fn) + if (!fs.existsSync(fp)) { + var wrst = fs.createWriteStream(fp) + + fetch(`${get_img_url(activity, "small_image")}`) + .then((response) => response.body) + .then((body) => { + const stream = new WritableStream({ + write(chunk) { + wrst.write(chunk) + } + }) + + body.pipeTo(stream) + }) + } + } } + } }) diff --git a/static/style.css b/static/style.css index 6bc81ca..b7d1450 100644 --- a/static/style.css +++ b/static/style.css @@ -107,6 +107,16 @@ a { object-fit: cover; } +.activity > .smallimg { + width: 64px; + height: 64px; + position: absolute; + bottom: 0px; + border-top-right-radius: 15px; + /* border-right: 2px gray solid; + border-top: 2px gray solid; */ +} + a:hover { color: white; transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1); From c234fc39198641ade848f4193671929b956aca9d Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Mon, 29 Jan 2024 18:49:04 -0600 Subject: [PATCH 2/6] Remove Debug --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 213418a..46262f4 100644 --- a/index.js +++ b/index.js @@ -269,7 +269,6 @@ async function pageUpdate() { } function smch() { - console.log(activity.name, get_img_url(activity, "small_image")) if (get_img_url(activity, "small_image")) { return `` } From 2ac05814cb3f4b3b368ed909c7224b983304c2a7 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Mon, 29 Jan 2024 18:58:58 -0600 Subject: [PATCH 3/6] Better formatting --- static/style.css | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/static/style.css b/static/style.css index b7d1450..d8ccacd 100644 --- a/static/style.css +++ b/static/style.css @@ -112,9 +112,16 @@ a { height: 64px; position: absolute; bottom: 0px; - border-top-right-radius: 15px; - /* border-right: 2px gray solid; - border-top: 2px gray solid; */ + left: 74px; + border-radius: 50px; + border: 2px gray solid; + transform: scale(0.8); +} + +.activity > .smallimg:hover { + border: 2px white solid; + transform: scale(1); + } a:hover { From 1b0d6ad14b718c1230fba02ae12730e965eb554b Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Tue, 30 Jan 2024 22:03:41 +0000 Subject: [PATCH 4/6] Update super duper outdated todo list in README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d61309..2bb8693 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ Violet's Purgatory is hosted on Railway right now, but there are plans to move t We also have an API, which can be located at https://api.violets-purgatory.dev, which is currently very under developed, but will continue to have updates for features I see fit. ## To-do -- [ ] Add image caching instead of using image proxies (keeps the security benefit and decreases loading times) +- [x] Add image caching instead of using image proxies (keeps the security benefit and decreases loading times) +- [x] Add code to automatically minify the HTML +- [x] Add random quotes +- [x] Seperate Values from the javascript into their own config for readability +- [ ] Stop using Lanyard Web Socket Directly and proxy it through the API (Alternatively, self host the Lanyard API) - [ ] Cut the main CSS file into multiple so that only the nessacary CSS is loaded (Reduces traffic and loading times) - [ ] Add a commit counter \ No newline at end of file From 69ccb79601f4f7c680db06f1d7a3ee358d858149 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Thu, 1 Feb 2024 19:22:41 +0000 Subject: [PATCH 5/6] Update Embed --- resources/mainPage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/mainPage.html b/resources/mainPage.html index b99257a..0b26c4e 100644 --- a/resources/mainPage.html +++ b/resources/mainPage.html @@ -12,7 +12,7 @@ - + From 6978654b5c306ebdbe1b6773027003190231f627 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Thu, 1 Feb 2024 19:23:48 +0000 Subject: [PATCH 6/6] Fix url? (I thought I already fixed this...) --- resources/mainPage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/mainPage.html b/resources/mainPage.html index 0b26c4e..c238ec0 100644 --- a/resources/mainPage.html +++ b/resources/mainPage.html @@ -13,7 +13,7 @@ - +