Skip to content

Commit

Permalink
update +_layouts/stock.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulong Ma committed Nov 16, 2024
1 parent a1ddbc0 commit 95d58db
Showing 1 changed file with 132 additions and 100 deletions.
232 changes: 132 additions & 100 deletions _layouts/stock.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,113 +6,145 @@
{% if site.cdn.jsdelivr.enabled %}
{% assign assets_base_url = "https://cdn.jsdelivr.net/gh/" | append: site.repository | append: '@'| append: site.cdn.jsdelivr.branch %}
{% endif %}

<section class="container content">
<style>
table {
border-collapse: collapse;
width: 90%;
font-size: 12px;
margin: 0 auto;
border-spacing: 10px;
}
th, td {
border: 1px solid black;
padding: 10px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.red { color: red; }
.green { color: green; }
.black { color: black; }
#detail-container {
display: flex;
flex-wrap: wrap; /* 自动换行 */
gap: 20px; /* 图片之间的间距 */
justify-content: space-between; /* 图片均匀分布 */
}
.detail-item {
flex: 1 1 calc(50% - 20px); /* 每个图片占50%宽度,减去间距 */
box-sizing: border-box; /* 确保宽度包括 padding 和 border */
max-width: calc(50% - 20px); /* 最大宽度控制 */
}
#detail-container img {
width: 100%;
height: auto;
max-width: 500px;
}
table {
border-collapse: collapse;
width: 90%;
font-size: 12px;
margin: 0 auto;
border-spacing: 10px;
}

th, td {
border: 1px solid black;
padding: 10px;
text-align: center;
}

th {
background-color: #f2f2f2;
}

.red {
color: red;
}

.green {
color: green;
}

.black {
color: black;
}

#detail-container {
display: flex;
flex-wrap: wrap; /* 自动换行 */
gap: 20px; /* 图片之间的间距 */
justify-content: space-between; /* 图片均匀分布 */
}

.detail-item {
flex: 1 1 calc(50% - 20px); /* 每个图片占50%宽度,减去间距 */
box-sizing: border-box; /* 确保宽度包括 padding 和 border */
max-width: calc(50% - 20px); /* 最大宽度控制 */
}

#detail-container img {
width: 100%;
height: auto;
max-width: 500px;
}
</style>

<table>
<thead>
<tr>
<th>名称</th>
<th>今日涨跌幅</th>
<th>价格</th>
</tr>
</thead>
<tbody id="data-body"></tbody>
<thead>
<tr>
<th>名称</th>
<th>今日涨跌幅</th>
<th>价格</th>
</tr>
</thead>
<tbody id="data-body"></tbody>
</table>

<script>
var url = 'https://push2.eastmoney.com/api/qt/ulist.np/get?fltt=2&invt=2&fields=f2,f3,f12,f14,f15,f16&secids=1.511130,1.513010,1.518880,1.159915';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data.rc === 0) {
var rows = '';
data.data.diff.forEach(function(item) {
var percentage = ((item.f2 - item.f16) / (item.f15 - item.f16) * 100).toFixed(2);
var colorClass = item.f3 > 0 ? 'red' : item.f3 < 0 ? 'green' : 'black';
var stockLink = 'https://m.10jqka.com.cn/stockpage/sh_' + item.f12 + '/#&atab=geguNews';
rows += '<tr>' +
'<td><a href="' + stockLink + '" target="_blank">' + item.f14.replace('ETF', '') + '</a></td>' +
'<td class="' + colorClass + '">' + item.f3 + '%</td>' +
'<td>' + item.f2 + ' (' + percentage + '%)</td>' +
'</tr>';
});
document.getElementById('data-body').innerHTML = rows;
}
}
};
xhr.send();
</script>
<div id="detail-container"></div>

<script>
const container = document.getElementById('detail-container')
const etfData = [
{
name: "30年国债etf",
code: "511130",
code_dc: "3"
},
{
name: "恒生科技etf",
code: "513010",
},
{
name: "黄金etf",
code: "518880",
}
];
etfData.forEach(item => {
const etfItem = document.createElement('div');
etfItem.className = 'detail-item';
const title = document.createElement('h4');
const link = document.createElement('a');
link.href = `https://m.10jqka.com.cn/stockpage/hs_${item.code}/#&atab=geguNews`;
link.target = '_blank';
link.textContent = `${item.name}: ${item.code}`;
console.log(link)
title.appendChild(link);
const img = document.createElement('img');
img.src = `https://webquotepic.eastmoney.com/GetPic.aspx?imageType=r&type=&nid=1.${item.code}`;
etfItem.appendChild(title);
etfItem.appendChild(img);
container.appendChild(etfItem);
});
var etfData = [
{
name: "恒生科技etf",
code: "513010",
code_a: "1",
code_b: "hs",
},
{
name: "纳指etf",
code: "513100",
code_a: "1",
code_b: "hs",
},
{
name: "黄金etf",
code: "518880",
code_a: "1",
code_b: "hs",
},
{
name: "创业板etf",
code: "159915",
code_a: "0",
code_b: "sz",
},
{
name: "30年国债etf",
code: "511130",
code_a: "1",
code_b: "hs",
}
];
var codeString = etfData.map(item => item.code_a + "." + item.code).join(',');
var url = `https://push2.eastmoney.com/api/qt/ulist.np/get?fltt=2&invt=2&fields=f2,f3,f12,f14,f15,f16&secids=${codeString}`;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data.rc === 0) {
var rows = '';
data.data.diff.forEach(function (item) {
var percentage = ((item.f2 - item.f16) / (item.f15 - item.f16) * 100).toFixed(2);
var colorClass = item.f3 > 0 ? 'red' : item.f3 < 0 ? 'green' : 'black';
// var stockLink = 'https://m.10jqka.com.cn/stockpage/sh_' + item.f12 + '/#&atab=geguNews';
var stockLink = ""
rows += '<tr>' +
'<td><a href="' + stockLink + '" target="_blank">' + item.f14.replace('ETF', '') + '</a></td>' +
'<td class="' + colorClass + '">' + item.f3 + '%</td>' +
'<td>' + item.f2 + ' (' + percentage + '%)</td>' +
'</tr>';
});
document.getElementById('data-body').innerHTML = rows;
}
}
};
xhr.send();

var container = document.getElementById('detail-container')
etfData.forEach(item => {
var etfItem = document.createElement('div');
etfItem.className = 'detail-item';
var title = document.createElement('h4');
var link = document.createElement('a');
link.href = `https://m.10jqka.com.cn/stockpage/hs_${item.code}/#&atab=geguNews`;
link.target = '_blank';
link.textContent = `${item.name}: ${item.code}`;
title.appendChild(link);
var img = document.createElement('img');
img.src = `https://webquotepic.eastmoney.com/GetPic.aspx?imageType=r&type=&nid=${item.code_a}.${item.code}`;
etfItem.appendChild(title);
etfItem.appendChild(img);
container.appendChild(etfItem);
});
</script>
</section>

0 comments on commit 95d58db

Please sign in to comment.