-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (184 loc) · 10 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" type="image/x-icon" href="https://zolodev.github.io/bumbisaft/favicon.ico">
<title>Avanza</title>
<link href="app.css" rel="stylesheet">
</head>
<body>
<div class="banner">
<h1>Avanza</h1>
<span class="banner-divider">/</span>
<a href="./skandia.html">Skandia</a>
</div>
<div id="dataContainer" class="data-container"></div>
<!-- The accordion container -->
<div class="accordion">
<!-- Each accordion item -->
<div class="accordion-item">
<button class="accordion-button" type="button">History</button>
<div id="historyContainer" class="accordion-content"></div>
</div>
</div>
<script>
var data = "";
// URL of the JSON data
const url = 'https://raw.githubusercontent.com/zolodev/auto-python/main/avanza_data.json';
// Fetch the JSON data from the URL
fetch(url)
.then(response => response.json())
.then(rec_data => {
// Convert the JSON data to a string with indentation
data = rec_data;
// Iterate over the data
data.forEach(item => {
// Create a div for the label
const labelDiv = document.createElement('div');
labelDiv.className = 'label';
labelDiv.textContent = item.Label;
document.getElementById('dataContainer').appendChild(labelDiv);
const containerDiv = document.createElement('div');
containerDiv.className = 'data-item-container';
document.getElementById('dataContainer').appendChild(containerDiv);
// HISTORY Part
// Create a div for the label
const historyLabelDiv = document.createElement('div');
historyLabelDiv.className = 'label';
historyLabelDiv.textContent = item.Label;
document.getElementById('historyContainer').appendChild(historyLabelDiv);
const historyContainerDiv = document.createElement('div');
historyContainerDiv.className = 'data-item-container';
document.getElementById('historyContainer').appendChild(historyContainerDiv);
// Iterate over the FundData array
item.FundData.forEach(fund => {
if (fund.history === true) { return; }
// Create a div for each fund
const div = document.createElement('div');
div.className = 'data-item';
const trendDay = fund['TrendDay'];
const trendDayGood = trendDay === '\u25b2';
const trendWeek = fund['TrendWeek'];
const trendWeekGood = trendWeek === '\u25b2';
// Build the content
div.innerHTML += `
<div class='data-item-name'>${fund['Name']}</div>
<div class='data-item-ppmcode'>${fund['PPMCode']}</div>
<div class='data-item-worth'>
<div class='data-item-worth-label'>Worth</div>
<div class='data-item-worth-container'>
<div class="data-item-worth-current">
<div>Current</div>
<div><strong>${fund['Current'].toFixed(3)}</strong></div>
</div>
<div class="data-item-worth-yesterday">
<div>Yesterday</div>
<div><strong>${fund['Yesterday'].toFixed(3)}</strong></div>
</div>
<div class="data-item-worth-lastweek">
<div>Last week</div>
<div><strong>${fund['LastWeek'].toFixed(3)}</strong></div>
</div>
</div>
</div>
<div class='data-item-trend'>
<div class='data-item-trend-label'>Trend</div>
<div class='data-item-trend-container'>
<div class="data-item-trend-day">
<div>Day</div>
<div class="${trendDayGood ? 'data-item-trend-up' : 'data-item-trend-down'}">${trendDay}</div>
</div>
<div class="data-item-trend-week">
<div>Week</div>
<div class="${trendWeekGood ? 'data-item-trend-up' : 'data-item-trend-down'}">${trendWeek}</div>
</div>
<div class="data-item-trend-awe">
<div>${fund['TrendAwesome']}</div>
</div>
</div>
</div>
<div class='data-item-updated'><em>${fund['LastUpdated']}</em></div>
<div class='data-item-link'>
<a href='${fund['URL']}' target='_blank'>${fund['URL']}</a>
</div>
`;
// Append the div to the container
containerDiv.appendChild(div);
});
// Adding History
item.FundData.forEach(fund => {
if (fund.history === false) { return; }
// Create a div for each fund
const div = document.createElement('div');
div.className = 'data-item-avanza-history-item';
const trendDay = fund['TrendDay'];
const trendDayGood = trendDay === '\u25b2';
const trendWeek = fund['TrendWeek'];
const trendWeekGood = trendWeek === '\u25b2';
// Build the content
div.innerHTML += `
<div class='data-item-name'>${fund['Name']}</div>
<div class='data-item-ppmcode'>${fund['PPMCode']}</div>
<div class='data-item-worth'>
<div class='data-item-worth-label'>Worth</div>
<div class='data-item-worth-container'>
<div class="data-item-worth-current">
<div>Current</div>
<div><strong>${fund['Current'].toFixed(3)}</strong></div>
</div>
<div class="data-item-worth-yesterday">
<div>Yesterday</div>
<div><strong>${fund['Yesterday'].toFixed(3)}</strong></div>
</div>
<div class="data-item-worth-lastweek">
<div>Last week</div>
<div><strong>${fund['LastWeek'].toFixed(3)}</strong></div>
</div>
</div>
</div>
<div class='data-item-trend'>
<div class='data-item-trend-label'>Trend</div>
<div class='data-item-trend-container'>
<div class="data-item-trend-day">
<div>Day</div>
<div class="${trendDayGood ? 'data-item-trend-up' : 'data-item-trend-down'}">${trendDay}</div>
</div>
<div class="data-item-trend-week">
<div>Week</div>
<div class="${trendWeekGood ? 'data-item-trend-up' : 'data-item-trend-down'}">${trendWeek}</div>
</div>
<div class="data-item-trend-awe">
<div>${fund['TrendAwesome']}</div>
</div>
</div>
</div>
<div class='data-item-updated'><em>${fund['LastUpdated']}</em></div>
<div class='data-item-link'>
<a href='${fund['URL']}' target='_blank'>${fund['URL']}</a>
</div>
`;
// Append the div to the container
historyContainerDiv.appendChild(div);
});
});
})
.catch(error => console.error('Error:', error));
// Get all the accordion items
const accordions = document.querySelectorAll('.accordion-item');
// Add an event listener to each accordion item
accordions.forEach((accordion) => {
const button = accordion.querySelector('.accordion-button');
const content = accordion.querySelector('.accordion-content');
// Toggle the content when the button is clicked
button.addEventListener('click', () => {
if (accordion.classList.contains('open')) {
accordion.classList.remove('open');
content.style.display = 'none';
} else {
accordion.classList.add('open');
content.style.display = 'block';
}
});
});
</script>
</body>
</html>