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 diff --git a/index.js b/index.js index d2d00b6..46262f4 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,18 @@ async function pageUpdate() { activity.assets = { "large_text": " ", "small_text": " " } } + function smch() { + if (get_img_url(activity, "small_image")) { + return `` + } + return "" + } + addedHTML += `
Playing ${activity.name}
${(activity.details || activity.assets.large_text || " ")}
@@ -405,8 +409,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 +428,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/resources/mainPage.html b/resources/mainPage.html
index b99257a..c238ec0 100644
--- a/resources/mainPage.html
+++ b/resources/mainPage.html
@@ -12,8 +12,8 @@
-
-
+
+
diff --git a/static/style.css b/static/style.css
index 6bc81ca..d8ccacd 100644
--- a/static/style.css
+++ b/static/style.css
@@ -107,6 +107,23 @@ a {
object-fit: cover;
}
+.activity > .smallimg {
+ width: 64px;
+ height: 64px;
+ position: absolute;
+ bottom: 0px;
+ 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 {
color: white;
transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1);