-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (61 loc) · 2.43 KB
/
script.js
File metadata and controls
67 lines (61 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function toggle(id) {
const el = document.getElementById(id);
el.style.display = el.style.display === "block" ? "none" : "block";
}
// Daily Bias logging
const STORAGE_KEY = 'dailyBiasLog';
function saveBias() {
const marketRisk = document.getElementById('marketRisk').value;
const primaryFocus = document.getElementById('primaryFocus').value;
const note = document.getElementById('biasNote').value;
const entry = { ts: new Date().toISOString(), marketRisk, primaryFocus, note };
const log = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
log.unshift(entry);
localStorage.setItem(STORAGE_KEY, JSON.stringify(log));
renderBiasLog();
}
function renderBiasLog() {
const container = document.getElementById('biasEntries');
container.innerHTML = '';
const log = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
if (!log.length) {
container.innerHTML = '<li class="empty">No entries yet.</li>';
return;
}
log.forEach(e => {
const li = document.createElement('li');
const time = new Date(e.ts).toLocaleString();
li.textContent = `${time} — ${e.marketRisk} — ${e.primaryFocus} — ${e.note}`;
container.appendChild(li);
});
}
function exportBiasCSV() {
const log = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
if (!log.length) return alert('No entries to export');
const rows = [['timestamp','marketRisk','primaryFocus','note']];
log.slice().reverse().forEach(e => rows.push([e.ts, e.marketRisk, e.primaryFocus, e.note]));
const csv = rows.map(r => r.map(c => '"' + String(c).replace(/"/g,'""') + '"').join(',')).join('\n');
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'daily-bias-log.csv';
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
function clearBiasLog() {
if (!confirm('Clear all daily bias entries?')) return;
localStorage.removeItem(STORAGE_KEY);
renderBiasLog();
}
document.addEventListener('DOMContentLoaded', () => {
const saveBtn = document.getElementById('saveBiasBtn');
if (saveBtn) saveBtn.addEventListener('click', saveBias);
const exportBtn = document.getElementById('exportBiasBtn');
if (exportBtn) exportBtn.addEventListener('click', exportBiasCSV);
const clearBtn = document.getElementById('clearBiasBtn');
if (clearBtn) clearBtn.addEventListener('click', clearBiasLog);
renderBiasLog();
});