Type |
Price |
Quantity |
Seller |
Time |
const $ = (sel) => document.querySelector(sel);
const fmt = (n) => Number(n).toLocaleString();
// Save API key locally
const keyInput = $('#apiKey');
const savedKey = localStorage.getItem('tornKey');
if (savedKey) keyInput.value = savedKey;
$('#saveKey').addEventListener('click', () => {
localStorage.setItem('tornKey', keyInput.value.trim());
});
// Profit calculator
function updateProfit() {
const buy = Number($('#buyPrice').value || 0);
const sell = Number($('#sellPrice').value || 0);
const fee = Number($('#feePct').value || 0);
const netSell = sell * (1 - fee / 100);
const profit = netSell - buy;
const roi = buy > 0 ? (profit / buy) * 100 : 0;
$('#profitOut').textContent = 'Profit: ' + fmt(profit);
$('#roiOut').textContent = 'ROI: ' + roi.toFixed(2) + '%';
}
['#buyPrice', '#sellPrice', '#feePct'].forEach(id => {
$(id).addEventListener('input', updateProfit);
});
// Item search (basic stub)
const knownItems = [
{ id: 3, name: 'Xanax' },
{ id: 4, name: 'Vicodin' },
{ id: 5, name: 'Morphine' },
{ id: 6, name: 'Ecstasy' },
{ id: 7, name: 'LSD' },
{ id: 8, name: 'Ketamine' },
{ id: 9, name: 'Cannabis' },
];
function searchItems(q) {
q = q.toLowerCase();
return knownItems.filter(i => i.name.toLowerCase().includes(q)).slice(0, 20);
}
$('#itemSearch').addEventListener('input', (e) => {
const q = e.target.value.trim();
const res = searchItems(q);
const list = $('#itemResults');
list.innerHTML = '';
res.forEach(item => {
const li = document.createElement('li');
li.className = 'py-2 px-2 hover:bg-slate-700 cursor-pointer flex justify-between';
li.innerHTML = `${item.name} #${item.id}`;
li.addEventListener('click', () => {
$('#itemId').value = item.id;
addToWatchlist(item);
loadMarket();
loadHistory();
});
list.appendChild(li);
});
});
// Watchlist
const watchKey = 'tornWatchlist';
function getWatchlist() {
try { return JSON.parse(localStorage.getItem(watchKey) || '[]'); } catch { return []; }
}
function setWatchlist(list) {
localStorage.setItem(watchKey, JSON.stringify(list));
renderWatchlist();
}
function addToWatchlist(item) {
const list = getWatchlist();
if (!list.find(x => x.id === item.id)) setWatchlist([...list, item]);
}
function removeFromWatchlist(id) {
setWatchlist(getWatchlist().filter(x => x.id !== id));
}
function renderWatchlist() {
const list = getWatchlist();
const el = $('#watchlist');
el.innerHTML = '';
list.forEach(item => {
const li = document.createElement('li');
li.className = 'flex items-center justify-between bg-slate-900 border border-slate-700 rounded p-2';
li.innerHTML = `
${item.name} #${item.id}
`;
li.children[1].children[0].addEventListener('click', () => {
$('#itemId').value = item.id;
loadMarket();
loadHistory();
});
li.children[1].children[1].addEventListener('click', () => removeFromWatchlist(item.id));
el.appendChild(li);
});
}
renderWatchlist();
// Torn API helpers
function