first commit
This commit is contained in:
commit
b11c87a506
26 changed files with 1782 additions and 0 deletions
BIN
public/assets/favicon.ico
Normal file
BIN
public/assets/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
25
public/css/error.css
Normal file
25
public/css/error.css
Normal file
|
@ -0,0 +1,25 @@
|
|||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 90vh;
|
||||
background: #0e0e10;
|
||||
color: #fff;
|
||||
font-family: system-ui, sans-serif;
|
||||
}
|
||||
.error-container {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
background: #1a1a1d;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 0 20px rgba(0,0,0,0.3);
|
||||
}
|
||||
.error-title {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 1rem;
|
||||
color: #ff4e4e;
|
||||
}
|
||||
.error-message {
|
||||
font-size: 1.2rem;
|
||||
opacity: 0.8;
|
||||
}
|
335
public/css/index.css
Normal file
335
public/css/index.css
Normal file
|
@ -0,0 +1,335 @@
|
|||
body {
|
||||
font-family: system-ui, sans-serif;
|
||||
background-color: #0e0e10;
|
||||
color: #ffffff;
|
||||
margin: 0;
|
||||
padding: 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.avatar-status-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.avatar-wrapper {
|
||||
position: relative;
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.decoration {
|
||||
position: absolute;
|
||||
top: -18px;
|
||||
left: -18px;
|
||||
width: 164px;
|
||||
height: 164px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
position: absolute;
|
||||
bottom: 4px;
|
||||
right: 4px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
border: 4px solid #0e0e10;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.status-indicator.online {
|
||||
background-color: #23a55a;
|
||||
}
|
||||
|
||||
.status-indicator.idle {
|
||||
background-color: #f0b232;
|
||||
}
|
||||
|
||||
.status-indicator.dnd {
|
||||
background-color: #f23f43;
|
||||
}
|
||||
|
||||
.status-indicator.offline {
|
||||
background-color: #747f8d;
|
||||
}
|
||||
|
||||
.platform-icon.mobile-only {
|
||||
position: absolute;
|
||||
bottom: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
margin: 0;
|
||||
color: #00b0f4;
|
||||
}
|
||||
|
||||
.custom-status {
|
||||
font-size: 1.2rem;
|
||||
color: #bbb;
|
||||
margin-top: 0.25rem;
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
|
||||
.custom-status .custom-emoji {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
vertical-align: text-bottom;
|
||||
margin-right: 4px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.8rem;
|
||||
margin: 2rem 0 1rem;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.activities {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.activity {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1rem;
|
||||
background: #1a1a1d;
|
||||
padding: 1rem;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 0 0 1px #2e2e30;
|
||||
transition: background 0.2s ease;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.activity:hover {
|
||||
background: #2a2a2d;
|
||||
}
|
||||
|
||||
.activity-art {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.activity-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.activity-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.activity-name {
|
||||
font-weight: bold;
|
||||
font-size: 1.1rem;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.activity-detail {
|
||||
font-size: 0.95rem;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.activity-timestamp {
|
||||
font-size: 0.8rem;
|
||||
color: #777;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 6px;
|
||||
background-color: #333;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #00b0f4;
|
||||
transition: width 0.5s ease;
|
||||
}
|
||||
|
||||
.progress-time-labels {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.75rem;
|
||||
color: #888;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.activity-header.no-timestamp {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.progress-time-labels.paused .progress-current::after {
|
||||
content: " ⏸";
|
||||
color: #f0b232;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
html {
|
||||
font-size: clamp(14px, 2vw, 16px);
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 1rem;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.user-card {
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.avatar-status-wrapper {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.avatar-wrapper {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
}
|
||||
|
||||
.decoration {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
top: -16px;
|
||||
left: -16px;
|
||||
}
|
||||
|
||||
.status-indicator,
|
||||
.platform-icon.mobile-only {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
bottom: 2px;
|
||||
right: 2px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.custom-status {
|
||||
font-size: 1rem;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.4rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.activities {
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.activity {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.activity-art {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
height: auto;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.activity-content {
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.activity-header {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.activity-timestamp {
|
||||
text-align: center;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.activity-detail {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
232
public/js/index.js
Normal file
232
public/js/index.js
Normal file
|
@ -0,0 +1,232 @@
|
|||
/* eslint-disable indent */
|
||||
|
||||
const activityProgressMap = new Map();
|
||||
|
||||
function formatTime(ms) {
|
||||
const totalSecs = Math.floor(ms / 1000);
|
||||
const mins = Math.floor(totalSecs / 60);
|
||||
const secs = totalSecs % 60;
|
||||
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function updateElapsedAndProgress() {
|
||||
const now = Date.now();
|
||||
|
||||
document.querySelectorAll(".activity-timestamp").forEach((el) => {
|
||||
const start = Number(el.dataset.start);
|
||||
if (!start) return;
|
||||
|
||||
const elapsed = now - start;
|
||||
const mins = Math.floor(elapsed / 60000);
|
||||
const secs = Math.floor((elapsed % 60000) / 1000);
|
||||
const display = el.querySelector(".elapsed");
|
||||
if (display)
|
||||
display.textContent = `(${mins}m ${secs.toString().padStart(2, "0")}s ago)`;
|
||||
});
|
||||
|
||||
document.querySelectorAll(".progress-bar").forEach((bar) => {
|
||||
const start = Number(bar.dataset.start);
|
||||
const end = Number(bar.dataset.end);
|
||||
if (!start || !end || end <= start) return;
|
||||
|
||||
const duration = end - start;
|
||||
const elapsed = now - start;
|
||||
const progress = Math.min(
|
||||
100,
|
||||
Math.max(0, Math.floor((elapsed / duration) * 100)),
|
||||
);
|
||||
|
||||
const fill = bar.querySelector(".progress-fill");
|
||||
if (fill) fill.style.width = `${progress}%`;
|
||||
});
|
||||
|
||||
document.querySelectorAll(".progress-time-labels").forEach((label) => {
|
||||
const start = Number(label.dataset.start);
|
||||
const end = Number(label.dataset.end);
|
||||
if (!start || !end || end <= start) return;
|
||||
|
||||
const current = Math.max(0, now - start);
|
||||
const total = end - start;
|
||||
|
||||
const currentEl = label.querySelector(".progress-current");
|
||||
const totalEl = label.querySelector(".progress-total");
|
||||
|
||||
const id = `${start}-${end}`;
|
||||
const last = activityProgressMap.get(id);
|
||||
|
||||
if (last !== undefined && last === current) {
|
||||
label.classList.add("paused");
|
||||
} else {
|
||||
label.classList.remove("paused");
|
||||
}
|
||||
|
||||
activityProgressMap.set(id, current);
|
||||
|
||||
if (currentEl) currentEl.textContent = formatTime(current);
|
||||
if (totalEl) totalEl.textContent = formatTime(total);
|
||||
});
|
||||
}
|
||||
|
||||
updateElapsedAndProgress();
|
||||
setInterval(updateElapsedAndProgress, 1000);
|
||||
|
||||
const head = document.querySelector("head");
|
||||
let userId = head?.dataset.userId;
|
||||
let instanceUri = head?.dataset.instanceUri;
|
||||
|
||||
console.log("User ID:", userId);
|
||||
console.log("Instance URI:", instanceUri);
|
||||
|
||||
if (userId && instanceUri) {
|
||||
if (!instanceUri.startsWith("http")) {
|
||||
instanceUri = `https://${instanceUri}`;
|
||||
}
|
||||
|
||||
const wsUri = instanceUri
|
||||
.replace(/^http:/, "ws:")
|
||||
.replace(/^https:/, "wss:")
|
||||
.replace(/\/$/, "");
|
||||
|
||||
const socket = new WebSocket(`${wsUri}/socket`);
|
||||
|
||||
socket.addEventListener("open", () => {
|
||||
socket.send(
|
||||
JSON.stringify({
|
||||
op: 2,
|
||||
d: {
|
||||
subscribe_to_id: userId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
socket.addEventListener("message", (event) => {
|
||||
const payload = JSON.parse(event.data);
|
||||
|
||||
if (payload.t === "INIT_STATE" || payload.t === "PRESENCE_UPDATE") {
|
||||
updatePresence(payload.d);
|
||||
updateElapsedAndProgress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildActivityHTML(activity) {
|
||||
const start = activity.timestamps?.start;
|
||||
const end = activity.timestamps?.end;
|
||||
const now = Date.now();
|
||||
const elapsed = start ? now - start : 0;
|
||||
const total = start && end ? end - start : null;
|
||||
const progress =
|
||||
total && elapsed > 0
|
||||
? Math.min(100, Math.floor((elapsed / total) * 100))
|
||||
: null;
|
||||
|
||||
const img = activity.assets?.large_image;
|
||||
let art = null;
|
||||
if (img?.includes("https")) {
|
||||
const clean = img.split("/https/")[1];
|
||||
if (clean) art = `https://${clean}`;
|
||||
} else if (img?.startsWith("spotify:")) {
|
||||
art = `https://i.scdn.co/image/${img.split(":")[1]}`;
|
||||
} else if (img) {
|
||||
art = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${img}.png`;
|
||||
}
|
||||
|
||||
const activityTimestamp =
|
||||
!total && start
|
||||
? `
|
||||
<div class="activity-timestamp" data-start="${start}">
|
||||
<span>
|
||||
Since: ${new Date(start).toLocaleTimeString("en-GB", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
})} <span class="elapsed"></span>
|
||||
</span>
|
||||
</div>`
|
||||
: "";
|
||||
|
||||
const progressBar =
|
||||
progress !== null
|
||||
? `
|
||||
<div class="progress-bar" data-start="${start}" data-end="${end}">
|
||||
<div class="progress-fill" style="width: ${progress}%"></div>
|
||||
</div>
|
||||
<div class="progress-time-labels" data-start="${start}" data-end="${end}">
|
||||
<span class="progress-current">${formatTime(elapsed)}</span>
|
||||
<span class="progress-total">${formatTime(total)}</span>
|
||||
</div>
|
||||
`
|
||||
: "";
|
||||
|
||||
return `
|
||||
<li class="activity">
|
||||
${art ? `<img class="activity-art" src="${art}" alt="Art">` : ""}
|
||||
<div class="activity-content">
|
||||
<div class="activity-header ${progress !== null ? "no-timestamp" : ""}">
|
||||
<span class="activity-name">${activity.name}</span>
|
||||
${activityTimestamp}
|
||||
</div>
|
||||
${activity.details ? `<div class="activity-detail">${activity.details}</div>` : ""}
|
||||
${activity.state ? `<div class="activity-detail">${activity.state}</div>` : ""}
|
||||
${progressBar}
|
||||
</div>
|
||||
</li>
|
||||
`;
|
||||
}
|
||||
|
||||
function updatePresence(data) {
|
||||
const avatarWrapper = document.querySelector(".avatar-wrapper");
|
||||
const statusIndicator = avatarWrapper?.querySelector(".status-indicator");
|
||||
const mobileIcon = avatarWrapper?.querySelector(
|
||||
".platform-icon.mobile-only",
|
||||
);
|
||||
|
||||
const userInfo = document.querySelector(".user-info");
|
||||
const customStatus = userInfo?.querySelector(".custom-status");
|
||||
|
||||
const platform = {
|
||||
mobile: data.active_on_discord_mobile,
|
||||
web: data.active_on_discord_web,
|
||||
desktop: data.active_on_discord_desktop,
|
||||
};
|
||||
|
||||
if (statusIndicator) {
|
||||
statusIndicator.className = `status-indicator ${data.discord_status}`;
|
||||
}
|
||||
|
||||
if (platform.mobile && !mobileIcon) {
|
||||
avatarWrapper.innerHTML += `
|
||||
<svg class="platform-icon mobile-only" viewBox="0 0 1000 1500" fill="#43a25a" aria-label="Mobile" width="17" height="17">
|
||||
<path d="M 187 0 L 813 0 C 916.277 0 1000 83.723 1000 187 L 1000 1313 C 1000 1416.277 916.277 1500 813 1500 L 187 1500 C 83.723 1500 0 1416.277 0 1313 L 0 187 C 0 83.723 83.723 0 187 0 Z M 125 1000 L 875 1000 L 875 250 L 125 250 Z M 500 1125 C 430.964 1125 375 1180.964 375 1250 C 375 1319.036 430.964 1375 500 1375 C 569.036 1375 625 1319.036 625 1250 C 625 1180.964 569.036 1125 500 1125 Z"/>
|
||||
</svg>
|
||||
`;
|
||||
} else if (!platform.mobile && mobileIcon) {
|
||||
mobileIcon.remove();
|
||||
avatarWrapper.innerHTML += `<div class="status-indicator ${data.discord_status}"></div>`;
|
||||
}
|
||||
|
||||
const custom = data.activities?.find((a) => a.type === 4);
|
||||
if (customStatus && custom) {
|
||||
let emojiHTML = "";
|
||||
const emoji = custom.emoji;
|
||||
if (emoji?.id) {
|
||||
const emojiUrl = `https://cdn.discordapp.com/emojis/${emoji.id}.${emoji.animated ? "gif" : "png"}`;
|
||||
emojiHTML = `<img src="${emojiUrl}" alt="${emoji.name}" class="custom-emoji">`;
|
||||
} else if (emoji?.name) {
|
||||
emojiHTML = `${emoji.name} `;
|
||||
}
|
||||
customStatus.innerHTML = `${emojiHTML}${custom.state}`;
|
||||
}
|
||||
|
||||
const filtered = data.activities?.filter((a) => a.type !== 4);
|
||||
const activityList = document.querySelector(".activities");
|
||||
|
||||
if (activityList) {
|
||||
activityList.innerHTML = "";
|
||||
if (filtered?.length) {
|
||||
activityList.innerHTML = filtered.map(buildActivityHTML).join("");
|
||||
}
|
||||
updateElapsedAndProgress();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue