Enriches leaderboard cards with tenure, cycle, recursions and more
// ==UserScript==
// @name DeepCo™ — Leaderboard Intel
// @namespace https://deepco.app/
// @version 9.0.0
// @description Enriches leaderboard cards with tenure, cycle, recursions and more
// @author You
// @match https://deepco.app/legends*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function () {
'use strict';
const CACHE_TTL_MS = 5 * 60 * 1000;
const cache = {};
function parseProfile(html) {
const doc = new DOMParser().parseFromString(html, 'text/html');
const get = (label) => {
let result = null;
doc.querySelectorAll('.rounded-box').forEach(box => {
const l = box.querySelector('.text-xs')?.textContent?.trim() || '';
if (l.toLowerCase().includes(label.toLowerCase())) {
result = box.querySelector('.text-2xl,.text-lg,.font-semibold')?.textContent?.trim() || null;
}
});
return result;
};
const tenureMatch = html.match(/Tenure\s+([\w\s]+?)(?:<\/span>|"|')/i);
return {
tenure: tenureMatch ? tenureMatch[1].trim() : null,
status: get('Status'),
department: get('Department')?.split('\n')[0].trim(),
cycleDuration: get('Cycle Duration'),
recursions: get('Recursions Executed'),
rcAcquired: get('Recursive Credits Acquired'),
lifetimeDC: get('DeepCoins™ Accrued'),
clusters: get('Data Clusters Completed'),
uptime: get('Active Uptime Logged'),
};
}
function getCached(id) {
const e = cache[id];
return e && Date.now() < e.expires ? e.data : null;
}
function setCached(id, data) {
cache[id] = { data, expires: Date.now() + CACHE_TTL_MS };
}
async function fetchProfile(id) {
const cached = getCached(id);
if (cached) return cached;
try {
const res = await fetch(`/workers/${id}`, {
headers: { 'Turbo-Frame': 'worker-profile', 'Accept': 'text/html' }
});
const data = parseProfile(await res.text());
setCached(id, data);
return data;
} catch { return null; }
}
function injectCard(link, data) {
if (!data || link.dataset.intelInjected) return;
link.dataset.intelInjected = '1';
// Inject inside the card-body, at the bottom
const cardBody = link.querySelector('.card-body');
if (!cardBody) return;
const stat = (label, val, color = '#8b949e') =>
val ? `<div style="display:flex;justify-content:space-between;gap:8px">
<span style="color:#484f58;font-size:9px;text-transform:uppercase;letter-spacing:.05em;white-space:nowrap">${label}</span>
<span style="color:${color};font-size:10px;text-align:right">${val}</span>
</div>` : '';
const isOnline = data.status?.toLowerCase() === 'online';
const panel = document.createElement('div');
panel.style.cssText = `
margin-top:10px;padding:8px;
background:#0d1117;border:1px solid #21262d;border-radius:6px;
font-family:'Courier New',monospace;
display:flex;flex-direction:column;gap:3px;
`;
panel.innerHTML = [
stat('Tenure', data.tenure, '#58a6ff'),
stat('Status', data.status, isOnline ? '#3fb950' : '#8b949e'),
stat('Dept', data.department, '#8b949e'),
stat('Cycle', data.cycleDuration, '#e3b341'),
stat('Recursions', data.recursions, '#a371f7'),
stat('RC Acq.', data.rcAcquired, '#a371f7'),
stat('Clusters', data.clusters, '#8b949e'),
stat('DC (life)', data.lifetimeDC, '#3fb950'),
stat('Uptime', data.uptime, '#8b949e'),
].filter(Boolean).join('');
cardBody.appendChild(panel);
}
function getLinks() {
return [...document.querySelectorAll('a[href^="/workers/"]')]
.filter(a => !a.closest('#utility-panel-comm,#fab-chat-container,.drawer-side,nav,header,[data-panel-key="comm"]'));
}
async function loadAll(btn) {
btn.disabled = true;
btn.textContent = '⬡ Loading…';
const links = getLinks().filter(a => !a.dataset.intelInjected);
await Promise.all(links.map(async link => {
const id = link.getAttribute('href').split('/').pop();
const data = await fetchProfile(id);
if (data) injectCard(link, data);
}));
btn.textContent = '⬡ Intel ✓';
setTimeout(() => { btn.textContent = '⬡ Load Intel'; btn.disabled = false; }, 2000);
}
function buildButton() {
if (document.getElementById('dco-intel-btn')) return;
const btn = document.createElement('button');
btn.id = 'dco-intel-btn';
btn.textContent = '⬡ Load Intel';
btn.style.cssText = `
position:fixed;bottom:16px;right:16px;z-index:99999;
background:#161b22;border:1px solid #3fb950;border-radius:6px;
color:#3fb950;font-family:'Courier New',monospace;font-size:12px;
padding:6px 14px;cursor:pointer;
box-shadow:0 2px 12px rgba(0,0,0,.6);
`;
btn.onmouseenter = () => btn.style.background = '#1a2a1a';
btn.onmouseleave = () => btn.style.background = '#161b22';
btn.onclick = () => loadAll(btn);
document.body.appendChild(btn);
}
document.addEventListener('turbo:load', buildButton);
document.addEventListener('turbo:frame-load', buildButton);
buildButton();
})();