-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.html
More file actions
230 lines (216 loc) · 6.83 KB
/
Copy pathsettings.html
File metadata and controls
230 lines (216 loc) · 6.83 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Settings - Monthly Goal</title>
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap" rel="stylesheet">
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #dedede;
font-family: 'Share Tech Mono', monospace;
}
#hamburger {
position: absolute;
top: 10px;
right: 10px;
font-size: 30px;
cursor: pointer;
user-select: none;
}
#nav-menu {
position: absolute;
top: 50px;
right: 10px;
background-color: rgba(255, 255, 255, 0.9);
border: 1px solid #ccc;
padding: 10px;
display: none;
font-size: 1.2em;
}
#nav-menu.open {
display: block;
}
#nav-menu a {
display: block;
text-decoration: none;
color: #333;
margin: 5px 0;
}
#slider-container {
margin-top: 20px;
}
#goal-label[contenteditable] {
display: inline-block;
min-width: 6ch;
padding: 2px 4px;
border: 1px dashed transparent;
}
#goal-label[contenteditable]:focus {
outline: none;
border-color: #666;
background-color: #fff;
}
#goals-table {
border-collapse: collapse;
margin-top: 20px;
}
#goals-table th,
#goals-table td {
border: 1px solid #ccc;
padding: 4px 8px;
}
#goals-table input {
width: 100px;
}
#api-section {
margin-top: 10px;
}
#api-list div {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div id="hamburger">☰</div>
<div id="nav-menu">
<a href="index.html">Home</a>
<a href="#">Stats</a>
<a href="settings.html">Settings</a>
</div>
<section id="api-section">
<div id="api-list"></div>
<button type="button" id="add-api">+</button>
<button type="button" id="save-apis">OK</button>
</section>
<h1>Monthly goals</h1>
<table id="goals-table">
<tr><th>Month</th><th>Goal</th></tr>
<tr><td>January 2025</td><td><input data-key="2025-01" type="text" placeholder="fill in"></td></tr>
<tr><td>February 2025</td><td><input data-key="2025-02" type="text" placeholder="fill in"></td></tr>
<tr><td>March 2025</td><td><input data-key="2025-03" type="text" placeholder="fill in"></td></tr>
<tr><td>April 2025</td><td><input data-key="2025-04" type="text" placeholder="fill in"></td></tr>
<tr><td>May 2025</td><td><input data-key="2025-05" type="text" placeholder="fill in"></td></tr>
<tr><td>June 2025</td><td><input data-key="2025-06" type="text" placeholder="fill in"></td></tr>
<tr><td>July 2025</td><td><input data-key="2025-07" type="text" placeholder="fill in"></td></tr>
<tr><td>August 2025</td><td><input data-key="2025-08" type="text" placeholder="fill in"></td></tr>
<tr><td>September 2025</td><td><input data-key="2025-09" type="text" placeholder="fill in"></td></tr>
<tr><td>October 2025</td><td><input data-key="2025-10" type="text" placeholder="fill in"></td></tr>
<tr><td>November 2025</td><td><input data-key="2025-11" type="text" placeholder="fill in"></td></tr>
<tr><td>December 2025</td><td><input data-key="2025-12" type="text" placeholder="fill in"></td></tr>
</table>
<div id="slider-container">
<label for="goal-slider">Monthly goal:</label>
<input type="range" id="goal-slider" min="100000" max="1000000" step="1000">
<span id="goal-label" contenteditable="true"></span>
</div>
<script>
const slider = document.getElementById('goal-slider');
const goalLabel = document.getElementById('goal-label');
const hamburger = document.getElementById('hamburger');
const navMenu = document.getElementById('nav-menu');
const apiListEl = document.getElementById('api-list');
const addApiBtn = document.getElementById('add-api');
const saveApisBtn = document.getElementById('save-apis');
let apiList = JSON.parse(localStorage.getItem('apiList') || '[]');
if (apiList.length === 0) {
apiList = [
{ url: '', name: 'API 1' },
{ url: '', name: 'API 2' }
];
}
function renderApiList() {
apiListEl.innerHTML = '';
apiList.forEach((api, index) => {
const row = document.createElement('div');
const urlInput = document.createElement('input');
urlInput.type = 'text';
urlInput.value = api.url || '';
urlInput.placeholder = 'URL';
urlInput.addEventListener('input', () => api.url = urlInput.value.trim());
const nameInput = document.createElement('input');
nameInput.type = 'text';
nameInput.value = api.name || '';
nameInput.placeholder = 'Navn';
nameInput.addEventListener('input', () => api.name = nameInput.value.trim());
row.textContent = `API ${index + 1}: `;
row.appendChild(urlInput);
row.appendChild(nameInput);
apiListEl.appendChild(row);
});
}
renderApiList();
addApiBtn.addEventListener('click', () => {
apiList.push({ url: '', name: '' });
renderApiList();
});
saveApisBtn.addEventListener('click', () => {
localStorage.setItem('apiList', JSON.stringify(apiList));
alert('Saved');
});
const now = new Date();
// Use the same YYYY-MM key as the main page
const monthKey = now.toISOString().slice(0,7);
// Retrieve stored month goals from localStorage
const monthlyGoals = JSON.parse(localStorage.getItem('monthlyGoals') || '{}');
// Default goal if none exists yet
let monthlyGoal = Number(monthlyGoals[monthKey]) || 500000;
function updateGoalDisplay() {
goalLabel.textContent = monthlyGoal.toLocaleString();
}
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('open');
});
slider.value = monthlyGoal;
updateGoalDisplay();
slider.addEventListener('input', () => {
monthlyGoal = Number(slider.value);
updateGoalDisplay();
// Persist the slider value for this month
monthlyGoals[monthKey] = monthlyGoal;
localStorage.setItem('monthlyGoals', JSON.stringify(monthlyGoals));
});
goalLabel.addEventListener('blur', () => {
const digits = goalLabel.textContent.replace(/[^0-9]/g, '');
const value = Number(digits);
if (!isNaN(value) && value >= 100000 && value <= 1000000) {
monthlyGoal = value;
slider.value = value;
}
updateGoalDisplay();
// Save goal after manual edit
monthlyGoals[monthKey] = monthlyGoal;
localStorage.setItem('monthlyGoals', JSON.stringify(monthlyGoals));
});
document.querySelectorAll('#goals-table input').forEach(input => {
const key = input.dataset.key;
if (monthlyGoals[key]) {
input.value = monthlyGoals[key].toLocaleString();
}
input.addEventListener('blur', () => {
const digits = input.value.replace(/[^0-9]/g, '');
const val = Number(digits);
if (!isNaN(val) && val >= 100000 && val <= 1000000) {
// Keep each month's value separate
monthlyGoals[key] = val;
if (key === monthKey) {
monthlyGoal = val;
slider.value = val;
updateGoalDisplay();
}
input.value = val.toLocaleString();
} else {
input.value = monthlyGoals[key] ? monthlyGoals[key].toLocaleString() : '';
}
// Save the table value back to localStorage
localStorage.setItem('monthlyGoals', JSON.stringify(monthlyGoals));
});
});
</script>
</body>
</html>