Violets-Purgatory/overcomplicatedStatuses.js

152 lines
6.8 KiB
JavaScript
Raw Normal View History

2024-02-18 08:21:08 -06:00
const path = require("path"),
2024-06-29 17:34:54 -05:00
fs = require("fs")
2024-02-18 08:21:08 -06:00
var constants = JSON.parse(fs.readFileSync(path.join(__dirname, 'constants.json')))
2024-02-18 08:21:08 -06:00
function makeCompat(string="") {
2024-06-02 18:31:08 -05:00
return string.replaceAll("<", "&lt;").replaceAll(">", "&gt;")
}
2024-02-18 08:01:58 -06:00
function timeFormatter(seconds) {
2024-06-29 17:34:54 -05:00
seconds = Math.ceil(seconds / 1000)
2024-02-18 08:01:58 -06:00
var minutes = Math.floor(seconds / 60)
if (seconds % 60 < 10) {
return `${minutes}:0${seconds % 60}`
} else {
return `${minutes}:${seconds % 60}`
}
}
function gameTimeFormatter(seconds) {
2024-06-29 17:34:54 -05:00
seconds = Math.ceil(seconds / 1000)
2024-02-18 08:01:58 -06:00
var minutes = Math.ceil(seconds / 60)
var hours = Math.floor(minutes / 60)
if (seconds <= 60) {
return 'about ' + seconds + ' seconds'
} else if (minutes < 60) {
return `${minutes} Minutes`
}
return `${hours} hours and ${minutes % 60} minutes`
}
function onlyIfExists(string, check) {
if (check) {
return string
} else {
return ""
}
}
2024-02-18 08:01:58 -06:00
module.exports = {
activitiesToHTML: (lanyardData, cachedImages) => {
var debounce = false
var addedHTML = ""
if (lanyardData && lanyardData.activities.length > 0) {
for (let index = 0; index < lanyardData.activities.length; index++) {
const activity = lanyardData.activities[index];
var found = false
for (let index = 0; index < lanyardData.activities.length; index++) {
const act = lanyardData.activities[index]
if (act.name == activity.name) {
if (Object.keys(act).length > Object.keys(activity).length) {
found = true
}
}
}
if (found) {
continue
}
function get_img(activity, size = "large_image") {
2024-10-16 10:26:13 -05:00
return "https://cache.violets-purgatory.dev/cached/byID/" + activity.id + "?size=" + size + "&url=" + activity.assets[size]
2024-02-18 08:01:58 -06:00
}
2024-06-29 17:34:54 -05:00
function activityTime() {
2024-02-18 08:01:58 -06:00
if (activity.timestamps) {
2024-06-29 17:34:54 -05:00
if (activity.timestamps.start) {
if (activity.timestamps.end) {
var timeLeft = Math.round((activity.timestamps.end - Date.now()) / 1000)
2024-11-22 17:04:39 -06:00
var totalTime = Math.round((activity.timestamps.end - activity.timestamps.start) / 1000)
2024-06-29 17:34:54 -05:00
return `
2024-11-22 17:04:39 -06:00
<div class="durationBarStuff">
2024-11-22 17:09:58 -06:00
<p style="padding-left: 0;" class="playTimeStart scriptEnabled" data-start="${activity.timestamps.start}" data-end="${activity.timestamps.end}">${timeFormatter((Date.now() - activity.timestamps.start))}</p>
2024-11-22 17:04:39 -06:00
<div class="lengthBar lengthBar${index}">
<div></div>
</div>
2024-11-22 17:09:58 -06:00
<p class="playTimeEnd" data-start="${activity.timestamps.start}" data-end="${activity.timestamps.end}">${timeFormatter((activity.timestamps.end - activity.timestamps.start))}</p>
2024-11-22 17:04:39 -06:00
</div>
2024-06-29 17:34:54 -05:00
<style>
2024-11-22 17:04:39 -06:00
.lengthBar${index} > div {
2024-06-29 17:34:54 -05:00
animation-name: songSlider${index};
2024-11-22 17:04:39 -06:00
animation-duration: ${totalTime}s;
animation-delay: ${timeLeft - totalTime}s;
2024-06-29 17:34:54 -05:00
animation-timing-function: linear;
2024-11-22 17:04:39 -06:00
animation-iteration-count: infinite;
2024-06-29 17:34:54 -05:00
}
@keyframes songSlider${index} {
0% {
2024-11-22 17:04:39 -06:00
width: 0%;
2024-06-29 17:34:54 -05:00
}
100% {
width: 100%;
}
}
</style>
`
} else {
return `
2024-11-22 17:04:39 -06:00
<p class="timeEstimate" data-start="${activity.timestamps.start}">${gameTimeFormatter((Date.now() - activity.timestamps.start))}</p>
2024-06-29 17:34:54 -05:00
`
}
2024-06-29 18:36:27 -05:00
} else if (activity.timestamps.end) {
return `
2024-11-22 17:04:39 -06:00
<p><span class="endEstimate" data-end="${activity.timestamps.end}">${timeFormatter((activity.timestamps.end - Date.now()))}</span> left</p>
2024-06-29 18:36:27 -05:00
`
2024-02-18 08:01:58 -06:00
}
}
2024-06-29 17:34:54 -05:00
}
2024-02-18 08:01:58 -06:00
2024-06-29 17:34:54 -05:00
if (activity.type != 4 && activity.assets) {
2024-02-18 08:01:58 -06:00
var time = activity.created_at
if (activity.timestamps) {
time = activity.timestamps.start
}
if (!activity.assets) {
activity.assets = { "large_text": "", "small_text": "" }
2024-02-18 08:01:58 -06:00
}
2024-11-22 17:04:39 -06:00
var text1 = onlyIfExists("<span style='font-size: 1.3rem;'>" + makeCompat(activity.song) + "</span>", activity.song) || activity.details
var text2 = onlyIfExists("By: " + activity.artist, activity.artist) || activity.state
2024-06-29 21:28:10 -05:00
var text3 = onlyIfExists("On: " + activity.album, activity.album != activity.song && activity.album)
2024-06-29 17:34:54 -05:00
2024-02-18 08:01:58 -06:00
addedHTML += `
<div class="chip activity grid-child">
<img src="${get_img(activity)}" title="${activity.assets.large_text || activity.assets.small_text}">
2024-07-01 18:26:36 -05:00
${onlyIfExists(`<img class="smallimg" src="${get_img(activity, "small_image")}" title="${activity.assets.small_text}">`, activity.assets.small_image)}
2024-11-22 17:04:39 -06:00
<div>
<p style="font-size: 1.6rem;">${activity.name}</p>
${onlyIfExists("<p>" + text1 + "</p>", text1)}
${onlyIfExists("<p>" + makeCompat(text2) + "</p>", text2)}
${onlyIfExists("<p>" + makeCompat(text3) + "</p>", text3)}
${onlyIfExists(activityTime(), activityTime())}
</div>
2024-02-18 08:01:58 -06:00
</div>
`
}
}
}
2024-06-05 22:04:30 -05:00
if (addedHTML.length > 10) {
addedHTML = `<h2><hr>What I'm up to:</h2><div class="activity-container">` + addedHTML
addedHTML += "</div>"
}
return addedHTML
2024-02-18 08:01:58 -06:00
}
}