Skip to content

Commit a1a425f

Browse files
committed
update label
1 parent e2b313c commit a1a425f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

public/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<div class="search">
1919
<input type="text" placeholder="Search...">
2020
</div>
21+
<button class="night-mode-btn">🌙</button>
2122
</nav>
2223
</header>
2324
<main>
@@ -26,8 +27,8 @@
2627
</div>
2728
</main>
2829
<footer>
30+
<div class="new-message">Kathryn: Swa</div>
2931
<button class="close-btn">X</button>
30-
<button class="night-mode-btn">🌙</button>
3132
<div class="design-by">Design by gusibi@path-meme</div>
3233
</footer>
3334
<script src="/script.js"></script>

public/script.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ document.addEventListener('DOMContentLoaded', async () => {
66
nightModeBtn.addEventListener('click', () => {
77
document.body.classList.toggle('night-mode');
88
nightModeBtn.textContent = document.body.classList.contains('night-mode') ? '☀️' : '🌙';
9+
// 保存夜间模式状态到 localStorage
10+
localStorage.setItem('nightMode', document.body.classList.contains('night-mode'));
911
});
1012

13+
// 检查并应用保存的夜间模式状态
14+
const savedNightMode = localStorage.getItem('nightMode');
15+
if (savedNightMode === 'true') {
16+
document.body.classList.add('night-mode');
17+
nightModeBtn.textContent = '☀️';
18+
}
19+
1120
try {
1221
const response = await fetch('https://path-momo-api.gusibi.workers.dev/api/blog-posts');
1322
if (!response.ok) {
@@ -35,9 +44,9 @@ document.addEventListener('DOMContentLoaded', async () => {
3544
contentHtml += `<p>${post.body}</p>`;
3645

3746
// 创建标签 HTML
38-
const labelsHtml = post.labels.map(label =>
47+
const labelsHtml = post.labels && post.labels.length > 0 ? post.labels.map(label =>
3948
`<span class="label" style="background-color: #${label.color}">${label.name}</span>`
40-
).join('');
49+
).join('') : '';
4150

4251
card.innerHTML = `
4352
<div class="header">

public/styles.css

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ nav {
3333
align-items: center;
3434
}
3535

36+
.night-mode-btn {
37+
background: none;
38+
border: none;
39+
font-size: 1.5em;
40+
cursor: pointer;
41+
}
42+
3643
.icons span {
3744
margin: 0 10px;
3845
cursor: pointer;

0 commit comments

Comments
 (0)