diff --git a/index.js b/index.js index df08653..50569ee 100644 --- a/index.js +++ b/index.js @@ -52,10 +52,10 @@ if (!fs.existsSync(path.join(cachePath, "emojis"))) { app.use(pageUpdater.middleWare) -process.on('uncaughtException', (err, origin) => { - fs.writeSync( - process.stderr.fd, - `Caught exception: ${err}\n` + - `Exception origin: ${origin}`, - ); - }); \ No newline at end of file +// process.on('uncaughtException', (err, origin) => { +// fs.writeSync( +// process.stderr.fd, +// `Caught exception: ${err}\n` + +// `Exception origin: ${origin}`, +// ); +// }); \ No newline at end of file diff --git a/overcomplicatedStatuses.js b/overcomplicatedStatuses.js index a429db7..bc7c6b8 100644 --- a/overcomplicatedStatuses.js +++ b/overcomplicatedStatuses.js @@ -1,5 +1,5 @@ const path = require("path"), -fs = require("fs") + fs = require("fs") var constants = JSON.parse(fs.readFileSync(path.join(__dirname, 'constants.json'))) @@ -33,7 +33,7 @@ function makeCompat(string) { } function timeFormatter(seconds) { - seconds = Math.ceil(seconds) + seconds = Math.ceil(seconds / 1000) var minutes = Math.floor(seconds / 60) if (seconds % 60 < 10) { @@ -44,7 +44,7 @@ function timeFormatter(seconds) { } function gameTimeFormatter(seconds) { - seconds = Math.ceil(seconds) + seconds = Math.ceil(seconds / 1000) var minutes = Math.ceil(seconds / 60) var hours = Math.floor(minutes / 60) if (seconds <= 60) { @@ -87,63 +87,47 @@ module.exports = { continue } - function get_img(activity, size = "large_image") { return "https://cache.violets-purgatory.dev/cached/" + get_img_url(activity, size) } - function songStats() { - var html = `` - - if (activity.assets && activity.assets.large_text != activity.details && activity.details.length + activity.state.length + activity.assets.large_text.length < 100) { - html += ` -
Album: ${makeCompat(activity.assets.large_text || " ")} -
Artist: ${makeCompat(activity.state || " ")} - ` - } else { - html += "
" - if (activity.state.includes(";")) - { html += "Artists: " } - else { html += "Artist: " } - html += `${makeCompat(activity.state || " ")}` - } - - return html - } - if (activity.type == 2) { - var timeLeft = Math.round((activity.timestamps.end - Date.now()) / 1000) - var currentPercent = (Date.now() - activity.timestamps.start) / (activity.timestamps.end - activity.timestamps.start) * 100 - addedHTML += ` -
- -

- Listening to ${activity.name} -
Song: ${makeCompat(activity.details || " ")} - ${songStats()} + function activityTime() { + if (activity.timestamps) { + if (activity.timestamps.start) { + if (activity.timestamps.end) { + var timeLeft = Math.round((activity.timestamps.end - Date.now()) / 1000) + var currentPercent = (Date.now() - activity.timestamps.start) / (activity.timestamps.end - activity.timestamps.start) * 100 + return `
- - ${timeFormatter((activity.timestamps.end - activity.timestamps.start) / 1000)} -

-
- + ` + } else { + return ` + ${gameTimeFormatter((Date.now() - activity.timestamps.start))} + ` + } } } - - ` - } else if (activity.type == 0 && activity.assets) { + } + + if (activity.type != 4 && activity.assets) { + var time = activity.created_at if (activity.timestamps) { time = activity.timestamps.start @@ -152,43 +136,19 @@ module.exports = { activity.assets = { "large_text": " ", "small_text": " " } } - function smch() { - if (get_img_url(activity, "small_image")) { - return `` - } - return "" - } - - - addedHTML += ` -
- - ${smch()} -

- Playing ${activity.name} - ${onlyIfExists("
" + (activity.details || activity.assets.large_text), activity.details || activity.assets.large_text)} - ${onlyIfExists("
" + (activity.state || activity.assets.small_text), activity.state || activity.assets.small_text)} -
${gameTimeFormatter((Date.now() - time) / 1000)} -

-
- ` - } else if (activity.type != 4 && activity.assets) { - var time = activity.created_at - if (activity.timestamps) { - time = activity.timestamps.start - } - if (!activity.assets) { - activity.assets = { "large_text": " ", "small_text": " " } - } + var text1 = onlyIfExists("
" + activity.song + "", activity.song) || activity.details || activity.assets.large_text + var text2 = onlyIfExists("By: " + activity.artist, activity.artist) || activity.state || activity.assets.small_text + var text3 = onlyIfExists("On: " + activity.album, activity.album) addedHTML += `
-

- ${activity.name} -
${(activity.details || activity.assets.large_text || " ")} -
${(activity.state || activity.assets.small_text || " ")} -
${gameTimeFormatter((Date.now() - time) / 1000)} +

+ ${activity.name} + ${onlyIfExists("
" + text1, text1)} + ${onlyIfExists("
" + text2, text2)} + ${onlyIfExists("
" + text3, text3)} + ${onlyIfExists("
" + activityTime(), activityTime())}

` diff --git a/static/main.js b/static/main.js index 7fa6466..04d8eb1 100644 --- a/static/main.js +++ b/static/main.js @@ -61,7 +61,32 @@ function lerp(a, b, t) { return a * (1 - t) + b * t } -function spinLoop() { +function gameTimeFormatter(seconds) { + seconds = Math.ceil(seconds / 1000) + 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 timeFormatter(seconds) { + seconds = Math.ceil(seconds / 1000) + var minutes = Math.floor(seconds / 60) + + if (seconds % 60 < 10) { + return `${minutes}:0${seconds % 60}` + } else { + return `${minutes}:${seconds % 60}` + } +} + +function loop() { spinWaiting = true setTimeout(() => { spinWaiting = false @@ -100,7 +125,18 @@ function spinLoop() { spins = lerp(spins, Math.round(spins), 1 / spinSpeed * 3) } $(".pfp").css("rotate", (spins * 360) + "deg") - spinLoop() + + $(".durationBarFormatter").each((_, item) => { + item = $(item) + item.text(`${timeFormatter((Date.now() - item.attr("data-start")))}/${timeFormatter((item.attr("data-end") - item.attr("data-start")))}`) + }) + + $(".timeEstimate").each((_, item) => { + item = $(item) + item.text(gameTimeFormatter(Date.now() - item.attr("data-start"))) + }) + + loop() }, 1/spinSpeed * 1000); } @@ -113,7 +149,7 @@ window.onload = function () { pfp = $(".pfp") - spinLoop() + loop() pfp.on("mousedown", () => { // if (!spinWaiting) { diff --git a/static/style.css b/static/style.css index ef86bed..e13d160 100644 --- a/static/style.css +++ b/static/style.css @@ -182,7 +182,7 @@ br { margin: 3px 0; } -@media screen and (min-width: 850px) { +@media screen and (min-width: 1000px) { .activity-container { display: flex; flex-wrap: wrap; @@ -268,7 +268,8 @@ li { .lengthBar { background-color: rgb(50, 40, 60); display: inline-block; - width: 80%; + margin: auto; + width: 65%; height: 10px; padding: 0; overflow: hidden;