Small Images
This commit is contained in:
parent
bc4b82965b
commit
d5fb040151
2 changed files with 46 additions and 13 deletions
49
index.js
49
index.js
|
@ -44,15 +44,11 @@ if (!fs.existsSync(path.join(staticpath, 'cached'))) {
|
||||||
|
|
||||||
var randomQuotes = config.quotes
|
var randomQuotes = config.quotes
|
||||||
|
|
||||||
function get_img_url(activity) {
|
function get_img_url(activity, size="large_image") {
|
||||||
|
|
||||||
if ("assets" in activity) {
|
if ("assets" in activity) {
|
||||||
var image = undefined
|
var image = activity.assets[size]
|
||||||
if ("large_image" in activity.assets) {
|
|
||||||
image = activity.assets.large_image
|
|
||||||
} else if ("small_image" in activity.assets) {
|
|
||||||
image = activity.assets.small_image
|
|
||||||
}
|
|
||||||
if (image) {
|
if (image) {
|
||||||
if (image.includes("https/")) {
|
if (image.includes("https/")) {
|
||||||
return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length))
|
return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length))
|
||||||
|
@ -198,9 +194,9 @@ async function pageUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_img(activity) {
|
function get_img(activity, size="large_image") {
|
||||||
if (get_img_url(activity)) {
|
if (get_img_url(activity, size)) {
|
||||||
var fn = sha256(get_img_url(activity))
|
var fn = sha256(get_img_url(activity, size))
|
||||||
var fp = path.join(staticpath, 'cached', fn)
|
var fp = path.join(staticpath, 'cached', fn)
|
||||||
|
|
||||||
if (!fs.existsSync(fp)) {
|
if (!fs.existsSync(fp)) {
|
||||||
|
@ -272,10 +268,19 @@ async function pageUpdate() {
|
||||||
activity.assets = { "large_text": " ", "small_text": " " }
|
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 `<img class="smallimg" src="${get_img(activity, "small_image")}" title="${activity.assets.small_text}">`
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
addedHTML += `
|
addedHTML += `
|
||||||
<div class="chip activity col-md-6 testing">
|
<div class="chip activity col-md-6 testing">
|
||||||
<img src="${get_img(activity)}" title="${activity.assets.large_text || activity.assets.small_text}">
|
<img src="${get_img(activity)}" title="${activity.assets.large_text}">
|
||||||
|
${smch()}
|
||||||
<p>
|
<p>
|
||||||
Playing <span style="color: rgb(255, 100, 150);">${activity.name}</span>
|
Playing <span style="color: rgb(255, 100, 150);">${activity.name}</span>
|
||||||
<br> ${(activity.details || activity.assets.large_text || " ")}
|
<br> ${(activity.details || activity.assets.large_text || " ")}
|
||||||
|
@ -405,8 +410,6 @@ lanyard.addEventListener("message", (res) => {
|
||||||
for (let index = 0; index < lanyardData.activities.length; index++) {
|
for (let index = 0; index < lanyardData.activities.length; index++) {
|
||||||
const activity = lanyardData.activities[index];
|
const activity = lanyardData.activities[index];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (get_img_url(activity)) {
|
if (get_img_url(activity)) {
|
||||||
var fn = sha256(get_img_url(activity))
|
var fn = sha256(get_img_url(activity))
|
||||||
var fp = path.join(__dirname, 'static/cached', fn)
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,16 @@ a {
|
||||||
object-fit: cover;
|
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 {
|
a:hover {
|
||||||
color: white;
|
color: white;
|
||||||
transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1);
|
transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1);
|
||||||
|
|
Loading…
Reference in a new issue